On 19.03.2018 12:43, [email protected] wrote:
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.


--
Kai Stian Olstad

--
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/69f9a3355f686f8d14b0e51f380a27a5%40olstad.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to