Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

allow_duplicates does not allow a role and its dependencies to be run multiple times #11205

Closed
dellis23 opened this issue Jun 8, 2015 · 6 comments
Labels
bug This issue/PR relates to a bug.
Milestone

Comments

@dellis23
Copy link

dellis23 commented Jun 8, 2015

Issue Type:

Bug Report

Ansible Version:
ansible 1.9.1
  configured module search path = None
Ansible Configuration:

N/A

Environment:

Mac OSX 10.9.5

Summary:

Roles that are included multiple times cannot have their dependencies included multiple times. The documentation states that allow_duplicates accomplish something like this so long as the dependency is included multiple times from the same role, but it does not seem to work for the aforementioned case.

Steps To Reproduce:

Here's a simple set of playbooks / roles that should illustrate the problem.

###  ./hypervisor-1.yml

---
- hosts:
    - host1
  roles:
    - role: vm
      name: red
    - role: vm
      name: blue

###  ./hypervisor-2.yml

---
- hosts:
    - host2
  roles:
    - role: vm
      name: green
    - role: vm
      name: yellow
    - role: vm
      name: purple

###  ./inventory
[hosts]
host1
host2

###  ./roles/disk/tasks/main.yml
- debug: msg="Setting up disk for {{ path }}"

###  ./roles/vm/meta/main.yml

---
allow_duplicates: yes
dependencies:
  - role: disk
    path: "/path/to/{{ name }}"

###  ./roles/vm/tasks/main.yml
- debug: msg="Installing VM {{ name }}"
Expected Results:

Running the first playbook, hypervisor-1.yml, should give output that shows a disk is set up for both red and blue, as well as the installation of the VM for both.

Actual Results:
PLAY [host1] ****************************************************************** 

GATHERING FACTS *************************************************************** 
ok: [host1]

TASK: [disk | debug msg="Setting up disk for /path/to/red"] ******************* 
ok: [host1] => {
    "msg": "Setting up disk for /path/to/red"
}

TASK: [vm | debug msg="Installing VM red"] ************************************ 
ok: [host1] => {
    "msg": "Installing VM red"
}

TASK: [vm | debug msg="Installing VM blue"] *********************************** 
ok: [host1] => {
    "msg": "Installing VM blue"
}

PLAY RECAP ******************************************************************** 
host1                      : ok=4    changed=0    unreachable=0    failed=0 

Note the disk is only set up for red and is skipped for blue.

@macster84
Copy link

Hi,

I encountered the same issue when I was provisioning some of my server machines. Trying to find a solution I've stumbled upon allow_duplicates too. However, as you've already mentioned, allow_duplicates should not apply here. The vm role is not referencing the disk role as a dependency twice. Instead the vm role is just referenced twice from the playbook.
That is a totally different use case.

The only workaround I can think of is to use includes instead of role dependencies but this effectively eliminates the whole role concept...

@dellis23
Copy link
Author

@LuedDev Yeah, I thought "oh, include should be fine", until I realized it breaks all of the variables defined in the roles as well as the tasks that include templates and files. So it's not much of a workaround unfortunately.

@joshuajcoronado
Copy link

+1

@jimi-c jimi-c added this to the v2 milestone Jul 16, 2015
@jimi-c
Copy link
Member

jimi-c commented Jul 16, 2015

@dellis23 about to push a fix up for this, but I do notice one mistake in your example above: you need to specify allow_duplicates in the disk role, not the vm role. Since you are specifying unique parameters to the vm role each invocation will be unique and thus falls outside of the duplicate detection check.

@jimi-c jimi-c closed this as completed in 052f3c2 Jul 16, 2015
@jimi-c
Copy link
Member

jimi-c commented Jul 16, 2015

Closing This Ticket

Hi!

We believe the above commit should resolve this problem for you. This will also be included in the next major release.

If you continue seeing any problems related to this issue, or if you have any further questions, please let us know by stopping by one of the two mailing lists, as appropriate:

Because this project is very active, we're unlikely to see comments made on closed tickets, but the mailing list is a great way to ask questions, or post if you don't think this particular issue is resolved.

Thank you!

@dellis23
Copy link
Author

Thank you @jimi-c ! Looking forward to trying it out.

@ansibot ansibot added bug This issue/PR relates to a bug. and removed bug_report labels Mar 6, 2018
@ansible ansible locked and limited conversation to collaborators Apr 25, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug This issue/PR relates to a bug.
Projects
None yet
Development

No branches or pull requests

6 participants