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.
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
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
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?
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