We've been testing ansible for our development virtual machine.

It's using yaml as base configuration provisioning and a cfg config file for the hosts.

The Vagrantfile can be defined like this for an ansible provision: :private_network, ip: ""
config.vm.provision :ansible do |ansible|
  ansible.playbook = "provisioning/playbook.yml"
  ansible.inventory_file = "provisioning/ansible_hosts"
  ansible.verbose = true
  ansible.extra_vars = {user: 'vagrant',  hosts: 'vagrant'}
  ansible.sudo = true

Notice extra_vars user and hosts, it will allow customizing the variables for a local provision.

You can create the ansible_hosts file with something like that:



For a very simple playbook.yml that just updates your apt repository:

- user:  '{{ user }}' 
  hosts:  '{{ hosts }}' 
  - name: ensure packages list is at the latest version
    apt: update_cache=yes

I recommend to install latest version of ansible. If you are a Debian user you can build package with a make deb.

Now with vagrant you can simply do a vagrant up and after provisioning with vagrant provision.

You can also use your recipe for your local machine with:

sudo ansible-playbook provisioning/playbook.yml -vvv --connection=local \
  --inventory-file=provisioning/ansible_hosts \
  --extra-vars "hosts=localhost user=$USER"

Ansible is a very simple tool to understand and maintain with its yaml files.

blog comments powered by Disqus