Ansible模块在两个文件中的区别 [英] difference in two file using ansible module

查看:67
本文介绍了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:主机名:/tmp/cde.txt

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天全站免登陆