Greetings,
I know it has been attempted before and is still slated for the future, but I recently needed fact caching in my personal use of Ansible. I leveraged the work that was already done to fix the bugs that were present and complete a handful of working caching backends: redis, memcached, and a simple file backend. I have been using them in my environments for a couple of weeks now (mostly redis, but testing the others as well), and haven’t had any issues. I am still extremely new to Ansible, and basically only have enough knowledge of the internals to implement the aforementioned functionality. That said, I figured I’d re-open discussion on this topic here before submitting a pull request. I’ve included a link here and below to a feature branch diff against the devel branch for review. Things of note:
- Only SETUP_CACHE is leveraging caching backends. VARS_CACHE is untouched as I’m not quite sure I understand the use-case behind caching play variables between playbook executions.
- Caching backends have a base class they should extend to ensure the API is properly implemented. All the heavy lifting is done by each caching backend.
- Given the existing usage of SETUP_CACHE (eg: dictionary based access), caching backends must be able to return the keys that are being held in cache. There are various ways of doing that can be seen in the diff. Redis is perhaps the most interesting and optimal since it allows usage of sorted sets.
- All unit tests pass and the sample playbooks noted as issues in the previous threads are not present. I haven’t had time recently to do so, but I’ll work on running the integration tests as well.
Hopefully I’m not encroaching on any plans of major refactoring for fact caching since I know it’s been in the pipeline for awhile. I don’t have any strong opinions on the matter, but I figured that I would make what I’ve done available in the event it might be useful.
Diff for Fact Caching Feature Branch: https://github.com/joshdrake/ansible/compare/feature/fact_caching?expand=1&w=1