allow_duplicates: yes doesn't work as expected

208 views
Skip to first unread message

Daniel Wendler

unread,
Jul 22, 2015, 10:17:56 AM7/22/15
to Ansible Project
Hello @all

today i took another try on the role dependency feature and realize that this doesn't work as i expect this.
First at all:
ansible --version
ansible 1.9.2
  configured module search path = /usr/share/ansible

I try to explain what i mean with an sample playbook/roles:
$ cat play-test.yml
---
- name: dependency test
  gather_facts: false
  hosts: localhost

  roles:
    - { role: feature1 }
    - { role: feature2 }

$ cat roles/feature1/tasks/main.yml
---
- name: in feature1
  debug: msg="here we are in feature1"

$ cat roles/feature1/meta/main.yml
---
allow_duplicates: yes
dependencies:
  - { role: base }

$ cat roles/feature2/tasks/main.yml 
---
- name: in feature2
  debug: msg="here we are in feature2"

$ cat roles/feature2/meta/main.yml 
---
allow_duplicates: yes
dependencies:
  - { role: base }

$ cat roles/base/tasks/main.yml 
---
- name: in base
  debug: msg="here we are in base"

I would expect because of the allow_duplicates: yes that the basic role is executed twice but that doesn't happen:

$ ansible-playbook play-test.yml 

PLAY [dependency test] ******************************************************** 

TASK: [base | in base] ******************************************************** 
ok: [localhost] => {
    "msg": "here we are in base"
}

TASK: [feature1 | in feature1] ************************************************ 
ok: [localhost] => {
    "msg": "here we are in feature1"
}

TASK: [feature2 | in feature2] ************************************************ 
ok: [localhost] => {
    "msg": "here we are in feature2"
}

PLAY RECAP ******************************************************************** 
localhost                  : ok=3    changed=0    unreachable=0    failed=0   

Is this the right behavior?

Daniel Wendler

unread,
Jul 22, 2015, 10:51:50 AM7/22/15
to Ansible Project
I extend the example with another pice named tags:
$ cat play-test.yml 
---
- name: dependency test
  gather_facts: false
  hosts: localhost

  roles:
    - { role: feature1, tags: feature1 }
    - { role: feature2, tags: feature2 }


This gives me another strage behavior if you look at the following output (i used --list-tags for simplicity):
$ ansible-playbook play-test.yml --list-tasks

playbook: play-test.yml

  play #1 (dependency test): TAGS: []
    in base TAGS: [feature1]
    in feature1 TAGS: [feature1]
    in feature2 TAGS: [feature2]

As there is still allow_duplicates: yes active, i would expect the execution of base 2 times.
So i try the following (as this is my initial intention to use role dependencys and tags):
$ ansible-playbook play-test.yml --list-tasks -t feature1

playbook: play-test.yml

  play #1 (dependency test): TAGS: []
    in base TAGS: [feature1]
    in feature1 TAGS: [feature1]

Looks OK to me, but then:
$ ansible-playbook play-test.yml --list-tasks -t feature2

playbook: play-test.yml

  play #1 (dependency test): TAGS: []
    in feature2 TAGS: [feature2]

So in the second try the base role isn't run at all.
This is definitely not the expected behavior. In the role "feature2" the dependency is set to the "basic" role and in my eyes if i specify an role with an tag the dependency should run (like the first one).

Did i miss something?



Daniel Wendler

unread,
Jul 24, 2015, 2:55:52 AM7/24/15
to Ansible Project, daniel.we...@gmail.com
I have opened an Issue on github and jimi-c explained it logical:

  Hi @MorphBonehunter, the problem is because allow_duplicates needs to be set on the base role, not in each of the intermediate roles. Move it there and this should work for you.


I've move the "allow_duplicates: yes" to the base role and delete the entry in all other roles and it works like expected...so that was clearly my fault.
$ ansible-playbook play-test.yml --list-tasks 

playbook: play-test.yml

  play #1 (dependency test): TAGS: []
    in base TAGS: [feature1]
    in feature1 TAGS: [feature1]
    in feature2 TAGS: [feature2]

But something is still strange when i remove the "allow_duplicates: yes" also in the base role i got the following:
     $ ansible-playbook play-test.yml --list-tasks -t feature1
 
    playbook: play-test.yml
 
      play #1 (dependency test):    TAGS: []
        in base TAGS: [feature1]
        in feature1 TAGS: [feature1]
 
     $ ansible-playbook play-test.yml --list-tasks -t feature2
 
    playbook: play-test.yml
 
      play #1 (dependency test):    TAGS: []
        in feature2 TAGS: [feature2]

So in the second case the base role isn't executed and this i think is not as expected.
Reply all
Reply to author
Forward
0 new messages