Ansible skips evaluation of dependencies

45 views
Skip to first unread message

Jiri

unread,
May 7, 2015, 7:36:28 AM5/7/15
to ansible...@googlegroups.com
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"?

Brian Coca

unread,
May 7, 2015, 10:27:02 AM5/7/15
to ansible...@googlegroups.com
roles will only be added once unless you allow duplicates, for more
info https://docs.ansible.com/playbooks_roles.html


--
Brian Coca
Reply all
Reply to author
Forward
0 new messages