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,