I have stored checksum of local and remote files in two different variables. Now I want to compare those checksum and fail if they don't match. Below is code.
- name: Get cksum some of files copied locally
stat:
path : "{{ item.src }}/{{ item.file }}"
checksum_algorithm: sha1
delegate_to: localhost
with_items: "{{ files }}"
register: local_files
- name: Get cksum of remote files
stat:
path : "{{ item.dest }}/{{ item.file }}_{{ item.package }}_NEW"
checksum_algorithm: sha1
with_items: "{{ files }}"
register: remote_files
- name : Compare local and remote cksums. Fail if not matched
debug:
msg="Checksum don't match"
failed_when: item[0].results.stat.checksum != item[1].results.stat.checksum
with_items:
- "{{ local_files.results }}"
- "{{ remote_files.results }}"
When I run this, I get below error.
FAILED! => {"failed": true, "msg": "The conditional check 'item[0].results.stat.checksum != item[1].results.stat.checksum' failed. The error was: error while evaluating conditional (item[0].results.stat.checksum != item[1].results.stat.checksum): dict object has no element 0"}
How can I correct it to compare checksum?
debugmodule ー start with checking whatitem[0]anditem[1]contain to see how far you are from what you imagined.