# Share data between lookup plugin instances

**URL:** <https://forum.ansible.com/t/share-data-between-lookup-plugin-instances/36938>\
**Category:** Ansible Developer\
**Created:** [August 3, 2022, 10:14am UTC](https://forum.ansible.com/t/share-data-between-lookup-plugin-instances/36938 "2022-08-03T10:14:54Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Pieter\_Voet](https://avatars.discourse-cdn.com/v4/letter/p/5fc32e/32.png) [@Pieter\_Voet](https://forum.ansible.com/u/Pieter_Voet)\
**Post date:** [August 3, 2022, 10:14am UTC](https://forum.ansible.com/t/share-data-between-lookup-plugin-instances/36938/1 "2022-08-03T10:14:54Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/ansible/original/1X/1882d9a01da5d8996a862359b0913cc568a39b84.svg) [@system](https://forum.ansible.com/u/system)\
**Post date:** [August 3, 2022, 1:09pm UTC](https://forum.ansible.com/t/share-data-between-lookup-plugin-instances/36938/2 "2022-08-03T13:09:54Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Pieter\_Voet](https://avatars.discourse-cdn.com/v4/letter/p/5fc32e/32.png) [@Pieter\_Voet](https://forum.ansible.com/u/Pieter_Voet)\
**Post date:** [August 3, 2022, 2:07pm UTC](https://forum.ansible.com/t/share-data-between-lookup-plugin-instances/36938/3 "2022-08-03T14:07:15Z")

</div>

OK, thanks Brian !
