# How to reuse an http client object ?

**URL:** <https://forum.ansible.com/t/how-to-reuse-an-http-client-object/37957>\
**Category:** Ansible Project\
**Created:** [May 3, 2023, 1:31pm UTC](https://forum.ansible.com/t/how-to-reuse-an-http-client-object/37957 "2023-05-03T13:31:39Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Jan\_Goyvaerts](https://avatars.discourse-cdn.com/v4/letter/j/13edae/32.png) [@Jan\_Goyvaerts](https://forum.ansible.com/u/Jan_Goyvaerts)\
**Post date:** [May 3, 2023, 1:31pm UTC](https://forum.ansible.com/t/how-to-reuse-an-http-client-object/37957/1 "2023-05-03T13:31:39Z")

</div>

Hello Community,

Is it possible to put a client object somewhere so it can be shared/reused by custom plugins ? That is, only for tasks running on the controlling node.

I’m trying to reuse the very same pysnow client object in successive tasks. Hoping to improve the performance of a very long running playbook.

THX

---

<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:** [May 3, 2023, 1:48pm UTC](https://forum.ansible.com/t/how-to-reuse-an-http-client-object/37957/2 "2023-05-03T13:48:41Z")

</div>

I'm assuming you are in a collection context, so plugins/module\_utils  
(they are also available to controller, not just modules)

---

<div class="post-metadata">

**Author:** ![Jan\_Goyvaerts](https://avatars.discourse-cdn.com/v4/letter/j/13edae/32.png) [@Jan\_Goyvaerts](https://forum.ansible.com/u/Jan_Goyvaerts)\
**Post date:** [May 3, 2023, 3:27pm UTC](https://forum.ansible.com/t/how-to-reuse-an-http-client-object/37957/3 "2023-05-03T15:27:31Z")

</div>

No collections. Just the classic \*\_plugins directories. For example action\_plugins.

The code is available to the controlling node too. What I’m trying to achieve is to create once the pysnow client, put it ‘somewhere’ and have the action plugins access this very same object. However, what is that ‘somewhere’, if any.

Unfortunately, every task runs in a different process (the pid is different) but they all share the same parent process. So, maybe, there is a way. I guess this is what Ansible does when it reuses the ssh connection.

Just don’t know where to look 🙂

---

<div class="post-metadata">

**Author:** ![felixfontein](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/felixfontein/32/7530_2.png) [@felixfontein](https://forum.ansible.com/u/felixfontein)\
**Post date:** [May 4, 2023, 5:30am UTC](https://forum.ansible.com/t/how-to-reuse-an-http-client-object/37957/4 "2023-05-04T05:30:48Z")

</div>

Hi,

> Is it possible to put a client object somewhere so it can be  
> shared/reused by custom plugins ? That is, only for tasks running on  
> the controlling node.
> 
> I'm trying to reuse the very same pysnow client object in successive  
> tasks. Hoping to improve the performance of a very long running  
> playbook.

for modules there exists some framework in cloud.common  
([https://galaxy.ansible.com/cloud/common](https://galaxy.ansible.com/cloud/common)) called 'Ansible turbo module'  
providing something like that (disclaimer: I've never used it). Not  
sure whether that also works for plugins though...

Cheers,  
Felix

---

<div class="post-metadata">

**Author:** ![Jan\_Goyvaerts](https://avatars.discourse-cdn.com/v4/letter/j/13edae/32.png) [@Jan\_Goyvaerts](https://forum.ansible.com/u/Jan_Goyvaerts)\
**Post date:** [May 4, 2023, 6:41am UTC](https://forum.ansible.com/t/how-to-reuse-an-http-client-object/37957/5 "2023-05-04T06:41:01Z")

</div>

I don’t know it either, but I’ll have a look. thanks for the hint ! 🙂

---

<div class="post-metadata">

**Author:** ![Jan\_Goyvaerts](https://avatars.discourse-cdn.com/v4/letter/j/13edae/32.png) [@Jan\_Goyvaerts](https://forum.ansible.com/u/Jan_Goyvaerts)\
**Post date:** [May 4, 2023, 11:55am UTC](https://forum.ansible.com/t/how-to-reuse-an-http-client-object/37957/6 "2023-05-04T11:55:08Z")

</div>

So, if I’m getting this right, the idea is that the custom plugin code connects with a daemon process. And that daemon maintains the connection and other stateful data ?
