# Find an entry in a file and email the file if the entry IS NOT found  - Tower

**URL:** <https://forum.ansible.com/t/find-an-entry-in-a-file-and-email-the-file-if-the-entry-is-not-found-tower/27037>\
**Category:** Ansible Project\
**Created:** [March 19, 2018, 11:43am UTC](https://forum.ansible.com/t/find-an-entry-in-a-file-and-email-the-file-if-the-entry-is-not-found-tower/27037 "2018-03-19T11:43:44Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![scott.fosberry](https://avatars.discourse-cdn.com/v4/letter/s/8dc957/32.png) [@scott.fosberry](https://forum.ansible.com/u/scott.fosberry)\
**Post date:** [March 19, 2018, 11:43am UTC](https://forum.ansible.com/t/find-an-entry-in-a-file-and-email-the-file-if-the-entry-is-not-found-tower/27037/1 "2018-03-19T11:43:44Z")

</div>

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.

- 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”

mail:

host: localhost

port: 25

---

<div class="post-metadata">

**Author:** ![Kai\_Stian\_Olstad](https://avatars.discourse-cdn.com/v4/letter/k/e19adc/32.png) [@Kai\_Stian\_Olstad](https://forum.ansible.com/u/Kai_Stian_Olstad)\
**Post date:** [March 19, 2018, 12:25pm UTC](https://forum.ansible.com/t/find-an-entry-in-a-file-and-email-the-file-if-the-entry-is-not-found-tower/27037/2 "2018-03-19T12:25:58Z")

</div>

> 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
> 
> &nbsp;&nbsp;tasks:
> 
> - name: read the fileout file
> 
> &nbsp;&nbsp;shell: cat /directory/directory/fileout.txt
> 
> &nbsp;&nbsp;register: presence
> 
> - name: a task that only happens if the entry exists
> 
> &nbsp;&nbsp;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.
