# Playbooks, roles, and tagging behaviors

**URL:** <https://forum.ansible.com/t/playbooks-roles-and-tagging-behaviors/16312>\
**Category:** Ansible Project\
**Created:** [September 23, 2014, 10:24pm UTC](https://forum.ansible.com/t/playbooks-roles-and-tagging-behaviors/16312 "2014-09-23T22:24:10Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![E.C\_Raymond](https://avatars.discourse-cdn.com/v4/letter/e/e19adc/32.png) [@E.C\_Raymond](https://forum.ansible.com/u/E.C_Raymond)\
**Post date:** [September 23, 2014, 10:24pm UTC](https://forum.ansible.com/t/playbooks-roles-and-tagging-behaviors/16312/1 "2014-09-23T22:24:10Z")

</div>

I am experiencing some strange behavior from what I understand to be applying tags to roles/dependencies. I wrote a facts plugin to gather information about a systems role, and it includes this in the playbook run. Each system runs a playbook on its own, only managing itself.

# ansible\_local facts

127.0.0.1 | success \>\> {  
“ansible\_facts”: {  
“ansible\_local”: {  
“host\_roles”: {  
“roles”: [  
“APPSERVERS”,

“COMMON”,

]  
}  
}  
},  
“changed”: false  
}

# site.yml

---

<div class="post-metadata">

**Author:** ![Michael\_DeHaan1](https://avatars.discourse-cdn.com/v4/letter/m/5e9695/32.png) [@Michael\_DeHaan1](https://forum.ansible.com/u/Michael_DeHaan1)\
**Post date:** [September 24, 2014, 1:56am UTC](https://forum.ansible.com/t/playbooks-roles-and-tagging-behaviors/16312/2 "2014-09-24T01:56:58Z")

</div>

For starters, can you share what version of Ansible you are using?

Thanks!

---

<div class="post-metadata">

**Author:** ![E.C\_Raymond](https://avatars.discourse-cdn.com/v4/letter/e/e19adc/32.png) [@E.C\_Raymond](https://forum.ansible.com/u/E.C_Raymond)\
**Post date:** [September 24, 2014, 4:41pm UTC](https://forum.ansible.com/t/playbooks-roles-and-tagging-behaviors/16312/3 "2014-09-24T16:41:58Z")

</div>

Hi Michael,

I am using 1.7.1, and tried on latest devel build.

---

<div class="post-metadata">

**Author:** ![Michael\_DeHaan1](https://avatars.discourse-cdn.com/v4/letter/m/5e9695/32.png) [@Michael\_DeHaan1](https://forum.ansible.com/u/Michael_DeHaan1)\
**Post date:** [September 24, 2014, 6:30pm UTC](https://forum.ansible.com/t/playbooks-roles-and-tagging-behaviors/16312/4 "2014-09-24T18:30:30Z")

</div>

Ok, please file a bug about this, that the when statements need to be propagated to the role deps.

Thanks!

---

<div class="post-metadata">

**Author:** ![E.C\_Raymond](https://avatars.discourse-cdn.com/v4/letter/e/e19adc/32.png) [@E.C\_Raymond](https://forum.ansible.com/u/E.C_Raymond)\
**Post date:** [September 24, 2014, 7:38pm UTC](https://forum.ansible.com/t/playbooks-roles-and-tagging-behaviors/16312/5 "2014-09-24T19:38:24Z")

</div>

Thanks, Michael. One question about this bug/behavior, I want to verify. If tags are applied at the role level, is it supposed to run each role, regardless of the when statement?

roles:

- { role: appserver, tags: [‘initial’], when: “‘APPSERVERS’ in ansible\_local.host\_roles.roles” }

- { role: hadoop\_jobtracker, tags: [‘initial’], when: “‘HADOOP\_JOBTRACKER’ in ansible\_local.host\_roles.roles” }

In this case, both appserver and the hadoop\_jobtracker roles are applied, disregarding my when statement. Do tags take precendence over other logic?

I am able to workaround this bug by adding an include statement in the tasks for each role, and everything works properly.

---

<div class="post-metadata">

**Author:** ![E.C\_Raymond](https://avatars.discourse-cdn.com/v4/letter/e/e19adc/32.png) [@E.C\_Raymond](https://forum.ansible.com/u/E.C_Raymond)\
**Post date:** [September 24, 2014, 9:24pm UTC](https://forum.ansible.com/t/playbooks-roles-and-tagging-behaviors/16312/6 "2014-09-24T21:24:02Z")

</div>

Found the problem was with the key,value passing in the role dependencies:

# roles/appserver/meta/main.yml

---

<div class="post-metadata">

**Author:** ![Michael\_DeHaan1](https://avatars.discourse-cdn.com/v4/letter/m/5e9695/32.png) [@Michael\_DeHaan1](https://forum.ansible.com/u/Michael_DeHaan1)\
**Post date:** [September 25, 2014, 11:55am UTC](https://forum.ansible.com/t/playbooks-roles-and-tagging-behaviors/16312/7 "2014-09-25T11:55:14Z")

</div>

"Thanks, Michael. One question about this bug/behavior, I want to verify. If tags are applied at the role level, is it supposed to run each role, regardless of the when statement? "

tags and conditionals in ansible are very different things.

If you run all things tagged “X”, it would still evaluate the conditionals on all things tagged “X”. Hope this makes sense.

Curious the above typo did not produce an error, can you file a bug about that one?

---

<div class="post-metadata">

**Author:** ![E.C\_Raymond](https://avatars.discourse-cdn.com/v4/letter/e/e19adc/32.png) [@E.C\_Raymond](https://forum.ansible.com/u/E.C_Raymond)\
**Post date:** [September 25, 2014, 8:37pm UTC](https://forum.ansible.com/t/playbooks-roles-and-tagging-behaviors/16312/8 "2014-09-25T20:37:14Z")

</div>

Well, it seems there is an issue with the when statement being used in roles as well.

Maybe its because I am constructing my playbooks in a different fashion than the usual documented, but when I run a playbook file that reads:

# site.yml

---

<div class="post-metadata">

**Author:** ![David\_Karban](https://avatars.discourse-cdn.com/v4/letter/d/90db22/32.png) [@David\_Karban](https://forum.ansible.com/u/David_Karban)\
**Post date:** [September 27, 2014, 5:10am UTC](https://forum.ansible.com/t/playbooks-roles-and-tagging-behaviors/16312/9 "2014-09-27T05:10:20Z")

</div>

Hi,

when you use “when” in role definiton, it basically propagate “when” to every task in the role. So it will run, but skip all tasks inside the role.

David
