


Also if my examples aren’t working, check the comments for errata and updates – and if you don’t find what you’re looking for, add a comment yourself! The syntax for setting which user to use changed between versions of ansible, this is the currently-correct syntax but you’ll see lots of examples using the older ones too so if you’re copying/pasting examples and having issues, check this. The second block teaches the vagrant box its name which prevents an annoying warning when sudoing things.
VAGRANT ANSIBLE INSTALL
Some of this is specific to the box that I had some issues with – since Python 2.7 isn’t installed by default, currently ansible requires this older version of Python and so I found I needed to disable the fact-gathering and then install the required python to get the process started. Lineinfile: dest=/etc/hosts line='127.0.0.1 ubuntu-xenial' owner=root group=root mode=0644 Here’s a quick cheatsheet of some of the patterns from my playbook.yml: You’ll probably want to refer to the excellent documentation for more information on the various modules that are in these examples and for others you want to use yourself. Rather than using the commands we already know, and typing them all in turn though, ansible has neat wrappers for almost all the tasks we could want to do. The playbook is the recipe for cooking up the virtual machine you desire: it can be used to install packages, restart services, run commands, or really anything else we need to do to get the platform we need.

In the Vagrantfile example above, we set the provisioner to be ansible and give the playbook parameter as playbook.yml. In particular its declarative approach makes it easy to iteratively build up a machine by adding to the ansible recipe and reprovisioning repeatedly rather than always having to destroy the machine and start completely from scratch to test changes. There are a few different tools that would fit here but I’ve picked ansible for my VMs and so far I have found it quite approachable. This will bring up a basic Ubuntu 16.04 box (my preferred distro although it shipped with Python 3 rather than 2 which is why I need the ansible_python_interpreter setting and why I need to set the box name as by default the early versions of this box had a hardcoded name which broke things when you used it as the basis of more than one VM) and then hand off to ansible to do everything else. "ansible_python_interpreter" => "/usr/bin/python2.7" Here’s that basic config:Ĭonfig.vm.network :private_network, ip: "192.168.121.8"Ĭonfig.vm.provision "ansible" do |ansible| Here I’m setting the simplest options – which box to use, a name for the box, any directories I want to mount, and then the instruction to use ansible for the rest. Vagrant is configured with a Vagrantfile. I thought I’d share some examples of my setup, in case anyone is interested, but more importantly so I can swiftly look this up when I start the next new project! Start with the Vagrantfile They cover quite a wide range of system requirements and so I’ve been creating ansible-provisioned vagrant machines for each one to make it easy to set up on other platforms. How do I go about getting additional debug information? I've already added ansible.verbose = true to my vagrant config which results in the dictionaries being displayed within the output above.With my new job came, of course, lots of new projects.
VAGRANT ANSIBLE SERIES
It appears to deploy fine, but I have seen a failure message after what looks like a series of successful steps: » vagrant provision ~/vm/blvagrant 1 ↵ Rather than rewriting my scripts, I took a sample and attempted to deploy it. My application is currently provisioned with shell scripts in Vagrant. I am investigating Ansible for server and application provisioning.
