在 remote1 和 remote2 上有一个文件:test.txt,它的版本带有日期,这些文件包含的不是固定的。
$ cat test.txt
Release_P1.11_2017-08-02-094316
02/08/2017
我需要检查:
- 如果文件包含相同,则继续执行进一步的任务。
- 如果文件包含不同,则停止任务。
---
- name: latest file check
stat:
path: /tmp/test.txt
get_checksum: yes
register: test_file_check
- debug:
var: test_file_check.stat.checksum
现在,如果文件包含相同,则校验和值相等,否则它没有相同。 但我没有弄清楚解决方案。
您所需要的只是第二次检查和何时条件
- hosts: remote_1
tasks:
- name: first file check
stat:
path: /tmp/test.txt
get_checksum: yes
register: test_file_check_1
...........................................
- hosts: remote_2
tasks:
- name: next check
stat:
path: /tmp/test.txt
get_checksum: yes
register: test_file_check_2
...........................................
- name: Block run only if file has no changes
command: /bin/true
when: test_file_check_1.stat.checksum == test_file_check_2.stat.checksum
http://docs.ansible.com/ansible/latest/playbooks_conditionals.html