使用ansible模块的两个文件的区别 [英] difference in two file using ansible module

查看:25
本文介绍了使用ansible模块的两个文件的区别的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想看看本地和远程主机上的文件是否有任何更改.如果有任何差异,它应该在屏幕上可见使用 Ansible 执行此操作的最佳方法是什么

I want to see if there is any changes in the file one present in local and other on the remote host. If there is any difference, it should be visible in screen what should be the best way to do this using Ansible

例如:

src : /tmp/abc.txt
dest : hostname:/tmp/cde.txt

推荐答案

您还可以使用 check_mode: yesdiff: yes 任务选项来显示差异:

You can also use check_mode: yes and diff: yes tasks options to show differences:

---
- hosts: localhost
  gather_facts: no

  tasks:
    - name: "Only show diff between test1.txt & test2.txt" 
      copy:
        src: /tmp/test2.txt
        dest: /tmp/test1.txt
      check_mode: yes
      diff: yes

示例:

# cat /tmp/test1.txt
test1

# cat /tmp/test2.txt
test1
test2

# ansible-playbook diff.yaml
PLAY [localhost] ***********************************************************************************************************************************

TASK [Only show diff between test1.txt & test2.txt] ************************************************************************************************
--- before: /tmp/test1.txt
+++ after: /tmp/test2.txt
@@ -1 +1,2 @@
 test1
+test2

changed: [localhost]

PLAY RECAP *****************************************************************************************************************************************
localhost                  : ok=1    changed=1    unreachable=0    failed=0

有关 check_mode 的更多信息 &diff 此处.

More information on check_mode & diff here.

这篇关于使用ansible模块的两个文件的区别的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆