Playbooks, roles, and tagging behaviors

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

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

Thanks!

Hi Michael,

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

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

Thanks!

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.

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

roles/appserver/meta/main.yml

"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?

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

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