Reputation: 35
I have two files called source.txt and destination.txt as below, Source.txt
[profile appdev]
Arn: aaa.dev:333:iam
Region: ap.southeast2
[profile applead]
Arn: aaa.techlead:333:iam
Region: ap.southeast2
[profile appprod]
Arn: aaa.techlead:333:iam
Region: ap.southeast2
[profile apppadmin]
Arn: aaa.techlead:333:iam
Region: ap.southeast2
[profile appsupport]
Arn: aaa.dev:333:iam
Region: ap.southeast2
destination.txt
[profile appdev]
Arn: aaa.dev:333:iam
Region: ap.southeast2
[profile applead]
Arn: aaa.techlead:333:iam
Region: ap.southeast2
[profile appprod]
Arn: aaa.techlead:333:iam
Region: ap.southeast2
[profile apppadmin]
Arn: aaa.techlead:333:iam
Region: ap.southeast2
When we compare source.txt and destination.txt, the below content is missing,
[profile appsupport]
Arn: aaa.dev:333:iam
Region: ap.southeast2
I want to append the missing content to destination.txt else we can skip it if no difference. I have used diif command in shell module, but i am not getting proper difference
Any idea how to do it in Ansible
Upvotes: 0
Views: 1740
Reputation: 972
basically you always want to have the same content on the 2 files if there is a difference, usually, I do that using the copy module:
---
- hosts: localhost
tasks:
- name: Copy content of file src to destination
copy:
src: /home/myfolder/txt2.txt
dest: /home/myfolder/txt1.txt
check_mode: yes
diff: yes
(You can delete check_mode see the link to know why: https://docs.ansible.com/ansible/latest/user_guide/playbooks_checkmode.html Basically check mode is a simulation and wont change any file)
Upvotes: 1