Using Ansible with Vagrant and Windows
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. :-)
Scott Keck-Warren
Scott is the Director of Technology at WeCare Connect where he strives to provide solutions for his customers needs. He's the father of two and can be found most weekends working on projects around the house with his loving partner.
Top Posts
- Working With Soft Deletes in Laravel (By Example)
- Fixing CMake was unable to find a build program corresponding to "Unix Makefiles"
- Upgrading to Laravel 8.x
- Get The Count of the Number of Users in an AD Group
- Multiple Vagrant VMs in One Vagrantfile
- Fixing the "this is larger than GitHub's recommended maximum file size of 50.00 MB" error
- Changing the Directory Vagrant Stores the VMs In
- Accepting Android SDK Licenses From The OSX Command Line
- Fixing the 'Target class [config] does not exist' Error
- Using Rectangle to Manage MacOS Windows