Reputation: 179
I need to find a way where I can compare elasticsearch template folders in given elasticsearch Data host group. Meaning if the directory is /usr/local/elasticsearch/config/templates/
, I need to make sure all the files inside that directory in that ansible host group is same.
No extra template files or difference version template files. I haven't been able to figure out how to do this.
Upvotes: 3
Views: 5349
Reputation: 810
Try combining ansible with rsync dry-run using the shell module:
ansible -i production data_hosts -l '!~host1' -f 1 -m shell \
-a 'rsync --checksum --delete --dry-run -r -v host1.example.com:/usr/local/elasticsearch/config/templates/ /usr/local/elasticsearch/config/templates'
Explanation
-l
limit argument: -l '!~host1'
-f 1
to only run one compare at a time. Optional, but helped in my case because the directories contained large numbers of files (>10K)--dry-run
to prevent rsync from actually sync'ing the directories--delete
to list extraneous files in the destination directory--checksum
to compare files based on checksum rather than mod-time and sizeNotes
--dry-run
. Consider adding -z
to compress file data during transfer, and -a
for archive mode.The production inventory file would look like this:
[data_hosts]
host1.example.com
host2.example.com
host3.example.com
host4.example.com
Upvotes: 1
Reputation: 179
I did it by first comparing the number of files in all hosts in that given group under the template folder, then getting the list of files and their respective md5sum values and exporting them to current playbook using include_vars. Then I compared each files md5sum against the one exported with include_vars and with_items.
Upvotes: 0