# Monitor Windows file (web.config) on servers

**URL:** <https://forum.ansible.com/t/monitor-windows-file-web-config-on-servers/20589>\
**Category:** Ansible Project\
**Tags:** windows\
**Created:** [February 16, 2016, 10:25am UTC](https://forum.ansible.com/t/monitor-windows-file-web-config-on-servers/20589 "2016-02-16T10:25:31Z")\
**Posts on this page:** 7\
**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 16, 2016, 10:25am UTC](https://forum.ansible.com/t/monitor-windows-file-web-config-on-servers/20589/1 "2016-02-16T10:25:31Z")

</div>

Hi

What is the best way to monitor any changes made to a Windows file (Either the web.config or hosts file)?

I want to be able to check that these files have not been changed at all, and if they have, Ansible picks that up and warns me and I can change it back to a template.

I am currently using the following playbook for the host file, but was wondering if there is sa easier way? As I want to do our web.config 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 16, 2016, 12:53pm UTC](https://forum.ansible.com/t/monitor-windows-file-web-config-on-servers/20589/2 "2016-02-16T12:53:20Z")

</div>

Above looks good. You could try using win\_stat, which returns a checksum and then do whatever is necessary if the checksum has changed.

Something like the following

---

<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 16, 2016, 1:48pm UTC](https://forum.ansible.com/t/monitor-windows-file-web-config-on-servers/20589/3 "2016-02-16T13:48:28Z")

</div>

Hi Jon

That is exactly what I was looking for!!

Thank you so much for your quick response and help!

Cheers  
Mark

---

<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 16, 2016, 2:01pm UTC](https://forum.ansible.com/t/monitor-windows-file-web-config-on-servers/20589/4 "2016-02-16T14:01:20Z")

</div>

Hi Jon

Just want to ask a quick question…

Tried to do the following with the web.config file but keep getting errors.

ok: [10.10.3.170] =\> {  
“Web.config\_fileinfo”: “VARIABLE IS NOT DEFINED!”

I the tried to run the following paybooks to get some variables for that 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 16, 2016, 2:21pm UTC](https://forum.ansible.com/t/monitor-windows-file-web-config-on-servers/20589/5 "2016-02-16T14:21:48Z")

</div>

So, not quite sure what’s going on here but…

register just stores the output from the win\_stat command in a variable with the name you’ve given it.

So you need to do something with the contents of the variable - hence the debug in the example playbook above

Also I think variable names can’t have . in them so this isn’t going to work:

register: Web.config\_fileinfo

See [http://docs.ansible.com/ansible/playbooks\_variables.html#what-makes-a-valid-variable-name](http://docs.ansible.com/ansible/playbooks_variables.html#what-makes-a-valid-variable-name) for valid variable names

That will be why you are getting the  
“Web.config\_fileinfo”: “VARIABLE IS NOT DEFINED!”

Its looking for a variable called Web with a method called config\_fileinfo on it, hence the failure.

Hopefully just picking a valid name for your variable and then examining the contents of the variable using debug will sort you out.

If you want some examples you can have a look in the ansible integration tests  
[https://github.com/ansible/ansible/blob/devel/test/integration/roles/test\_win\_stat/tasks/main.yml](https://github.com/ansible/ansible/blob/devel/test/integration/roles/test_win_stat/tasks/main.yml)

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 16, 2016, 2:54pm UTC](https://forum.ansible.com/t/monitor-windows-file-web-config-on-servers/20589/6 "2016-02-16T14:54:06Z")

</div>

Hi Jon

Thanks for the quick response…

Using the information you provided I did the following playbook below…and it worked perfectly.

So for some reason when I tried to use the following variable names it kept failing…‘web\_stat\_file’, '‘file\_info’, ‘web\_fileinfo’  
Will have to read through and see why the only variable that works is ‘host\_fileinfo’

---

<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 16, 2016, 4:04pm UTC](https://forum.ansible.com/t/monitor-windows-file-web-config-on-servers/20589/7 "2016-02-16T16:04:41Z")

</div>

Glad its working. I don’t know why those other variable names might be failing.

Perhaps worth checking your playbook is valid yaml. I like to use either notepad++ as it has YAML syntax hightlighting, or use [www.yamlint.com](http://www.yamlint.com) to check for correctness.

Jon
