Facts no longer available in lookup plugin

31 views
Skip to first unread message

Christian Hammerl

unread,
Aug 19, 2015, 10:02:19 PM8/19/15
to Ansible Project
Some time ago, I wrote a small lookup plugin https://github.com/mantiz/ansible-lookup-plugin-os-specific

This plugin allows/allowed to define a list of items where each item could be specialized for a specific os or distribution.
For this to work, I need the facts to access ansible_distribution and so on.

Yesterday, I updated to the latest git version of ansible and the facts seem no longer be passed to the module.

Is there another way to access the facts from inside the module?

The only workaround I found was to pass the facts manually, like:

- some_task: ...
  with_os_specific
:
    facts
: "{{ vars }}"
    items
:
     
- ...

But this is annoying and easy to forget.

If there is no way to access the facts, is there any other way to solve the issue, the plugin solves?

Brian Coca

unread,
Aug 19, 2015, 11:06:02 PM8/19/15
to Ansible Project
the 3rd var passed into the run method are the host variables, which
should include facts.


--
Brian Coca

Christian Hammerl

unread,
Aug 20, 2015, 11:43:22 AM8/20/15
to Ansible Project
Oh dear, thank you very much.
It was previously the 2nd variable which contained the facts and I didn't even think about inspecting the third one. ;)

Brian Coca

unread,
Aug 20, 2015, 11:45:28 AM8/20/15
to Ansible Project
I see it as the third (counting self) in both versions.



--
Brian Coca

Christian Hammerl

unread,
Aug 20, 2015, 6:04:55 PM8/20/15
to Ansible Project
Hm, that's strange.

Previously, my method's signature was:

def run(self, terms, inject=None, **kwargs):

I'm no python guy and I really don't know what this 'kwargs' means but I think it may be related to named parameters.
The above signature worked until I updated ansible yesterday to the current master.

If I change the signature to this:

def run(self, terms, variables=None, **kwargs):

the variables parameter is set accordingly but kwargs no longer has a key 'variables'.

So, I think this parameter was renamed from 'inject' to 'variables' some time ago, or the method caller changed from positional parameters to named parameters, I don't know.

However, the facts are now accessible through "variables['vars']" which is fine for me.

Thanks again for your help which pointed me to the right direction.

Reply all
Reply to author
Forward
0 new messages