to check file has the same value or not i e comparing file with stat module

0 votes

I can see a file i.e., test.txt on remote1 and remote2 which has version with date and these file contains aren't fixed.

$ cat test.txt
Release_P1.11_2017-08-02-094316
02/08/2017

I wanted to set the condition to check if file contains are same then continue to perform further tasks and if they are not the same then stop the tasks

 ---
   - name: latest file check
     stat:
        path: /tmp/test.txt
        get_checksum: yes
     register: test_file_check

   - debug:
        var: test_file_check.stat.checksum
Checksum value are equal if file contains will be same, otherwise it's not the same.
I am unable to figure it out. Can anyone help me with this?
Thanks
May 1, 2018 in DevOps & Agile by Atul
• 10,240 points
4,171 views

1 answer to this question.

0 votes

Try the following script:

Do the second time check and when condition be like:

- hosts: remote_1
  tasks:
    - name: first file check
      stat:
        path: /tmp/test.txt
        get_checksum: yes
      register: test_file_check_1

...........................................
- hosts: remote_2
  tasks: 
    - name: next check
      stat:
        path: /tmp/test.txt
        get_checksum: yes
      register: test_file_check_2
...........................................

- name: Block run only if file has no changes
  command: /bin/true
  when: test_file_check_1.stat.checksum == test_file_check_2.stat.checksum

Click on the below link to get the clear ideas.

http://docs.ansible.com/ansible/latest/playbooks_conditionals.html

answered May 1, 2018 by shubham
• 7,340 points

Related Questions In DevOps & Agile

0 votes
1 answer
+1 vote
2 answers

Should I commit Terraform State files to the git repository?

Its better not to commit it to ...READ MORE

answered Aug 3, 2018 in DevOps & Agile by Nilesh
• 7,060 points
3,547 views
+15 votes
2 answers

Git management technique when there are multiple customers and need multiple customization?

Consider this - In 'extended' Git-Flow, (Git-Multi-Flow, ...READ MORE

answered Mar 27, 2018 in DevOps & Agile by DragonLord999
• 8,450 points
4,036 views
+2 votes
1 answer
+1 vote
2 answers

How do I run Apache server from Docker without mapping to a location?

If you're seeing a 500 error, that's ...READ MORE

answered Oct 18, 2018 in DevOps & Agile by lina
• 8,220 points
2,193 views
+1 vote
1 answer

How do I get a Docker container's IP address from the host?

Save your docker image as a tar ...READ MORE

answered Aug 29, 2018 in DevOps & Agile by shubham
• 7,340 points
998 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP