Hi All ,
I have to search for a pattern string in the various log files located in
some directory on the host. how we can use regex kind of a thing with
command module or may be some other useful ansible way i am not aware about.
here is my code which complains about vm*.log.
- name: Check whether vmware log file contains TDR
command: grep 'TDR_DUMP' '{{guest_vm_path}}/{{item}}/vm*.log'
with_items:
- '{{guest_list}}'
- '{{guest_name_poweredon}}'
ignore_errors: True
register: output
- debug:
var: output
- debug: msg="No TDR signature found"
when: output["results"][0].rc == 1 and
output["results"][1].rc == 1 and
output["results"][2].rc == 1
- debug: msg="Found the TDR signature"
when: output["results"][0].rc == 0 or
output["results"][1].rc == 0 or
output["results"][2].rc == 0
- debug:
var: output.stdout_lines
when: output["results"][0].rc == 0 or
output["results"][1].rc == 0 or
output["results"][2].rc == 0
OutPUT:
ok: [x.x.x.x] => {
"output": {
"changed": true,
"failed": true,
"msg": "One or more items failed",
"results": [
{
"_ansible_item_result": true,
"_ansible_no_log": false,
"_ansible_parsed": true,
"changed": true,
"cmd": [
"grep",
"TDR_DUMP",
"/vmfs/volumes/mag27_datastore/test1/vm*.log"
],
"delta": "0:00:00.015495",
"end": "2017-10-14 04:35:30.309261",
"failed": true,
"invocation": {
"module_args": {
"_raw_params": "grep 'TDR_DUMP'
'/vmfs/volumes/mag27_datastore/test1/vm*.log'",
"_uses_shell": false,
"chdir": null,
"creates": null,
"executable": null,
"removes": null,
"warn": true
}
},
"item": "test1",
"rc": 2,
"start": "2017-10-14 04:35:30.293766",
"stderr": "grep: /vmfs/volumes/mag27_datastore/test1/vm*.log:
No such file or directory",
"stderr_lines": [
"grep: /vmfs/volumes/mag27_datastore/test1/vm*.log: No such
file or directory"
],
"stdout": "",
"stdout_lines": []
},
{
"_ansible_item_result": true,
--
You received this message because you are subscribed to the Google Groups
"Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/ansible-project/b45af043-5aa9-42e5-9a4b-8fd64b74333d%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.