-1
로컬 디렉터리의 파일 목록을 기반으로 체크섬을 수행하려고합니다. 그런 다음 해당 파일의 체크섬을 가져 와서 원격 시스템의 동일한 파일의 체크섬과 비교할 수 있습니다. 당신은 두하여이 작업을 수행 할 수Ansable : sha1 체크섬에 대한 로컬 및 원격 파일 집합을 확인하는 방법
# Gather Files
- name: gather names of files
local_action: shell ls {{ playbook_dir }}/roles/common/files/*.dat | awk -F '/' '{ print $NF }'
register: datfiles
# Local File
- stat:
path: "{{ playbook_dir }}/roles/common/files/{{ item }}"
checksum_algorithm: sha1
with_items: "{{ datfiles.stdout_lines }}"
delegate_to: localhost
run_once: true
register: localsha_result
# Remote file
- stat:
path: "{{ rmt_dest_dir }}/{{ item }}"
checksum_algorithm: sha1
with_items: "{{ datfiles.stdout_lines }}"
register: sha_result
- name: check sha1
fail: msg="SHA1 checksum fails"
when: not sha_result.stat.checksum is defined or not sha_result.stat.checksum == "{{ item.stat.checksum }}"
with_items: "{{ datfiles.stdout_lines}}"
매력! 'failed_when'은 매우 도움이됩니다. 정말 고마워요 !! – Cale