Inventory pattern matching from lookup plugin

17 views
Skip to first unread message

Randy Syring

unread,
Jun 1, 2017, 2:06:59 PM6/1/17
to Ansible Project
 I want to develop a lookup plugin that would take a string like "mygroup:!badhost" and return the list of host objects that match that pattern.

Based on my inspection of the Ansible source code, it seems like I could probably do that if I can get reference to an instance of the InventoryManager object.  Can i get access to the inventory object from within a lookup plugin?

Matt Martz

unread,
Jun 1, 2017, 2:10:45 PM6/1/17
to ansible...@googlegroups.com
There is a lookup that already does this called "inventory_hostnames"




On Thu, Jun 1, 2017 at 1:07 PM Randy Syring <randy....@level12.io> wrote:
 I want to develop a lookup plugin that would take a string like "mygroup:!badhost" and return the list of host objects that match that pattern.

Based on my inspection of the Ansible source code, it seems like I could probably do that if I can get reference to an instance of the InventoryManager object.  Can i get access to the inventory object from within a lookup plugin?

--
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 ansible-proje...@googlegroups.com.
To post to this group, send email to ansible...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/21974bf8-3f68-47cb-9c13-0328c72e7b5c%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
--
Matt Martz
@sivel
sivel.net

Matt Martz

unread,
Jun 1, 2017, 2:12:17 PM6/1/17
to ansible...@googlegroups.com
I suppose to expand on that, once you have the name, you can then use 

hostvars[item] to effectively get the data associated with the host.

Not an actual Host object, but it should have what you need

Randy Syring

unread,
Jun 1, 2017, 4:25:02 PM6/1/17
to ansible...@googlegroups.com
Great, thanks so much!

Randy Syring
Chief Executive Developer
Direct: 502.276.0459
Office: 812.285.8766

Level 12

You received this message because you are subscribed to a topic in the Google Groups "Ansible Project" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/ansible-project/WKI8ATqzVBI/unsubscribe.
To unsubscribe from this group and all its topics, send an email to ansible-proje...@googlegroups.com.

To post to this group, send email to ansible...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages