+++
title = "learning the ansible way"
date = "2014-08-08T19:13:07+00:00"
author = "Gibheer"
draft = false
+++

Some weeks ago I read a [blog post](http://palcu.blogspot.se/2014/06/dotfiles-and-dev-tools-provisioned-by.html) about rolling out your configs with ansible as a way to learn how to use it. The posts wasn't full of information how to do it, but his repository was a great inspiration.

As I stopped [using cfengine](/post/107) and instead wanted to use ansible, that was a great opportunity to further learn how to use it and I have to say, it is a really nice experience. Apart from a bunch configs I find every now and then, I have everything in my [config repository](https://github.com/Gibheer/configs/tree/501c2887b74b7447803e1903bd7c0781d911d363/playbooks).

The config is split at the moment between servers and workstations, but using an inventory file with localhost. As I mostly use freebsd and archlinux, I had to set the python interpreter path to different locations. There are two ways to do that in ansible. The first is to add it to the inventory

    [hosts]
    localhost

    [hosts:vars]
    ansible_connection=local
    ansible_python_interpreter=/usr/local/bin/python2

and the other is to set it in the playbook

    - hosts: hosts
      vars:
        ansible_python_interpreter: /usr/local/bin/python2
      roles:
        - vim

The latter has the small disadvantage, that running plain ansible is not possible. Ansible in the command and check mode also needs an inventory and uses the variables too. But if they are not stated there, ansible has no idea what to do. But at the moment, it isn't so much a problem.
Maybe that problem can be solved by using a [dynamic inventory](http://docs.ansible.com/intro_dynamic_inventory.html#other-inventory-scripts).

What I can definitely recommend is using roles. These are descriptions on what to do and can be filled with variables from the outside. I have used them bundle all tasks for one topic. Then I can unclude these for the hosts I want them to have, which makes rather nice playbooks. One good example is my [vim config](https://github.com/Gibheer/configs/tree/501c2887b74b7447803e1903bd7c0781d911d363/playbooks/roles/vim), as it shows [how to use lists](https://github.com/Gibheer/configs/blob/501c2887b74b7447803e1903bd7c0781d911d363/playbooks/roles/vim/tasks/main.yml).

All in all I'm pretty impressed how well it works. At the moment I'm working on a way to provision jails automatically, so that I can run the new server completely through ansible. Should make moving to a new server in the fututre much easier.
