Hi, I am fairly new to Ansible, so would appreciate some help.
I am trying to look in a .csv or .txt file. I need to email it when the entry ‘0 rows’ does not appear. Basically the file has been produced by a software vendor, and a result of ‘0 rows’ confirms no errors. Any other result would mean there are errors.
I have tried the following code, after not having much success with ‘lineinfile’. However, the play emails me whether it has found the text or not. I did try a debug argument on it to view the output and noted that ‘json’ was full off characters similar to:
“presence.stdout”: "ÿþJ\u0000o\u0000b\u0000 \u0000’\u0000P\u0000a\u0000u\u0000s\u0000e\u0000 \u0000a\u0000n\u0000d\u0000
However, the ‘standard out’ does contain the information I require:
(0 rows(s) affected)
Any suggestions are much appreciated. Thanks.
tasks:
- name: read the fileout file
shell: cat /directory/directory/fileout.txt
register: presence
- name: a task that only happens if the entry exists
when: “‘0 rows’ not in presence”
mail:
host: localhost
port: 25
Hi, I am fairly new to Ansible, so would appreciate some help.
I am trying to look in a .csv or .txt file. I need to email it when the
entry '0 rows' does not appear. Basically the file has been produced by a
software vendor, and a result of '0 rows' confirms no errors. Any other
result would mean there are errors.
I have tried the following code, after not having much success with
'lineinfile'. However, the play emails me whether it has found the text or
not.
lineinfile is used to add line(s) to a file.
I did try a debug argument on it to view the output and noted that
'json' was full off characters similar to:
"presence.stdout": "ÿþJ\u0000o\u0000b\u0000
\u0000'\u0000P\u0000a\u0000u\u0000s\u0000e\u0000 \u0000a\u0000n\u0000d\u0000
However, the 'standard out' does contain the information I require:
(0 rows(s) affected)
Any suggestions are much appreciated. Thanks.
- hosts: localhost
tasks:
- name: read the fileout file
shell: cat /directory/directory/fileout.txt
register: presence
- name: a task that only happens if the entry exists
when: "'0 rows' not in presence"
So you information is in presence.stdout but you are using presence instead.
presence is a dictionary that contain a lot of information about the shell task, the output of the command in the shell is stored in presence.stdout so you need to use that one.