# connection caching throughout a play

**URL:** <https://forum.ansible.com/t/connection-caching-throughout-a-play/30030>\
**Category:** Ansible Project\
**Created:** [March 29, 2019, 9:27pm UTC](https://forum.ansible.com/t/connection-caching-throughout-a-play/30030 "2019-03-29T21:27:20Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Michael\_Stroder](https://avatars.discourse-cdn.com/v4/letter/m/7ea924/32.png) [@Michael\_Stroder](https://forum.ansible.com/u/Michael_Stroder)\
**Post date:** [March 29, 2019, 9:27pm UTC](https://forum.ansible.com/t/connection-caching-throughout-a-play/30030/1 "2019-03-29T21:27:20Z")

</div>

HI!

On the ansible controller I'd like to establish an authenticated LDAP  
connection at the beginning of a playbook run and use this afterwards in  
several tasks.

Up to now the ansible modules I reviewed seem to re-open all kinds of  
backend connections all the time using long-term credentials. Which  
means I cannot use 2-factor-auth with an OTP.  
(No, using Kerberos is not an option.)

So I wonder whether it's possible to cache a connection object and  
re-use it in subsequent tasks. Any framework for something like this?

Ciao, Michael.

---

<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:** [April 3, 2019, 8:41pm UTC](https://forum.ansible.com/t/connection-caching-throughout-a-play/30030/2 "2019-04-03T20:41:51Z")

</div>

Currently there is no way to do this, but it is something we have been  
thinking about for a while now as a feature.

Just don't expect it anytime soon, as it is a complex ask, specially  
if you consider modules are not guaranteed to execute on the same  
machine.
