# When: inventory\_hostname not in ./my\_file.txt

**URL:** <https://forum.ansible.com/t/when-inventory-hostname-not-in-my-file-txt/30143>\
**Category:** Ansible Project\
**Created:** [April 18, 2019, 8:12am UTC](https://forum.ansible.com/t/when-inventory-hostname-not-in-my-file-txt/30143 "2019-04-18T08:12:52Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![ryad9200000](https://avatars.discourse-cdn.com/v4/letter/r/f04885/32.png) [@ryad9200000](https://forum.ansible.com/u/ryad9200000)\
**Post date:** [April 18, 2019, 8:12am UTC](https://forum.ansible.com/t/when-inventory-hostname-not-in-my-file-txt/30143/1 "2019-04-18T08:12:52Z")

</div>

Hi all,

I have this file “my\_file.txt” with this content :

1,user1,host1  
2,user2,host2

My inventory is :

host5

I want condition “when” for skip same task if inventory\_hostname is not in my file “my\_file.txt”

exemple :

.  
same tasks  
.  
.  
**when: inventory\_hostname not in ./my\_file.txt**

but this synthax not works ;(

can you help me please community ansible !! 😉

Thanks you ! 🙂

Regards,

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/ansible/original/1X/1882d9a01da5d8996a862359b0913cc568a39b84.svg) [@system](https://forum.ansible.com/u/system)\
**Post date:** [April 18, 2019, 3:46pm UTC](https://forum.ansible.com/t/when-inventory-hostname-not-in-my-file-txt/30143/2 "2019-04-18T15:46:59Z")

</div>

assuming the file is 'local on the controller':

when: lookup('pipe', 'grep ' + inventory\_hostname + ' ../myfile.txt'

otherwise use the 'find' plugin with 'contains', register results and  
use conditional on that.
