Ansible角色取决于其他角色未运行多次

时间:2015-09-29 17:01:34

标签: dependencies ansible ansible-playbook

我正在运行Ansible 1.9.3并且无法从Ansible文档中获取role dependency wheel/tire example

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

以下是我的文件:

$ 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

因此app角色取决于wheel角色的四个实例,而后者又取决于tire角色。

但是,运行playbook只显示tire任务的一次执行:

$ 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   

我在两个allow_duplicates: yes|no文件中尝试了meta/main.yml的各种组合,但每次都得到相同的结果。目标是对wheeltire任务执行四次执行,n等于1,2,3,4。

1 个答案:

答案 0 :(得分:3)

我遇到了同样的问题,并向Ansible github回购提交了一张票:https://github.com/ansible/ansible/issues/11205

它已合并到v2.0中。由于2.0还没有发布,而且不清楚迁移会带来什么,我被迫重组我的角色。不幸的是,我相信我把它们组合成了同一个角色。