Validation on Config files in Windows

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?

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