I've been experimenting with Ansible for new server setup and I was amazed to see Vagrant supports it out of the box (I guess I shouldn't be Vagrant is a great piece of software). When I tried to use it on my Windows laptop I received the following error:

> vagrant up test
Bringing machine 'test' up with 'virtualbox' provider...
There are errors in the configuration of this machine. Please fix the following errors and try again:

ansible provisioner:
* `playbook` for the Ansible provisioner does not exist on the host system: C:/path/playbook.yml

I said to myself:

It's okay I'll just install ansible on Windows. How hard could it be?

It turns out it's not simple and I don't really want to have to do this on all our computers. I know it seems like a small amount of work but it adds up.

The fix for this was for me to run the playbook inside the VM. First I setup the Vagrantfile to run a shell script:

config.vm.provision :shell, :inline =>
  "/path/to/ansible/provision.sh"

Then inside the shell script we're going to install ansible (if the ansible-playbook executable doesn't exist) and then we're going to run the playbook.

if [ ! -f /usr/bin/ansible-playbook ]
    then
    apt-get install software-properties-common
    apt-add-repository ppa:ansible/ansible
    apt-get update
    apt-get install -y ansible
fi

ansible-playbook --inventory="localhost," -c local  /path/to/ansible/playbook.yml

By using the -c local we're telling anisble to make a local connection and not use SSH because then we would need to setup keys and that seems like a lot of unnecessary work. :-)

Like this post? Don't forget to follow us on Twitter and Facebook for updates.