Skip to content

Instantly share code, notes, and snippets.

@binaryphile
Last active November 10, 2016 16:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save binaryphile/ed68fc95fbc5cad06f2f9cb4a84a1651 to your computer and use it in GitHub Desktop.
Save binaryphile/ed68fc95fbc5cad06f2f9cb4a84a1651 to your computer and use it in GitHub Desktop.
AView base box Vagrantfile
# -*- mode: ruby -*-
# vi: set ft=ruby :
private_key_path = File.join(Dir.home, ".ssh", "id_rsa")
public_key_path = File.join(Dir.home, ".ssh", "id_rsa.pub")
insecure_key_path = File.join(Dir.home, ".vagrant.d", "insecure_private_key")
ssh_config = File.join(Dir.home, ".ssh", "config")
host_config = <<CONFIG
Host vagrant
HostName 127.0.0.1
User vagrant
Port 2222
UserKnownHostsFile /dev/null
StrictHostKeyChecking no
PasswordAuthentication no
IdentityFile ~/.ssh/id_rsa
IdentitiesOnly yes
LogLevel FATAL
CONFIG
public_key = IO.read(public_key_path)
configured = false
additions_installed = false
if configured
`sed -i 's/additions_installed = false$/additions_installed = true/' Vagrantfile`
else
File.open(ssh_config, "a") { |f| f.puts host_config } if `grep "Host vagrant$" #{ssh_config}` == ""
`sed -i 's/configured = false$/configured = true/' Vagrantfile`
end
Vagrant.configure("2") do |config|
config.vm.box = "centos/6"
config.ssh.insert_key = false
config.ssh.private_key_path = [
private_key_path,
insecure_key_path # to provision the first time
]
config.vm.network "private_network", type: "dhcp"
if configured
config.vm.synced_folder ".", "/vagrant", type: "nfs"
else
config.vm.synced_folder ".", "/vagrant", disabled: true
end
config.vm.provider "virtualbox" do |vb|
# Customize the amount of memory on the VM:
# vb.memory = "1024"
vb.customize ['modifyvm', :id, '--natnet1', '192.168.222.0/24']
end
config.vm.provision :shell, :inline => <<-SCRIPT
echo '#{public_key}' > /home/vagrant/.ssh/authorized_keys
chmod 600 /home/vagrant/.ssh/authorized_keys
yum update -y
echo 'NOTICE: Run "vagrant reload" to complete the provisioning process'
SCRIPT
config.vbguest.auto_update = false if ! configured || additions_installed
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment