Victor Castell

Tue, May 13, 2014

Ansible tip 1

As a general rule always tag your roles.

Tagging individual role tasks, allows you to selectively apply just one part of the configuration when you need it.

While the advantatges of this may not seem clear at the beginning, you have to take into account that ansible is not the fastest kid on the block. Doing this always, allows great flexibility and high level of granularity when running your playbooks.

This is an example of a mongodb setup role:

    - apt_key: url=http://docs.mongodb.org/10gen-gpg-key.asc state=present
      tags: mongodb

    - apt_repository: repo='deb http://downloads-distro.mongodb.org/repo/ubuntu-upstart dist 10gen' state=present
      tags: mongodb

    - apt: pkg={{ item }}={{ mongodb_version }} update-cache=yes
      with_items:
        - mongodb-org
        - mongodb-org-server
        - mongodb-org-shell
        - mongodb-org-mongos
        - mongodb-org-tools
      tags: mongodb

    - service: name=mongod state=started
      tags: mongodb

    - template: src=etc/mongod.conf dest=/etc/mongod.conf owner=root group=root mode=0644
      notify: restart mongod
      tags: mongodb

As a best practice I always tag the role with the role name.