Set up a check for the patching logs in the nodes

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.

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

Hi Kai/Team,

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

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

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
  become: true
  tasks:
    - name: check the Logs to find if patching completed
      find:
        paths: "/var/log"
        recurse: yes
        follow: True
        patterns: "*PATCH.*"
        #use_regex: True
        contains: "*COMPLETED*"
      register: success_patch_logs
    - name: print matches
      debug:
        msg: "{{ success_patch_logs }}"

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