ansible-modules-bitwarden icon indicating copy to clipboard operation
ansible-modules-bitwarden copied to clipboard

Add cache functionality to improve lookup executing times

Open rkokkelk opened this issue 2 years ago • 1 comments

This PR adds caching functionality and improves executing times by remove unnecessary logged_in verification. As mentioned in #11, I've also encountered really long executing times in Ansible due to this plugin looking up passwords used in become.

Due to how lookups are being handled internally by Ansible, the only way to implement a caching method is to use global variables. Implementing a cache in the actual LookModule or Bitwarden module is not beneficiary because these objects are recreated for every lookup. However importing the actual Lookup plugin happens rarely and thus the cache exists for a long time within a playbook.

Because the plugin check for every lookup whether BW is still logged in, this is also now improved to only check it initially and then trust that result. This also prevents a lot of unnecessary HTTP and CLI lookups.

Caching specific values greatly increases executing times because now certain passwords does not have to be looked up every time. E.g. in my situation the sudo password is looked up for every task, even for every item in a loop, this greatly increases execution time. With this new modification now a cache lookup is used instead of BW lookups. Manual verification shows that this has a extreme benefit on the execution time.

This PR will fix #11.

rkokkelk avatar Aug 20 '21 13:08 rkokkelk

@c0sco any indication when this could be merged?

rkokkelk avatar Jun 04 '23 17:06 rkokkelk