# Comparing checksums on a group of files

**URL:** <https://forum.ansible.com/t/comparing-checksums-on-a-group-of-files/27232>\
**Category:** Ansible Project\
**Created:** [April 10, 2018, 2:35pm UTC](https://forum.ansible.com/t/comparing-checksums-on-a-group-of-files/27232 "2018-04-10T14:35:34Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Hank\_Beatty](https://avatars.discourse-cdn.com/v4/letter/h/f6c823/32.png) [@Hank\_Beatty](https://forum.ansible.com/u/Hank_Beatty)\
**Post date:** [April 10, 2018, 2:35pm UTC](https://forum.ansible.com/t/comparing-checksums-on-a-group-of-files/27232/1 "2018-04-10T14:35:34Z")

</div>

Hello,

I would like to compare checksums on a group of files and then copy the new file over the old file if different.

Here is what I have so far:

`- name: Get Checksum for Old Comparison Zone Files`  
`stat:`  
`path: "{{ named_options.directory }}/.{{ item.file }}.old"`  
`register: named_old_zones_stat`  
`with_items: "{{ named_zones | default([]) }}"`

`- debug:`  
`var: named_old_zones_stat`

`- name: Create New Comparison Zone Files`  
`template:`  
`src: zone_hidden.j2`  
`dest: "{{ named_options.directory }}/.{{ item.file }}.new"`  
`with_items: "{{ named_zones | default([]) }}"`

`- name: Get Checksum for New Comparison Zone Files`  
`stat:`  
`path: "{{ named_options.directory }}/.{{ item.file }}.new"`  
`register: named_new_zones_stat`  
`with_items: "{{ named_zones | default([]) }}"`

`- name: Copy the New Comparison Zones Over Old if Different`  
`template:`  
`src: zone_hidden.j2`  
`dest: "{{ named_options.directory }}/.{{ item.file }}.old"`  
`with_items: "{{ named_zones | default([]) }}"`  
`when:`

The last task is where I am stumbling. I was thinking of using “with\_nested” in the last task, but I cannot seem to make it work. Does anyone have any suggestions?

Thanks,  
Hank

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/ansible/original/1X/1882d9a01da5d8996a862359b0913cc568a39b84.svg) [@system](https://forum.ansible.com/u/system)\
**Post date:** [September 13, 2018, 11:28pm UTC](https://forum.ansible.com/t/comparing-checksums-on-a-group-of-files/27232/2 "2018-09-13T23:28:58Z")

</div>

The template and copy modules do this automatically, files are only  
copied if different.
