# Windows File Difference

**URL:** <https://forum.ansible.com/t/windows-file-difference/20657>\
**Category:** Ansible Project\
**Tags:** windows\
**Created:** [February 23, 2016, 11:29am UTC](https://forum.ansible.com/t/windows-file-difference/20657 "2016-02-23T11:29:48Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Mark\_Matthews](https://avatars.discourse-cdn.com/v4/letter/m/5f9b8f/32.png) [@Mark\_Matthews](https://forum.ansible.com/u/Mark_Matthews)\
**Post date:** [February 23, 2016, 11:29am UTC](https://forum.ansible.com/t/windows-file-difference/20657/1 "2016-02-23T11:29:48Z")

</div>

Hi

I am trying to find an way Ansible can not only alert me of a change in a file but exactly what was changed in that file.

I am currently using win\_stat play bookk to check the host file of a server and let me know if anything has changed. This works great, cut it only tells me if something has changed, it doesn;t tell me what has changed in the file.

---

<div class="post-metadata">

**Author:** ![j.r.hawkesworth](https://avatars.discourse-cdn.com/v4/letter/j/a3d4f5/32.png) [@j.r.hawkesworth](https://forum.ansible.com/u/j.r.hawkesworth)\
**Post date:** [February 23, 2016, 12:09pm UTC](https://forum.ansible.com/t/windows-file-difference/20657/2 "2016-02-23T12:09:19Z")

</div>

At the moment I don’t think there’s anything in the windows modules that will help with this. If anyone knows better please say but I think today --check and --diff aren’t implemented for windows modules.

However, it might be possible to make use of the --check and --diff playbook command line arguments if you first fetch the files that you care about back to the controller and then use copy tasks (which won’t actually copy in --check mode).

There’s a thread here describing this

[https://groups.google.com/forum/#!topic/ansible-project/6xkSE1nxIOU](https://groups.google.com/forum/#!topic/ansible-project/6xkSE1nxIOU)

That said, as you’ve pointed out comparing files in powershell is pretty straightforward so there’s no reason why win\_copy couldn’t be changed to implement --check and --diff modes.

Hope this helps,

Jon

---

<div class="post-metadata">

**Author:** ![Mark\_Matthews](https://avatars.discourse-cdn.com/v4/letter/m/5f9b8f/32.png) [@Mark\_Matthews](https://forum.ansible.com/u/Mark_Matthews)\
**Post date:** [February 24, 2016, 3:32pm UTC](https://forum.ansible.com/t/windows-file-difference/20657/3 "2016-02-24T15:32:46Z")

</div>

Hi Jon

I tried creating the following playbook below, and running the following command: ansible-playbook test\_win.yml --check --diff  
But I just got errors Not sure if this is what you were trying to explain what I should do?

---

<div class="post-metadata">

**Author:** ![j.r.hawkesworth](https://avatars.discourse-cdn.com/v4/letter/j/a3d4f5/32.png) [@j.r.hawkesworth](https://forum.ansible.com/u/j.r.hawkesworth)\
**Post date:** [February 25, 2016, 9:50am UTC](https://forum.ansible.com/t/windows-file-difference/20657/4 "2016-02-25T09:50:13Z")

</div>

Hi

Sorry, probably didn’t explain myself very well and what I was proposing was probably pretty fragile.

You’d have to set up a directory of reference files that you want to compare to, and another of candidate files.  
Then you’d need a playbook to use fetch to pull the candidate files back from the windows hosts, and then use the copy module (running with --check --diff) to ‘‘copy’’ between the candidate and reference files. It wouldn’t actually copy but would show the difference between the reference and candidate files I think.

You can see the output from command if you run ansible with -v switch or if you store results from commands using register, and then use the debug module to display the contents of the registered variable.

Hope this helps,

Jon
