如何检查一个 Ansible 任务的结果在所有服务器上是否相同?
How to check whether the result of an Ansible task is the same on all the servers?
作为 Ansible 剧本的一部分,我想验证我的服务器是否同步。
为此,我使用 shell
模块在我的每台服务器上执行一个脚本,并将结果注册到一个变量中,比如 result_value
。
棘手的部分是验证 result_value
在所有服务器上是否相同。预期值事先未知。
在 Ansible 中是否有惯用的方法来实现这一点?
可能的方法之一:
---
- hosts: all
tasks:
- shell: /usr/bin/my_check.sh
register: result_value
- assert:
that: hostvars[item]['result_value'].stdout == result_value.stdout
with_items: "{{play_hosts}}"
run_once: true
作为 Ansible 剧本的一部分,我想验证我的服务器是否同步。
为此,我使用 shell
模块在我的每台服务器上执行一个脚本,并将结果注册到一个变量中,比如 result_value
。
棘手的部分是验证 result_value
在所有服务器上是否相同。预期值事先未知。
在 Ansible 中是否有惯用的方法来实现这一点?
可能的方法之一:
---
- hosts: all
tasks:
- shell: /usr/bin/my_check.sh
register: result_value
- assert:
that: hostvars[item]['result_value'].stdout == result_value.stdout
with_items: "{{play_hosts}}"
run_once: true