Ansible tags

 

To run specific part or exclude specific part in a playbook we an use tags attrubute.

Here is my example playbook with name tags_example.yml:

---
- hosts: all
  tasks:
    - name: Hello
      shell: "echo hello"
      tags:
         - hello

    - name: Bye
      shell: "echo bye"
      tags:
         - bye

In above playbook we have two tasks Hello and Bye with tags hello and bye tags respectively.

To execute above playbook use following command:

$ ansible-playbook yml/tags_example.yml

Above command will execute both tasks Hello and Bye respectively.

Now lets see how to execute specific part of play book.

We can use --tags "<tagName>" argument with ansible-playbook to execute only specific tasks and use --skip-tasks "<tagName>" to skip specific tasks from execution.

To execute all tasks with hello tag use following command:

$ ansible-playbook yml/tags_example.yml --tags "hello"

To skip all tasks with hello tag use following command:

$ ansible-playbook yml/tags_example.yml --skip-tags "hello"

To execute multiple tags use following command:

$ ansible-playbook yml/tags_example.yml --tags "hello,bye"

To skip multiple tags use following command:

$ ansible-playbook yml/tags_example.yml --skip-tags "hello,bye"

I hope this will helps to understand tags concept in Ansible.

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 )

Twitter picture

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

Facebook photo

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

Google+ photo

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

Connecting to %s