Share data between lookup plugin instances

9 views
Skip to first unread message

piete...@gmail.com

unread,
Aug 3, 2022, 6:14:54 AM8/3/22
to Ansible Development
Hi all,

I've written a lookup plugin that authenticates to some REST endpoint.
Once authenticated a token is returned that can be reused for further REST calls.

Is there a way I can store the token someplace, so that the next invocation
of the lookup plugin can access it and use it instead of authenticating with userid/pw
again ?

I tried to access the 'play' object to get its VariableManager, but I guess that's
not accessible from a LookupPlugin.  Then I tried to use pythons'  os.environ
to set a variable, but apparently each invocation of the lookup is done using
a different python  instance, hence not sharing their environments.

Thanks for any help.

Pieter.

Brian Coca

unread,
Aug 3, 2022, 9:11:13 AM8/3/22
to piete...@gmail.com, Ansible Development
There is no facility to do this, you would have to save/read a file
like the password lookup does.
Another option is to have a task that does the login and registers the
token into a variable (via register: or returning ansible_facts).

FYI, each lookup does not have it's own python instance, but each
task/host has it's own fork.

----------
Brian Coca

piete...@gmail.com

unread,
Aug 3, 2022, 10:07:15 AM8/3/22
to Ansible Development
OK, thanks Brian !

Op woensdag 3 augustus 2022 om 15:11:13 UTC+2 schreef bc...@redhat.com:
Reply all
Reply to author
Forward
0 new messages