Consistent hosts file with Ansible

One of the things, that I hate the most about an infrastructure is to have an inconsistent platform. Obviously DNS runs but it could fail, and then it’s always good to rely on your /etc/hosts. However before this, it must be consistent.

The template file:   localhost   {{ ansible_hostname }}     bla1.mydomain     bla2.mydomain     bla3.mydomain     bla4.mydomain     bla5.mydomain

The yaml file:

- hosts: all

      - name: template test
        action: template src=templates/hosts.j2 dest=/etc/hosts

Run it:

$ ansible-playbook -i hosts_infra --user=leseb --sudo hosts.yml

I hope consistency maniacs will like this ;-)