# Validation on Config files in Windows

**URL:** <https://forum.ansible.com/t/validation-on-config-files-in-windows/21546>\
**Category:** Ansible Project\
**Tags:** windows\
**Created:** [May 24, 2016, 3:47pm UTC](https://forum.ansible.com/t/validation-on-config-files-in-windows/21546 "2016-05-24T15:47:44Z")\
**Posts on this page:** 2\
**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:** [May 24, 2016, 3:47pm UTC](https://forum.ansible.com/t/validation-on-config-files-in-windows/21546/1 "2016-05-24T15:47:44Z")

</div>

Hi

I have a situation where I have several web servers that are load balanced and are updated daily through Octopus.

Although we still have issues when uses will go onto the Windows machines and manually edit config files (Eg: web.config file).

Is there anything that Ansible can do to check that all web.config files are identical, and if a change is made to one of them it fails?  
I would like to run a scheduled playbook that checks that all the we.config files are identical and if one has been changed it fails…and if possible can show where the file has been changed?

I have been playing around with the following below, and although it works to a certain point, its just not what im looking for.  
So really just trying to find out if there is something that I dont know about? Or some options I can look at?

Tried the below playbook, and it works great. But if the web.config is changed everyday through Octopus, then the md5 changes. Which means I would need to edit this everytime there is an update?

- name: Check Web.config file  
hosts: all  
tasks:

- name: Stat the web.config file  
win\_stat:  
path: C:\Websites\Live\Web.config  
register: hosts\_fileinfo

- name: show web.config file stats for debugging purposes  
debug:  
var: hosts\_fileinfo

- name: fail file not there  
fail:  
msg: “WEB.CONFIG file is missing”  
when: hosts\_fileinfo.stat.exists != true

- name: fail if modified  
fail:  
msg: “WEB.CONFIG file has been modified”  
when: hosts\_fileinfo.stat.checksum != “7ebf68e867b5b51570758ba81fd23258f1da9029”

Tried the below to search for a line in the file on all the servers, and it works. But if a file is missing this line, it just puts it at the bottom of the file. Which doesn’t help…I would need it to look like all the other web.config’s?

---

<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:** [May 24, 2016, 4:10pm UTC](https://forum.ansible.com/t/validation-on-config-files-in-windows/21546/2 "2016-05-24T16:10:29Z")

</div>

Hi,

Not tried this myself but you could perhaps use fetch to pull the files back to the ansible controller and then run a task to compare that all of the fetched files match whatever your critieria are.

You might be able to use --diff if you compare the files as a local action on your ansible controller.

Obviously its not ideal but until the windows modules can do --diff and --check that might do what you need.

Hope this helps,

Jon
