Add cache functionality to improve lookup executing times #18
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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
orBitwarden
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.