Share object between modules

Hi All,

We have different module to do different activity.
https://github.com/Juniper/ansible-junos-stdlib/tree/master/library

Every time each modules/tasks will connect to the device (and close the connection).

So if we are using say 4 modules/tasks in our playbook, We are ideally connecting to Juniper devices 4 time (While starting connection each time lot of other process is followed)

That obviously will be impacting the performance.

Is there a way to share the connection object over the different modules?

Thanks

Nitin Kr

I think only way to work around this is somehow create persistent connection to junos device. Same way like ssh is doing it.

First off, I don’t know that this would be possible with modules because, I believe, that the modules are executed outside of Ansible, even when they are run locally (this is why you can write the modules in bash, perl, tcl, etc). Therefore, sharing anything (other than text sent as a task_arg) between them is not possible.

However, the Juniper-supplied modules only seem to support:
commit, get_config, get_facts, install_config, install_os, rollback, shutdown, srx_cluster, zeroize

So, most of your operations are probably going to be install_config (install_config does the commit for you so you don’t have to call that separately).

IF this is the case, you could always generate the bits of config from templates, then use the assemble ansible module to put them into a single file and then only call install_config the one time.

Unfortunately, if you are wanting to do things in between the juniper tasks (like check, verify, etc), then you might be able to do something with pickles and creating an action_plugin or modifying the Juniper-supplied libraries.

I think the only way to do this would be to modify the Juniper-supplied libraries. Currently,