您如何比较两个可取列表中的值?
我在Ansible中有两个列表,可以使用查找
模块
- name: "Find all files in {{ backup_path }}"
ansible.builtin.find:
paths:
- "{{ backup_path }}"
get_checksum: true
recurse: yes
depth: 2
patterns: "{{ file_patterns }}"
register: backup_files
- name: "Find all files in {{ new_path }}"
ansible.builtin.find:
paths:
- "{{ new_path }}"
get_checksum: true
recurse: yes
depth: 2
patterns: "{{ file_patterns }}"
register: new_files
,一旦我注册这些变量,我想在old_files
和new_files 列表。
- name: diff files between new and old
ansible.builtin.shell:
cmd: "diff {{ item.0 }} {{ item.1 }}"
register: diff_files
loop:
- "{{ backup_files }}"
- "{{ new_files }}"
我知道上面的片段是错误的,但是我想将0个项目从new_files与old_files n次数的0次数进行比较。
本剧本的目的是比较两个目录中的所有文件,并替换那些不同的文件。
I've got two lists in Ansible that I build on the fly using the find
module
- name: "Find all files in {{ backup_path }}"
ansible.builtin.find:
paths:
- "{{ backup_path }}"
get_checksum: true
recurse: yes
depth: 2
patterns: "{{ file_patterns }}"
register: backup_files
- name: "Find all files in {{ new_path }}"
ansible.builtin.find:
paths:
- "{{ new_path }}"
get_checksum: true
recurse: yes
depth: 2
patterns: "{{ file_patterns }}"
register: new_files
Once I register those variables, I want to run a diff between the old_files
and new_files
lists.
- name: diff files between new and old
ansible.builtin.shell:
cmd: "diff {{ item.0 }} {{ item.1 }}"
register: diff_files
loop:
- "{{ backup_files }}"
- "{{ new_files }}"
I know the above snippet is wrong, but I want to compare the 0th item from new_files to 0th item from old_files n number of times.
The purpose of this playbook is to compare all the files in two directories and replace those that are different.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
事实证明,我使这比需要的要复杂得多,这是更简单的工作。基本上,使用
diff -rq \ path1 \ path2
。Turns out I was making this far more complicated than it needed to be, here is what worked that was much simpler. Basically, use
diff -rq \path1 \path2
.