Victor Castell   Dkron    About

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_repository: repo='deb dist 10gen' state=present
      tags: mongodb

    - apt: pkg={{ item }}={{ mongodb_version }} update-cache=yes
        - 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</code></pre></div>

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

Written on May 13, 2014.