我正在努力找出如何比较两个文件。尝试了几种方法,包括此方法,该方法的错误之处在于:
失败!=> {“ msg”:“在已配置的模块路径中找不到模块差异。此外,核心模块丢失。如果这是签出,请运行'git pull --rebase'来纠正此问题。”}
这是比较两个文件并确保内容相同的最佳实践,还是有更好的方法?
提前致谢。
我的剧本:
- name: Find out if cluster management protocol is in use
ios_command:
commands:
- show running-config | include ^line vty|transport input
register: showcmpstatus
- local_action: copy content="{{ showcmpstatus.stdout_lines[0] }}" dest=/poc/files/{{ inventory_hostname }}.result
- local_action: diff /poc/files/{{ inventory_hostname }}.result /poc/files/transport.results
failed_when: "diff.rc > 1"
register: diff
- name: debug output
debug: msg="{{ diff.stdout }}"
Run Code Online (Sandbox Code Playgroud)
为什么不使用stat
比较这两个文件?只是一个简单的例子:
- name: Get cksum of my First file
stat:
path : "/poc/files/{{ inventory_hostname }}.result"
register: myfirstfile
- name: Current SHA1
set_fact:
mf1sha1: "{{ myfirstfile.stat.checksum }}"
- name: Get cksum of my Second File (If needed you can jump this)
stat:
path : "/poc/files/transport.results"
register: mysecondfile
- name: Current SHA1
set_fact:
mf2sha1: "{{ mysecondfile.stat.checksum }}"
- name: Compilation Changed
debug:
msg: "File Compare"
failed_when: mf2sha1 != mf1sha1
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
8346 次 |
最近记录: |