I am trying to find a way to compare multiple files in a directory to files in another directory. For example - there are 10 files in a directory /home/ansible/properties/ and similar set of files in another directory on remote host like /opt/apps/properties/. I want to compare each of them probably using checksum and even if one of the file is changed then do some task -
Below of my play can compare one file but is there a way to compare all the files or for that matter a directory?
- name: Get checksum of my First file
stat:
path : "/home/ansible/properties/my.properties"
register: myfirstfile
- name: Current SHA1
set_fact:
1stFilechecksum: "{{ myfirstfile.stat.checksum }}"
- name: Get checksum of my Second File
stat:
path : "/opt/aaps/properties/my.properties"
register: mysecondfile
- name: Current SHA1
set_fact:
2ndFilechecksum: "{{ mysecondfile.stat.checksum }}"
- name: Comparing 2 files
debug:
msg: "Do Something....."
when: 1stFilechecksum != 2ndFilechecksum