[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  

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s