1
我有一个包含两个播放的ansible playbook,第一个播放的输出将被第二个播放器使用。所以我使用寄存器变量来存储输出。问题是我的游戏打算在多主机而不是单个主机上工作,并且每次都会覆盖寄存器的输出,而我没有最后(n-1)次执行的值。使用寄存器变量来存储多主机播放的值
我的剧本是这样的:
- name: Perform task
hosts: db_server
connection: local
gather_facts: no
vars:
- method: "{{ method }}"
roles:
- {role: run_custom_module, tags: ["maintenance"]}
- name: Second task based on output of first
hosts: db_server
connection: local
gather_facts: no
vars:
- method: "{{ method }}"
roles:
- {role: run_custom_module, when: result=="some_string"}
作用run_custom_module看起来是这样的:
- name: Executing the custom module
run_custom_module:
task: "Run custom py module"
var: "{{ method }}"
register: result
清单文件看起来像:
[db_server]
1.1.1.1
2.2.2.2
3.3.3.3
在with_items的情况下寄存器变量将输出存储在名为的列表中结果,请参考here。在类似的理由,我怎么能将多主机播放的输出存储在寄存器变量中,以便它可以在同一个剧本的第二个播放中使用?
那么是什么问题? – techraf
如何访问播放器中每个主机生成的输出?它被覆盖。 :( –
就像你在你发布的代码中做的那样:一个注册变量就像是一个事实,Ansible单独存储每个主机的值 – techraf