Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to check whether the result of an Ansible task is the same on all the servers?

Tags:

ansible

As part of an Ansible playbook, I want to verify whether my servers are in sync.

To do so, I execute a script on each of my servers using the shell module and I register the result into a variable, say result_value.

The tricky part is to verify whether result_value is the same on all the servers. The expected value is not known beforehand.

Is there an idiomatic way to achieve this in Ansible?

like image 319
Roberto Aloi Avatar asked Oct 22 '25 03:10

Roberto Aloi


1 Answers

One of possible ways:

---
- 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
like image 73
Konstantin Suvorov Avatar answered Oct 23 '25 20:10

Konstantin Suvorov