I want to be able to do a checksum based on a list of files in a local dir. Then be able to get those files checksum and compare it to the checksum of the same files on a remote system.
I know I can get the with the following
# Local File
- stat:
path: "{{ playbook_dir }}/roles/common/files/myfile.dat"
checksum_algorithm: sha1
delegate_to: localhost
run_once: true
register: localsha_result
# Remote file
- stat:
path: "{{ rmt_dest_dir }}/myfile.dat"
checksum_algorithm: sha1
register: sha_result
and I have tried to loop through the files that I want to checksum with:
# Gather Files
- name: gather names of files
local_action: shell ls {{ playbook_dir }}/roles/common/files/*.dat | awk -F '/' '{ print $NF }'
register: datfiles
# Local File
- stat:
path: "{{ playbook_dir }}/roles/common/files/{{ item }}"
checksum_algorithm: sha1
with_items: "{{ datfiles.stdout_lines }}"
delegate_to: localhost
run_once: true
register: localsha_result
# Remote file
- stat:
path: "{{ rmt_dest_dir }}/{{ item }}"
checksum_algorithm: sha1
with_items: "{{ datfiles.stdout_lines }}"
register: sha_result
- name: check sha1
fail: msg="SHA1 checksum fails"
when: not sha_result.stat.checksum is defined or not sha_result.stat.checksum == "{{ item.stat.checksum }}"
with_items: "{{ datfiles.stdout_lines}}"
failed_when
is very helpful. Thank you So much!! – Rifkin