Facts no longer available in lookup plugin

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?

the 3rd var passed into the run method are the host variables, which
should include facts.

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

I see it as the third (counting self) in both versions.

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.