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'


---
- name: Check Host 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 if modified
       fail:
         msg: "WEB.CONFIG file has been modified"
       when: hosts_fileinfo.stat.checksum != 
"xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"


Thanks again for all your help.

Cheers
Mark


On Tuesday, February 16, 2016 at 10:25:31 AM UTC, Mark Matthews wrote:
>
> 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?
>
>
> --- 
> - name: Check Host File Entries 
>   hosts: all   
>   tasks: 
>     - name: Check Host File Entries 
>       win_lineinfile: 
>         dest: C:\Windows\System32\drivers\etc\hosts 
>         regexp: "{{item.regexp}}" 
>         line: "{{item.line}}"
>
>       with_items:
>         - { regexp: '^10.10.3.76   www.test.co.uk', line: '10.10.3.76   
> www.test.co.uk' }
>         - { regexp: '^10.10.3.77   www.test1.co.uk', line: '10.10.3.77   
> www.test1.co.uk' }
>         - { regexp: '^10.10.3.77   ca.test1.com', line: '10.10.3.77   
> ca.test1.com' }
>         - { regexp: '^10.10.3.74   www.test3.com', line: '10.10.3.74   
> www.test3.com' }
>         - { regexp: '^10.10.3.19   test4.com', line: '10.10.3.19   
> test4.com' }
>
>
> Cheers
> Mark
>

-- 
You received this message because you are subscribed to the Google Groups 
"Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/067fc924-0992-46ea-b81b-19d6342a604e%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to