Hi,
I need to do the following thing.
On the first host, calculate the checksum of a certain file (es. /etc/hosts) and save it into a variable, let's say "file_checksum".
On the second host, I would like to calculate newly the checksum and compare it with the one from the first host (i.e. the value saved in "file_checksum"). And so on with the other hosts of my inventory.
I tried several ways without success. Also run_once on set_fact doesn't seem to work (see below the snippet not fully working).
Any Idea how to save a value between hosts in a playbook?
Thanks in advance.
Cheers.
Gaetano
---
- name: check_configuration
hosts: all
serial: 1
gather_facts: yes
tasks:
- name: Execution of the stat on the file
stat: path=/etc/hosts
register: stat_results
- name: Check of file existence
fail:
msg: "The file doesn't exist!"
when: stat_results.stat.exists|bool == false
- debug: var=file_checksum
when: file_checksum is defined
- name: Set fact
set_fact:
file_checksum: "{{ stat_results.stat.checksum }}"
run_once: true
- name: Compare of the file file_checksum
debug: var="Checksum of the file is {{ file_checksum }} but right is {{ stat_results.stat.checksum }}"
when: file_checksum != "" and (file_checksum != stat_results.stat.checksum)
- name: Compare of the file_checksum with the first value
fail:
msg: var="Checksum of the file is {{ file_checksum }} but right is {{ stat_results.stat.checksum }}"
when: file_checksum != "" and file_checksum != stat_results.stat.checksum