Skip to content

Instantly share code, notes, and snippets.

@pixelistik
Created March 11, 2015 22:42
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pixelistik/f4c9e6814cc69c935fe1 to your computer and use it in GitHub Desktop.
Save pixelistik/f4c9e6814cc69c935fe1 to your computer and use it in GitHub Desktop.
Vagrant with self-provisioning Ansible playbook
Vagrant.configure(2) do |config|
config.vm.box = "trusty64"
config.vm.network "forwarded_port", guest: 8080, host: 9090
config.vm.provider "virtualbox" do |vb|
vb.memory = "2048"
end
$script = <<SCRIPT
# Install Ansible dependencies on first run:
if [ ! -f /etc/ansible/hosts ]; then
# Improved mirror sources for apt packages
echo 'deb mirror://mirrors.ubuntu.com/mirrors.txt trusty main restricted universe multiverse' | cat - /etc/apt/sources.list > temp && sudo mv temp /etc/apt/sources.list
echo 'deb mirror://mirrors.ubuntu.com/mirrors.txt trusty-updates main restricted universe multiverse' | cat - /etc/apt/sources.list > temp && sudo mv temp /etc/apt/sources.list
sudo apt-get update
sudo apt-get install -y python-pip
sudo pip install ansible
# Create a simple inventory file for localhost:
mkdir -p /etc/ansible
echo "[local]" > /etc/ansible/hosts
echo "localhost ansible_connection=local" >> /etc/ansible/hosts
fi
cd /vagrant
# We want Ansible's output line by line:
export PYTHONUNBUFFERED=1
# Run the actual playbook:
ansible-playbook provision/main.yml
SCRIPT
config.vm.provision "shell", inline: $script
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment