# Parsing and Comparing a text file

**URL:** <https://forum.ansible.com/t/parsing-and-comparing-a-text-file/23680>\
**Category:** Ansible Project\
**Created:** [February 8, 2017, 6:01am UTC](https://forum.ansible.com/t/parsing-and-comparing-a-text-file/23680 "2017-02-08T06:01:03Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Mona\_Gopal](https://avatars.discourse-cdn.com/v4/letter/m/b4bc9f/32.png) [@Mona\_Gopal](https://forum.ansible.com/u/Mona_Gopal)\
**Post date:** [February 8, 2017, 6:01am UTC](https://forum.ansible.com/t/parsing-and-comparing-a-text-file/23680/1 "2017-02-08T06:01:03Z")

</div>

Hello,

My requirement is as below:

A text file with configuration contents would be given to us by the product teams.  
I will have to compare this file against the one on the remote host , find out the difference, and replace values for the variables where it doesn’t match.  
How is this achievable using Ansible.  
Kindly suggest a solution.

Thanks in advance,  
Mona G

---

<div class="post-metadata">

**Author:** ![Johannes\_Kastl](https://avatars.discourse-cdn.com/v4/letter/j/bbe5ce/32.png) [@Johannes\_Kastl](https://forum.ansible.com/u/Johannes_Kastl)\
**Post date:** [February 8, 2017, 8:44am UTC](https://forum.ansible.com/t/parsing-and-comparing-a-text-file/23680/2 "2017-02-08T08:44:10Z")

</div>

I assume you want to manually control, what the differences are.  
Automating this is difficult.

I would use a template task, put the file you just got into your  
ansible folder as the template src file and then run the  
ansible-playbook command with --check --diff:

# File foobar.yml  
- hosts: foobar  
&nbsp;&nbsp;tasks:  
&nbsp;&nbsp;- template:  
&nbsp;&nbsp;&nbsp;&nbsp;src: "file\_you\_just\_got"  
&nbsp;&nbsp;&nbsp;&nbsp;dest: "/path/to/file/on/remote/server"  
&nbsp;&nbsp;check\_mode: yes

Then run the playbook foobar.yml like this:

ansible-playbook foobar.yml --check --diff

Johannes

---

<div class="post-metadata">

**Author:** ![Brian\_Coca](https://avatars.discourse-cdn.com/v4/letter/b/6de8d8/32.png) [@Brian\_Coca](https://forum.ansible.com/u/Brian_Coca)\
**Post date:** [February 8, 2017, 6:30pm UTC](https://forum.ansible.com/t/parsing-and-comparing-a-text-file/23680/3 "2017-02-08T18:30:33Z")

</div>

The copy module does this by default, run with --diff --check to see  
what 'it would do'
