Showing posts with label vagrant. Show all posts
Showing posts with label vagrant. Show all posts

Sunday, 27 August 2017

Vagrant provisioning scripts

An example "create-user.sh" script
 
  #!/bin/bash

  # Add the user
  sudo useradd -m clarkeb -s '/bin/bash'
  sudo echo -e 'password\npassword\n' | sudo passwd clarkeb

  # Set up sudo 
  echo "clarkeb ALL=(ALL:ALL) NOPASSWD: ALL" > /etc/sudoers.d/10_clarkeb

  # Allow password based login
  sed -i 's/PasswordAuthentication no/PasswordAuthentication yes/g' /etc/ssh/sshd_config
  sed -i 's/ChallengeResponseAuthentication no/ChallengeResponseAuthentication yes/g' /etc/ssh/sshd_config
  service sshd restart



An example Vagrantfile snippet to invoke the above script
 
  config.vm.define "core01" do |core01|

    core01.vm.provision "shell", path: "create-user.sh"

    core01.vm.hostname = "core01"
    core01.vm.network "private_network", ip: "10.1.1.101"
    core01.vm.provider "virtualbox" do |vb|
    vb.memory = "1024"
      vb.customize ["modifyvm", :id, "--cpus", "1"]
    end
  end

Vagrant and AWS

An example Vagrantfile
 require 'vagrant-aws'  
  
 Vagrant.configure('2') do |config|  
   
  config.vm.box = "aws-box"  
  config.vm.box_url = "https://github.com/mitchellh/vagrant-aws/raw/master/dummy.box"  
   
  config.vm.define "jupiter" do |jupiter|  
    jupiter.vm.provision "shell", path: "install_ansible.sh"  
    jupiter.vm.provider 'aws' do |aws, override|  
      aws.access_key_id = ENV['AWS_ACCESS_KEY_ID']  
      aws.secret_access_key = ENV['AWS_SECRET_ACCESS_KEY']  
      aws.keypair_name = 'vagrant'  
      aws.region = 'us-west-2'  
      aws.ami = 'ami-20be7540'  
      aws.security_groups = ['default']  
      override.ssh.username = 'ansible'  
      override.ssh.private_key_path = '~/ec2/keys/vagrant.pem'  
      aws.tags = {  
       'Name' => "ansible"  
      }  
    end  
  end