[Ansible] – How to use tags?

Tags is an attribute which can be used to allow or not run some tasks when just some specific tag is informed. It can be useful when is required some specific action when the script will be executed in a development environment for example. Following an example.

---
- hosts: all
  tasks:
  - name: Install postgresql 
    yum:
      name: postgresql
      state: latest
    tags:
      - development
  - name: Start postgresql 
    service: 
      name: postgresql 
      state: started

Then, if the above playbook is executed with the following command the task to install the postgresql will be performed. 

$ ansible-playbook playbook.yml –tags ‘development’

Also, it is possible to skype the execution of some tags via the parameter –skip-tags  as the following example.

$ ansible-playbook playbook.yml –skip-tags ‘test’

For further information check the Tags Ansible documentation  

Leave a comment