Role dependencies not being fulfilled

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

  1. role1 is invoked due to role1 being specified in the playbook.yml
  2. role1 dependencies are invoked prior to role1 tasks
  3. role2 is invoked because doit is True
  4. role2 dependencies are invoked prior to role2 tasks
  5. role3 is invoked
  6. role3 tasks are run (first task)
  7. role2 tasks are run (second task)
  8. role3 would be invoked from the role1 dependencies, but since it has already been invoked from the role2 dependecies, it is ignored
  9. 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.

Are you using 2.15.5 or later? This looks like the issue I fixed in [2.15] Only mark a role as complete once a task in it executes by s-hertel · Pull Request #81668 · ansible/ansible · GitHub.

Thanks. That looks like the fix. I am running 2.15.3
I will get this updated.

1 Like