I am trying to grep
the keyword ERROR
in all log files present in the directory /home/application/logs
using the following playbook:
---
- hosts: localhost
become: yes
gather_facts: False
tasks:
- name: Find the log files
find:
paths: /home/application/logs
pattern: '*Errors.log'
register: logfiles
- name: Check for errors in Logfiles
shell:
cmd: "cat {{ item.path }} | grep ERROR"
with_items: "{{ logfiles.files }}"
This is what I get:
PLAY [localhost] ********************************************************************************************************************************************
TASK [Find the log files] ***********************************************************************************************************************************
ok: [localhost]
TASK [Check for errors in Logfiles] *************************************************************************************************************************
changed: [localhost] => (item={u'rusr': True, u'uid': 0, u'rgrp': True, u'xoth': True, u'islnk': False, u'woth': False, u'nlink': 1, u'issock': False, u'mtime': 1642488884.289124, u'gr_name': u'root', u'path': u'/home/application/logs/AgentErrors.log', u'xusr': True, u'atime': 1642850644.2357764, u'inode': 524344, u'isgid': False, u'size': 292, u'isdir': False, u'ctime': 1642832206.1996558, u'isblk': False, u'wgrp': False, u'xgrp': True, u'isuid': False, u'dev': 64771, u'roth': True, u'isreg': True, u'isfifo': False, u'mode': u'0755', u'pw_name': u'root', u'gid': 0, u'ischr': False, u'wusr': True})
changed: [localhost] => (item={u'rusr': True, u'uid': 0, u'rgrp': True, u'xoth': False, u'islnk': False, u'woth': False, u'nlink': 1, u'issock': False, u'mtime': 1642832446.9004142, u'gr_name': u'root', u'path': u'/home/application/logs/AppErrors.log', u'xusr': False, u'atime': 1642832446.9034142, u'inode': 524434, u'isgid': False, u'size': 402, u'isdir': False, u'ctime': 1642832446.9004142, u'isblk': False, u'wgrp': False, u'xgrp': False, u'isuid': False, u'dev': 64771, u'roth': True, u'isreg': True, u'isfifo': False, u'mode': u'0644', u'pw_name': u'root', u'gid': 0, u'ischr': False, u'wusr': True})
PLAY RECAP **************************************************************************************************************************************************
localhost : ok=2 changed=1 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0
All I want is the line inside the logs containing the keyword ERROR
.