Comparing checksums on a group of files

10 views
Skip to first unread message

Hank Beatty

unread,
Apr 10, 2018, 10:35:50 AM4/10/18
to Ansible Project

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

Brian Coca

unread,
Sep 13, 2018, 7:29:30 PM9/13/18
to Ansible Project
The template and copy modules do this automatically, files are only
copied if different.

--
----------
Brian Coca
Reply all
Reply to author
Forward
0 new messages