Ansible Tags

Placing tags inside playbooks will allow you to select specific tasks from within. 

Tip: It is possible to reuse the same tag in more than one task. Example below uses different tags to differentiate between tasks.

$ cat hello.yml

– name: Tags
hosts: localhost
tasks:

– name: Debug Module Message One

debug:
msg:
– “Welcome One!”

tags: one

– name: Debug Module Message Two

debug:
msg:
– “Welcome Two!”

tags: two

Example…

ansible-playbook hello.yml –tag two

$ ansible-playbook hello.yml –tag two

PLAY [Tags] *

TASK [Gathering Facts] ****
ok: [localhost]

TASK [Two] **
ok: [localhost] => {
“msg”: [
“Welcome Two!”
]
}

PLAY RECAP **
localhost : ok=2 changed=0 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0

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 )

Facebook photo

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

Connecting to %s