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
301 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
• 6,870 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
• 6,900 points
394 views
0 votes
1 answer

Why am I not able to re-deploy after moving 3 apps into one folder ?

The error that you are getting i.e., app ...READ MORE

answered Aug 9, 2018 in DevOps & Agile by Damon Salvatore
• 5,490 points
26 views
+13 votes
2 answers
0 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,100 points
60 views
0 votes
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
• 6,870 points
36 views