# Set up a check for the patching logs in the nodes

**URL:** <https://forum.ansible.com/t/set-up-a-check-for-the-patching-logs-in-the-nodes/26804>\
**Category:** Ansible Project\
**Created:** [February 20, 2018, 5:38pm UTC](https://forum.ansible.com/t/set-up-a-check-for-the-patching-logs-in-the-nodes/26804 "2018-02-20T17:38:06Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Shreela\_Roy](https://avatars.discourse-cdn.com/v4/letter/s/46a35a/32.png) [@Shreela\_Roy](https://forum.ansible.com/u/Shreela_Roy)\
**Post date:** [February 20, 2018, 5:38pm UTC](https://forum.ansible.com/t/set-up-a-check-for-the-patching-logs-in-the-nodes/26804/1 "2018-02-20T17:38:06Z")

</div>

I am running an ansible playbook for patching the nodes from the control server. I want to set up a check which would check for the word COMPLETED in the file:

something like:  
/var/log/12-2017PM-PATCH.log| grep -o COMPLETED

But cannot find the way out for checking each of the nodes and then if successfully finds the word COMPLETED would reboot the servers one by one. and leaves the server where its not completed.

---

<div class="post-metadata">

**Author:** ![Kai\_Stian\_Olstad](https://avatars.discourse-cdn.com/v4/letter/k/e19adc/32.png) [@Kai\_Stian\_Olstad](https://forum.ansible.com/u/Kai_Stian_Olstad)\
**Post date:** [February 20, 2018, 5:54pm UTC](https://forum.ansible.com/t/set-up-a-check-for-the-patching-logs-in-the-nodes/26804/2 "2018-02-20T17:54:20Z")

</div>

You can use file module, it has the option contain that will search for a string in the file.  
Register the output from find and then check that matched == 1

---

<div class="post-metadata">

**Author:** ![Shreela\_Roy](https://avatars.discourse-cdn.com/v4/letter/s/46a35a/32.png) [@Shreela\_Roy](https://forum.ansible.com/u/Shreela_Roy)\
**Post date:** [March 23, 2018, 12:02pm UTC](https://forum.ansible.com/t/set-up-a-check-for-the-patching-logs-in-the-nodes/26804/3 "2018-03-23T12:02:30Z")

</div>

Hi Kai/Team,

Can you give me a small example of using file module for matching strings in the file?

---

<div class="post-metadata">

**Author:** ![Shreela\_Roy](https://avatars.discourse-cdn.com/v4/letter/s/46a35a/32.png) [@Shreela\_Roy](https://forum.ansible.com/u/Shreela_Roy)\
**Post date:** [April 3, 2018, 5:48am UTC](https://forum.ansible.com/t/set-up-a-check-for-the-patching-logs-in-the-nodes/26804/4 "2018-04-03T05:48:31Z")

</div>

Hi All,

What I want to achieve here is check the log file: 12-2017PM-PATCH.log

and find for the word COMPLETED in it and return to me the output for each server where I searched for the log.

What would be the syntax to put the search string in contains parameter and patterns parameter. Please please help me. I tried as below, need your guidance

-sh-4.1$ ansible-playbook ip360\_mod\_02042018.yml  
SUDO password:

PLAY [all] \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*

TASK [Gathering Facts] \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*  
ok: [10.54.38.37]

TASK [check the Logs to find if patching completed] \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*  
ok: [10.54.38.37]

TASK [print matches] \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*  
ok: [10.54.38.37] =\> {  
“msg”: {  
“changed”: false,  
“examined”: 222,  
“failed”: false,  
“files”: ,  
“matched”: 0,  
“msg”: “”  
}  
}

PLAY RECAP \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*  
10.54.38.37 : ok=3 changed=0 unreachable=0 failed=0

-sh-4.1$ cat ip360\_mod\_02042018.yml

---

<div class="post-metadata">

**Author:** ![Kai\_Stian\_Olstad](https://avatars.discourse-cdn.com/v4/letter/k/e19adc/32.png) [@Kai\_Stian\_Olstad](https://forum.ansible.com/u/Kai_Stian_Olstad)\
**Post date:** [April 3, 2018, 8:12pm UTC](https://forum.ansible.com/t/set-up-a-check-for-the-patching-logs-in-the-nodes/26804/5 "2018-04-03T20:12:40Z")

</div>

> Hi All,
> 
> What I want to achieve here is check the log file: 12-2017PM-PATCH.log
> 
> and find for the word COMPLETED in it and return to me the output for each  
> server where I searched for the log.
> 
> What would be the syntax to put the search string in contains parameter and  
> patterns parameter. Please please help me. I tried as below, need your  
> guidance

I saw I wrote file module when I meant find module back in March, sorry about that.

> ---  
> - hosts: all  
> &nbsp;&nbsp;become: true  
> &nbsp;&nbsp;tasks:  
> &nbsp;&nbsp;&nbsp;&nbsp;- name: check the Logs to find if patching completed  
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;find:  
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;paths: "/var/log"  
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;recurse: yes  
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;follow: True  
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;patterns: "\*PATCH.\*"  
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;#use\_regex: True  
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;contains: "\*COMPLETED\*"  
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;register: success\_patch\_logs  
> &nbsp;&nbsp;&nbsp;&nbsp;- name: print matches  
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;debug:  
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;msg: "{{ success\_patch\_logs }}"

The contains: is regex so you need to use ".\*COMPLETED.\*"
