Discussion:
[ansible-project] allow_duplicates: yes doesn't work as expected
Daniel Wendler
2015-07-22 14:13:12 UTC
Permalink
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 }



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?
--
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 ansible-project+***@googlegroups.com.
To post to this group, send email to ansible-***@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/3af29ef8-f635-4a1a-b0c6-3f88abd3b05e%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Daniel Wendler
2015-07-22 14:17:56 UTC
Permalink
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?
--
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 ansible-project+***@googlegroups.com.
To post to this group, send email to ansible-***@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/f5e1cdc8-993d-414d-aaac-b16fd71753d4%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Daniel Wendler
2015-07-22 14:51:50 UTC
Permalink
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?
--
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 ansible-project+***@googlegroups.com.
To post to this group, send email to ansible-***@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/a30da201-3bd0-4ade-9e56-46df383169e9%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Daniel Wendler
2015-07-24 06:55:52 UTC
Permalink
I have opened an Issue <https://github.com/ansible/ansible/issues/11707> on
github and *jimi-c* explained it logical:

Hi @MorphBonehunter <https://github.com/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.
--
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 ansible-project+***@googlegroups.com.
To post to this group, send email to ansible-***@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/24b30049-9ba8-4d4a-82d8-0e67e05246b4%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Loading...