Skip to content

Instantly share code, notes, and snippets.

@fredleger
Created August 25, 2016 09:38
Show Gist options
  • Save fredleger/289cb1a7e9709661e0eba839f02e1270 to your computer and use it in GitHub Desktop.
Save fredleger/289cb1a7e9709661e0eba839f02e1270 to your computer and use it in GitHub Desktop.
Default Vagrantfile (OS wide)
# -*- mode: ruby -*-
# vi: set ft=ruby :
Vagrant.configure(2) do |config|
config.vm.box = "debian/contrib-jessie64"
config.vm.network "public_network"
# get arround a vagrant bug : http://stackoverflow.com/questions/34176041/vagrant-with-virtualbox-on-windows10-rsync-could-not-be-found-on-your-path
config.vm.synced_folder ".", "/vagrant", type: "virtualbox"
# default router
config.vm.provision "shell",
run: "always",
inline: "route add default gw 192.168.77.1 || exit 0"
# delete default gw on eth0
config.vm.provision "shell",
run: "always",
inline: "eval `route -n | awk '{ if ($8 ==\"eth0\" && $2 != \"0.0.0.0\") print \"route del default gw \" $2; }'`"
config.vm.provision "shell",
run: "always",
inline: "echo \"VM IP: $(ip add sh dev eth1 | grep 'inet ' | awk '{ print $2 }' | cut -f 1 -d /)\""
# get arround a vms common bug see : https://github.com/mitchellh/vagrant/issues/1673
config.vm.provision "shell", inline: <<-SHELL
export DEBIAN_FRONTEND=noninteractive
# sudo sed -i 's/^mesg n$/tty -s \&\& mesg n/g' /root/.profile
# sed -i 's/^mesg n$/tty -s \&\& mesg n/g' ~/.profile
SHELL
config.vm.provision "shell", inline: <<-SHELL
export DEBIAN_FRONTEND=noninteractive
sudo bash -c "echo 'deb http://http.debian.net/debian jessie-backports main' >> /etc/apt/sources.list"
sudo apt-get update -q > /dev/null
sudo apt-get install -t jessie-backports -y --no-install-recommends ansible && sudo bash -c "echo localhost ansible_connection=local >> /etc/ansible/hosts" && sudo ansible localhost -m ping
sudo sed -i.bak -e '/#roles_path/a roles_path=/etc/ansible/roles:/vagrant/roles' /etc/ansible/ansible.cfg
[ -f /vagrant/requirements.yml ] && sudo ansible-galaxy install -r /vagrant/requirements.yml
[ -f /vagrant/playbook.yml ] && sudo ansible-playbook --syntax-check /vagrant/playbook.yml && sudo ansible-playbook /vagrant/playbook.yml
SHELL
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment