Last active
January 25, 2017 22:06
-
-
Save mohclips/8d989794cf6098731a5067d97b769148 to your computer and use it in GitHub Desktop.
Tags in include and blocks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# vim: noai:ts=2:sw=2:et | |
--- | |
- name: "Test block tag include block tag" | |
hosts: localhost | |
connection: local | |
gather_facts: no | |
tasks: | |
- debug: msg="always" | |
tags: always | |
- include: b.yml | |
tags: t_incl_b | |
- debug: msg="another tag" | |
tags: t_another_tag |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# vim: noai:ts=2:sw=2:et | |
--- | |
- debug: msg="b.yml no tag" | |
- debug: msg="tag t_b1" | |
tags: t_b1 | |
- block: | |
- debug: msg="inside b.yml t_b_block" | |
- debug: msg="tag b2 inside block" | |
tags: t_b2 | |
tags: t_b_block |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# | |
# tags are complex animals, you need to be carefuk with them - especially inside 'include:' | |
# | |
# | |
# What tags are available to us | |
# | |
$ ansible-playbook --list-tags a.yml | |
[WARNING]: provided hosts list is empty, only localhost is available | |
playbook: a.yml | |
play #1 (localhost): Test block tag include block tag TAGS: [] | |
TASK TAGS: [always, t_another_tag, t_b1, t_b2, t_b_block, t_incl_b] | |
# | |
# run playbook, no tags selected/unselected | |
# | |
$ ansible-playbook a.yml | |
[WARNING]: provided hosts list is empty, only localhost is available | |
PLAY [Test block tag include block tag] **************************************** | |
TASK [debug] ******************************************************************* | |
ok: [localhost] => { | |
"msg": "always" | |
} | |
TASK [debug] ******************************************************************* | |
ok: [localhost] => { | |
"msg": "b.yml no tag" | |
} | |
TASK [debug] ******************************************************************* | |
ok: [localhost] => { | |
"msg": "tag t_b1" | |
} | |
TASK [debug] ******************************************************************* | |
ok: [localhost] => { | |
"msg": "inside b.yml t_b_block" | |
} | |
TASK [debug] ******************************************************************* | |
ok: [localhost] => { | |
"msg": "tag b2 inside block" | |
} | |
TASK [debug] ******************************************************************* | |
ok: [localhost] => { | |
"msg": "another tag" | |
} | |
PLAY RECAP ********************************************************************* | |
localhost : ok=6 changed=0 unreachable=0 failed=0 | |
------------------------------------------------------------------------ 0.01s | |
Playbook finished: Wed Jan 25 22:01:47 2017, 1 total tasks. 0:00:00 elapsed. | |
# | |
# run playbook, select one tag inside include | |
# | |
$ ansible-playbook a.yml --tags=t_b1 | |
[WARNING]: provided hosts list is empty, only localhost is available | |
PLAY [Test block tag include block tag] **************************************** | |
TASK [debug] ******************************************************************* | |
ok: [localhost] => { | |
"msg": "always" | |
} | |
TASK [debug] ******************************************************************* | |
ok: [localhost] => { | |
"msg": "tag t_b1" | |
} | |
PLAY RECAP ********************************************************************* | |
localhost : ok=2 changed=0 unreachable=0 failed=0 | |
------------------------------------------------------------------------ 0.01s | |
Playbook finished: Wed Jan 25 22:02:07 2017, 1 total tasks. 0:00:00 elapsed. | |
# | |
# run playbook - select tag inside a block which also has a tag | |
# | |
# NOTE: this ignores the block tag and only runs the selected tag!! | |
# | |
nick@nick-Lenovo-Z710:~/workspace/openstack/k5-infra2$ ansible-playbook a.yml --tags=t_b2 | |
[WARNING]: provided hosts list is empty, only localhost is available | |
PLAY [Test block tag include block tag] **************************************** | |
TASK [debug] ******************************************************************* | |
ok: [localhost] => { | |
"msg": "always" | |
} | |
TASK [debug] ******************************************************************* | |
ok: [localhost] => { | |
"msg": "tag b2 inside block" | |
} | |
PLAY RECAP ********************************************************************* | |
localhost : ok=2 changed=0 unreachable=0 failed=0 | |
------------------------------------------------------------------------ 0.02s | |
Playbook finished: Wed Jan 25 22:03:48 2017, 1 total tasks. 0:00:00 elapsed. | |
# | |
# run playbook, ignore the block in the include | |
# | |
$ ansible-playbook a.yml --skip-tags=t_b_block | |
[WARNING]: provided hosts list is empty, only localhost is available | |
PLAY [Test block tag include block tag] **************************************** | |
TASK [debug] ******************************************************************* | |
ok: [localhost] => { | |
"msg": "always" | |
} | |
TASK [debug] ******************************************************************* | |
ok: [localhost] => { | |
"msg": "b.yml no tag" | |
} | |
TASK [debug] ******************************************************************* | |
ok: [localhost] => { | |
"msg": "tag t_b1" | |
} | |
TASK [debug] ******************************************************************* | |
ok: [localhost] => { | |
"msg": "another tag" | |
} | |
PLAY RECAP ********************************************************************* | |
localhost : ok=4 changed=0 unreachable=0 failed=0 | |
------------------------------------------------------------------------ 0.02s | |
Playbook finished: Wed Jan 25 22:02:29 2017, 1 total tasks. 0:00:00 elapsed. | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment