When: inventory_hostname not in ./my_file.txt

11 views
Skip to first unread message

ryad9...@gmail.com

unread,
Apr 18, 2019, 4:12:52 AM4/18/19
to Ansible Project
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,

Brian Coca

unread,
Apr 18, 2019, 11:48:33 AM4/18/19
to Ansible Project
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.



--
----------
Brian Coca
Reply all
Reply to author
Forward
0 new messages