When: inventory_hostname not in ./my_file.txt

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 !! :wink:

Thanks you ! :slight_smile:

Regards,

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.