I think I have discovered an inconsistent behavior in Ansible when dealing
with role dependencies. When I'm trying to use a role through another role
twice in the same play, it seems like the second execution of the role
skips the evaluation of dependencies. Please see the example bellow:
cat <<END > ./hosts
localhost ansible_python_interpreter=/usr/bin/python2
END
mkdir -p ./roles/role0/meta
cat <<END > ./roles/role0/meta/main.yaml
---
dependencies:
- role: role2
c: "{{ a }}"
when: not skip_in_role1
END
mkdir -p ./roles/role1/meta
cat <<END > ./roles/role1/meta/main.yaml
---
dependencies:
- role: role2
c: "{{ b }}"
END
mkdir -p ./roles/role2/meta
cat <<END > ./roles/role2/meta/main.yaml
---
dependencies:
- role: role3
d: "{{ c }}"
END
mkdir -p ./roles/role2/tasks
cat <<END > ./roles/role2/tasks/main.yaml
---
- debug:
msg: Hello from role2
END
mkdir -p ./roles/role3/tasks
cat <<END > ./roles/role3/tasks/main.yaml
---
- debug:
msg: Hi from {{ d }}
END
cat <<END > ./site.yaml
---
- hosts: localhost
gather_facts: false
connection: local
vars:
skip_in_role1: false
roles:
- role: role0
a: role0 branch
- role: role1
b: role1 branch
END
The output of the play (executed with Ansible v1.9.1) is:
PLAY [localhost]
**************************************************************
TASK: [role3 | debug ]
********************************************************
ok: [localhost] => {
"msg": "Hi from role0 branch"
}
TASK: [role2 | debug ]
********************************************************
ok: [localhost] => {
"msg": "Hello from role2"
}
TASK: [role2 | debug ]
********************************************************
ok: [localhost] => {
"msg": "Hello from role2"
}
PLAY RECAP
********************************************************************
localhost : ok=3 changed=0 unreachable=0 failed=0
You can notice that there is no "Hi from role1 branch" output here.
Interesting is that if I set the "skip_in_role1" variable to "true", to
actually skip all the "role0 branch", the dependencies in the "role2"
through the "role1 branch" are still not being evaluated (there is no "Hi
from role1 branch" message printed out):
PLAY [localhost]
**************************************************************
TASK: [role3 | debug ]
********************************************************
skipping: [localhost]
TASK: [role2 | debug ]
********************************************************
skipping: [localhost]
TASK: [role2 | debug ]
********************************************************
ok: [localhost] => {
"msg": "Hello from role2"
}
PLAY RECAP
********************************************************************
localhost : ok=1 changed=0 unreachable=0 failed=0
Please could somebody give me an insight why this is happening and whether
this is a bug or a "feature"?
--
You received this message because you are subscribed to the Google Groups
"Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/ansible-project/41243e7d-f05d-4be3-b8b6-914574aff82e%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.