Set up a check for the patching logs in the nodes

18 views
Skip to first unread message

Shreela Roy

unread,
Feb 20, 2018, 12:38:06 PM2/20/18
to Ansible Project
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.

Kai Stian Olstad

unread,
Feb 20, 2018, 12:54:39 PM2/20/18
to ansible...@googlegroups.com
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


--
Kai Stian Olstad

Shreela Roy

unread,
Mar 23, 2018, 8:02:31 AM3/23/18
to Ansible Project
Hi Kai/Team,

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

Shreela Roy

unread,
Apr 3, 2018, 1:48:31 AM4/3/18
to Ansible Project
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
---
- 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 }}"

Kai Stian Olstad

unread,
Apr 3, 2018, 4:13:00 PM4/3/18
to ansible...@googlegroups.com
On 03.04.2018 07:48, Shreela Roy wrote:
> 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.*"


--
Kai Stian Olstad
Reply all
Reply to author
Forward
0 new messages