I resolved it

 tasks:
  - name: copy hosts for validation file
    copy:
      src: ./templates/hosts
      dest: /tmp/hosts
      owner: root
      group: root
      mode: '0644'
      backup: yes

  - name: compare md5 local copy host file
    stat:
      path: /tmp/hosts
      checksum_algorithm: md5
      get_checksum: yes
    register: originalfile

  - name: compare md5 remote hosts file
    stat:
      path: /etc/hosts
      checksum_algorithm: md5
      get_checksum: yes
    register: remotefile

  - name: Verify host files md5 value
    debug:
      msg:
"File Compare hash value of {{ remotefile.stat.checksum }} is same as
{{ originalfile.stat.checksum }}."
    failed_when: remotefile.stat.checksum != originalfile.stat.checksum
Thank you.
Regards,
Siva


On Thu, 21 May 2020 at 18:32, Stefan Hornburg (Racke) <ra...@linuxia.de>
wrote:

> On 5/21/20 9:01 AM, Sivakumar Saravanamuthu wrote:
> > hi
> >
> > I have requirement to compare local file with remote file. Example I
> have a copy of standard /etc/hosts  file and I need
> > to compare that file with remote host /etc/hosts file to check the
> difference. If there is difference it should register
> > it and proceed with next task. I tried various option like diff and stat
> but unable to get expected result.
> >
> > Is there any way I can execute that.
>
> With the stat module you should be able to establish whether the files
> have different checksums. What did you try
> exactly?
>
> Regards
>         Racke
>
> >
> > Regards,
> > Siva
> >
> > --
> > 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
> > ansible-project+unsubscr...@googlegroups.com <mailto:
> ansible-project+unsubscr...@googlegroups.com>.
> > To view this discussion on the web visit
> >
> https://groups.google.com/d/msgid/ansible-project/469d7a64-a6be-427f-9de9-539ce5ee09f1%40googlegroups.com
> > <
> https://groups.google.com/d/msgid/ansible-project/469d7a64-a6be-427f-9de9-539ce5ee09f1%40googlegroups.com?utm_medium=email&utm_source=footer
> >.
>
>
> --
> Ecommerce and Linux consulting + Perl and web application programming.
> Debian and Sympa administration. Provisioning with Ansible.
>
> --
> 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 ansible-project+unsubscr...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/ansible-project/dc439995-263e-3795-6cf9-1682dfc85be6%40linuxia.de
> .
>

-- 
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 ansible-project+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/CANnu9FH2ut01EYdhPmhXRLzh-kk%3D8QpiKkRTc168mSH3McKwdA%40mail.gmail.com.

Reply via email to