How to reuse an http client object ?

20 views
Skip to first unread message

Jan Goyvaerts

unread,
May 3, 2023, 9:31:39 AM5/3/23
to Ansible Project
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

Brian Coca

unread,
May 3, 2023, 9:51:02 AM5/3/23
to ansible...@googlegroups.com
I'm assuming you are in a collection context, so plugins/module_utils
(they are also available to controller, not just modules)


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

Jan Goyvaerts

unread,
May 3, 2023, 11:27:31 AM5/3/23
to Ansible Project

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 :-)

Felix Fontein

unread,
May 4, 2023, 1:31:08 AM5/4/23
to ansible...@googlegroups.com
Hi,
for modules there exists some framework in 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


Jan Goyvaerts

unread,
May 4, 2023, 2:41:01 AM5/4/23
to Ansible Project
I don't know it either, but I'll have a look. thanks for the hint ! :-)

Jan Goyvaerts

unread,
May 4, 2023, 7:55:08 AM5/4/23
to Ansible Project
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 ?
On Thursday, May 4, 2023 at 7:31:08 AM UTC+2 Felix Fontein wrote:
Reply all
Reply to author
Forward
0 new messages