我有一个包含两个剧本的 ansible 剧本,第一个剧本的输出将由第二个剧本使用。所以我使用寄存器变量来存储输出。问题是我的游戏打算在多台主机上运行,而不是在单台主机上运行,并且寄存器的输出每次都被覆盖,而且我没有最后 (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 Code Online (Sandbox Code Playgroud)
角色 run_custom_module 如下所示:
- name: Executing the custom module
run_custom_module:
task: "Run custom py module"
var: "{{ method }}"
register: result
Run Code Online (Sandbox Code Playgroud)
库存文件如下所示:
[db_server]
1.1.1.1
2.2.2.2 …Run Code Online (Sandbox Code Playgroud) ansible ×1