Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

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

For example:

src : /tmp/abc.txt
dest : hostname:/tmp/cde.txt
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
730 views
Welcome To Ask or Share your Answers For Others

1 Answer

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

Example:

# 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

More information on check_mode & diff here.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...