Patrick
Patrick

Reputation: 5994

Ansible roles depending on other roles not running multiple times

I'm running Ansible 1.9.3 and have been unable to get the role dependency wheel/tire example from the Ansible documentation working.

$ ansible --version
ansible 1.9.3
  configured module search path = None

Here are my files:

$ find ./ -type f | while read f; do printf "# %s\n" "$f"; cat "$f"; printf "\n\n"; done

# ./inventory
[webservers]
example.com

# ./roles/app/meta/main.yml
---
dependencies:
  - { role: wheel, n: 1 }
  - { role: wheel, n: 2 }
  - { role: wheel, n: 3 }
  - { role: wheel, n: 4 }

# ./roles/tire/tasks/main.yml
- name: "tire {{ n }}"
  command: "echo tire {{ n }}"

# ./roles/wheel/meta/main.yml
---
allow_duplicates: yes
dependencies:
  - { role: tire }

# ./roles/wheel/tasks/main.yml
- name: "wheel {{ n }}"
  command: "echo wheel {{ n }}"

# ./site.yml
---
- include: webservers.yml

# ./webservers.yml
---
- hosts: webservers
  roles:
    - role: app

So the app role depends on four instances of the wheel role, which in turn depend on the tire role.

However, running the playbook shows only one execution of the tire task:

$ ansible-playbook -v -i inventory site.yml

PLAY [webservers] ************************************************************* 

GATHERING FACTS *************************************************************** 
ok: [example.com]

TASK: [tire | tire 1] ********************************************************* 
changed: [example.com] => {"changed": true, "cmd": ["echo", "tire", "1"], "delta": "0:00:00.004721", "end": "2015-09-29 16:55:27.075745", "rc": 0, "start": "2015-09-29 16:55:27.071024", "stderr": "", "stdout": "tire 1", "warnings": []}

TASK: [wheel | wheel 1] ******************************************************* 
changed: [example.com] => {"changed": true, "cmd": ["echo", "wheel", "1"], "delta": "0:00:00.004355", "end": "2015-09-29 16:55:27.806182", "rc": 0, "start": "2015-09-29 16:55:27.801827", "stderr": "", "stdout": "wheel 1", "warnings": []}

TASK: [wheel | wheel 2] ******************************************************* 
changed: [example.com] => {"changed": true, "cmd": ["echo", "wheel", "2"], "delta": "0:00:00.005012", "end": "2015-09-29 16:55:28.539339", "rc": 0, "start": "2015-09-29 16:55:28.534327", "stderr": "", "stdout": "wheel 2", "warnings": []}

TASK: [wheel | wheel 3] ******************************************************* 
changed: [example.com] => {"changed": true, "cmd": ["echo", "wheel", "3"], "delta": "0:00:00.003573", "end": "2015-09-29 16:55:29.259193", "rc": 0, "start": "2015-09-29 16:55:29.255620", "stderr": "", "stdout": "wheel 3", "warnings": []}

TASK: [wheel | wheel 4] ******************************************************* 
changed: [example.com] => {"changed": true, "cmd": ["echo", "wheel", "4"], "delta": "0:00:00.003541", "end": "2015-09-29 16:55:29.981742", "rc": 0, "start": "2015-09-29 16:55:29.978201", "stderr": "", "stdout": "wheel 4", "warnings": []}

PLAY RECAP ******************************************************************** 
example.com : ok=6    changed=5    unreachable=0    failed=0   

I've tried various combinations of allow_duplicates: yes|no in the two meta/main.yml files, but get the same result every time. The goal is to have four executions of both the wheel and tire tasks, with n equal to 1,2,3,4.

Upvotes: 2

Views: 1477

Answers (1)

Dan
Dan

Reputation: 1986

I had this same issue and submitted a ticket to the Ansible github repo: https://github.com/ansible/ansible/issues/11205

It has been merged into v2.0. Since 2.0 hasn't been released yet and it's unclear what migration will entail, I was forced to restructure my roles. I believe I combined them into the same role, unfortunately.

Upvotes: 3

Related Questions