In the process of learning ansible I am trying to create a playbook to run on some email hosts to gather sha1 hashes of the files. I have a plaintext file with the path and filenames the playbook needs to check.
It is formatted as follows:
files2.txt:
/opt/zimbra/zimlets-deployed/com_zextras_drive_open/assets/refresh.png
/opt/zimbra/zimlets-deployed/com_zextras_drive_open/assets/icon.png
/opt/zimbra/zimlets-deployed/com_zextras_drive_open/assets/sad-face.png
/opt/zimbra/zimlets-deployed/com_zextras_drive_open/com_zextras_drive_open.properties
/opt/zimbra/zimlets-deployed/com_zextras_drive_open/ZimbraDrive.template.js
Now I think I need to use the lookup directive with something like:
---
- hosts: localhost
gather_facts: no
vars:
contents: "{{ lookup('file', '/home/ansible/ansible/files2.txt') }}"
If I do - debug: msg="the value of zcs-files is {{ contents }}"
I see the contents. How can I filter this to only the file name and the checksum?
I also think I need to use stat to get the current file hash, and loop through the file above.
My goal with this playbook, is to gather the sha1 checksum of the files specified in the files2.txt file above, then log the matching hashes, and log the mismatch file hashes to the local control node.
Any guidance would be greatly appreciated. Here is what I have so far, but I don't know if any of this is correct.
---
- hosts: mail
become: true
vars_files:
- files.yml
tasks:
- name: Use sha1 to calculate checksum
stat:
path: "{{ item.name }}"
checksum_algorithm: sha1
get_checksum: yes
register: sha
loop: "{{ files }}"
- set_fact:
path_hash: "{{ dict(_path|zip(_hash)) }}"
vars:
_path: "{{ hash_check.results|map(attribute='stat.path')|list }}"
_hash: "{{ hash_check.results|map(attribute='stat.checksum')|list }}"
I know I am probably way off on this, but I am trying to learn.
Thank you