Ansible: How to Check a local and remote set of files for sha1 checksum

∥☆過路亽.° 提交于 2019-12-04 18:45:34

You can do this with just two tasks: (1) register local checksums, (2) check remote checksums comparing them to corresponding local:

---
- hosts: test-server
  tasks:
    - stat:
        path: "{{ item }}"
        checksum_algorithm: sha1
      delegate_to: localhost
      with_fileglob: /tmp/*.dat
      register: local_files
    - stat:
        path: "/tmp/{{ item.stat.path | basename }}"
        checksum_algorithm: sha1
      failed_when: remote_files.stat.checksum != item.stat.checksum
      # failed_when condition checked after every iteration
      #   and remote_files here is a result of individual task
      #   but after loop is finished, remote_files is a cobination
      #   of all iterations results
      with_items: "{{ local_files.results }}"
      register: remote_files
      loop_control:
        label: "{{ item.stat.path | basename }}"
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!