我试图在项目中使用include_role
---
- hosts: cluster
tasks:
- block:
- name: Execute test role
include_role:
name: testrole
with_items:
- 'one'
...我的角色是
---
- name: Just debugging
debug:
...问题是,这个角色似乎是由每一个主机运行X次,其中X是主机的数量。
PLAY [cluster] *****************************************************************
TASK [setup] *******************************************************************
ok: [thisNode]
ok: [dww]
TASK [Execute test role] *******************************************************
TASK [testrole : Just debugging] ***********************************************
ok: [thisNode] => {
"msg": "Hello world!"
}
ok: [dww] => {
"msg": "Hello world!"
}
TASK [testrole : Just debugging] ***********************************************
ok: [thisNode] => {
"msg": "Hello world!"
}
ok: [dww] => {
"msg": "Hello world!"
}
PLAY RECAP *********************************************************************
dww : ok=3 changed=0 unreachable=0 failed=0
thisNode : ok=3 changed=0 unreachable=0 failed=0 为什么会发生这种事,我该怎么解决呢?
不可接受的主机:
[cluster]
thisNode ansible_host=localhost ansible_connection=local
dww我不能委托任务,因为在真正的角色中,任务必须在每个主机上执行。
使用allow_duplicates: no仍然输出相同的内容。
---
- hosts: cluster
tasks:
- name: Execute test role
include_role:
name: testrole
allow_duplicates: False
with_items:
- 'one'
...发布于 2017-02-11 01:57:21
作为一种解决方法,您可以添加allow_duplicates: false以防止Ansible使用相同的参数两次运行相同的角色。
显然,模块被循环了两次:一次是与主机一起,另一次是使用指定的项。由于它应该对所有主机运行该操作,外部循环将被执行两次。
它是一个处于预览状态的新模块,这种行为可能会成为文件的问题。
Ansible有一个内部参数BYPASS_HOST_LOOP来避免这种情况,这个机制可能应该由这个模块使用。
https://stackoverflow.com/questions/42171103
复制相似问题