Recently upgrade to ansible-core 2.15 and some of my roles are no longer included even though they are in the meta dependencies list.
To demonstrate this, I have 3 role
role1
role2
role3
all three roles have a single task
- name: Now in {{ role_name }}
debug:
msg: “running tasks in {{ role_name }}”
role1 has meta/main.yml contents
dependencies:
- role: role2
when: doit|default(True)
- role: role3
role2 has meta/main.yml contents
dependencies:
- role: role3
running a playbook that includes role1 I get the following
playbook.yml -e ‘{ doit: True }’
TASK [role3 : Now in role3] ******************
ok: [myhost] => {
“msg”: “running tasks in role3”
}
TASK [role2 : Now in role2] ****************
ok: [myhost] => {
“msg”: “running tasks in role2”
}
TASK [role1 : Now in role1] ****************
ok: [myhost] => {
“msg”: “running tasks in role1”
}
I think this occurs for the following logic
- role1 is invoked due to role1 being specified in the playbook.yml
- role1 dependencies are invoked prior to role1 tasks
- role2 is invoked because doit is True
- role2 dependencies are invoked prior to role2 tasks
- role3 is invoked
- role3 tasks are run (first task)
- role2 tasks are run (second task)
- role3 would be invoked from the role1 dependencies, but since it has already been invoked from the role2 dependecies, it is ignored
- role1 tasks are run (third task)
This is what I would expect, and is what happened before I upgraded to ansible-core 2.15
The issue is that if doit is False, role3 is never invoked.
playbook.yml -e ‘{ doit: False }’
TASK [role3 : Now in role3] ****************
skipping: [myhost]
TASK [role2 : Now in role2] ****************
skipping: [myhost]
TASK [role1 : Now in role1] ****************
ok: [myhost] => {
“msg”: “running tasks in role1”
}
It seems that the dependencies in role1 where role3 is included is masked by role2 being skipped. what used to happen is
playbook.yml -e ‘{ doit: False }’
TASK [role3 : Now in role3] ****************
skipping: [myhost]
TASK [role2 : Now in role2] ****************
skipping: [myhost]
TASK [role3 : Now in role3] ******************
ok: [myhost] => {
“msg”: “running tasks in role3”
}
TASK [role1 : Now in role1] ****************
ok: [myhost] => {
“msg”: “running tasks in role1”
}
The dependency of role3 from the meta/main.yml of role1 has no when clause, and since it has not been invoked yet, it gets invoked and its dependencies AND tasks are run.
Is this a bug?
If it is not a bug, how do I get role3 to be invoked when somewhere in the dependencies of role2 there was a skipped role3?
Thanks.