cancel
Showing results for 
Search instead for 
Did you mean: 
Trevor
Starfighter Starfighter
Starfighter
  • 290 Views

Ansible Tags

What are Ansible tags?  

How are Ansible tags used?

Trevor "Red Hat Evangelist" Chandler
Labels (2)
2 Replies
Blue_bird
Flight Engineer
Flight Engineer
  • 208 Views

Ansible tags are keywords used to mark and control the execution of specific tasks, roles, or plays within a playbook. They allow you to selectively run or skip certain parts of a playbook, which is useful for debugging, testing, or selectively applying changes...!

Thanks

Chetan_Tiwary_
Community Manager
Community Manager
  • 188 Views

Ansible tags are like labels you assign to individual actions (tasks) within your playbooks. These labels act as runtime selectors, enabling you to instruct Ansible to execute or skip specific tasks when you run the playbook. Although the usual workflow involves running an entire playbook from beginning to end, the ability to target and execute particular tasks on demand offers significant flexibility and efficiency.

 

---

- hosts: localhost
  gather_facts: False
  tasks:

    - name: Hello tag example
      debug:
        msg: "Hello!"
      tags:
        - hello

    - name: No tag example
      debug:
        msg: "How are you?"

    - name: Goodbye tag example
      debug:
        msg: "Goodbye!"
      tags:
        - goodbye

ansible-playbook example.yml --tags "<tag-name>" (the task with this tag will be executed only )

ansible-playbook example.yml --skip-tags "<tag-name>" ( the task with this tag will be skipped while rest of the play will be executed ).

apart from this, ansible has always and never tag which helps you to execute a task from the playbook always and never respectively as the name suggests.

https://docs.ansible.com/ansible/2.9/user_guide/playbooks_tags.html

 

0 Kudos
Join the discussion
You must log in to join this conversation.