Skip to content

Instantly share code, notes, and snippets.

@mss
Created October 8, 2013 11:49
Show Gist options
  • Save mss/6883503 to your computer and use it in GitHub Desktop.
Save mss/6883503 to your computer and use it in GitHub Desktop.
Use ansible with a local connection in Vagrant (no ansible required on the host)
# -*- mode: ruby -*-
# vi: set ft=ruby :
VAGRANTFILE_API_VERSION = "2"
Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
config.vm.box = "ubuntu-precise-12.04.x-amd64-virtualbox-cloudimg"
config.vm.box_url = "http://cloud-images.ubuntu.com/vagrant/precise/current/precise-server-cloudimg-amd64-vagrant-disk1.box"
config.vm.provision "shell" do |shell|
# Put the path to your playbook here
shell.args = ""
shell.inline = <<-end
#!/bin/bash
ppa=
while getopts p OPTNAME; do
case "$OPTNAME" in
p)
ppa=ppa:rquillo/ansible
;;
*)
exit 1
;;
esac
done
shift $((OPTIND - 1))
playbook=${1:-playbook.yml}
set -ex
sed -i -e "/ $(lsb_release -cs)-backports /s/^# *//" /etc/apt/sources.list
if [ -n "$ppa" ]; then
if ! dpkg -s python-software-properties 2>/dev/null | grep -q '^Status:.* installed'; then
apt-get update
apt-get install -y python-software-properties
fi
apt-add-repository -y "$ppa"
fi
apt-get update
apt-get install -y ansible
ansible-playbook /vagrant/$playbook -c local -i /etc/hostname
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment