Hello, I am setting some facts for a handful of nodes which do not have Python (so I can’t use the setup module). I am persisting the facts by using the cacheable: true flag. I have it working as intended but as I have been tweaking it I now have a bunch of facts that I not longer want to be set in the cache. I removed the tasks which set these facts from the playbook but obviously that won’t delete them from the cache.
How do I delete these set facts from the fact cache?
Thanks!
Hello, I am setting some facts for a handful of nodes which do not have
Python (so I can't use the setup module). I am persisting the facts by
using the cacheable: true flag. I have it working as intended but as I have
been tweaking it I now have a bunch of facts that I not longer want to be
set in the cache. I removed the tasks which set these facts from the
playbook but obviously that won't delete them from the cache.
You shouldn't use facts caching for this.
Use host_vars and/or group_vars and set the variables to desired value.
How do I delete these set facts from the fact cache?
It depends on where you are storing the cache, if using Redis you need to delete them from there, if using directory you need to delete the files/content of the file or just wait 24 hours and all cache will timeout anyway.
Thanks for the response Kai. Can you elaborate on how I would be using variables for this? The goal is to grab pieces of information for devices which do not have Python (by using the raw module and grabbing stdout) and then store them persistently for each host. Are you suggesting I could do this exact same process but rather than using set_fact (and cacheable:true) I could set host variables instead? Do these persist until removed? I would only be able to interact with these variables via the API (no cmdline access and no disk access), so I think these variables can be added, modified, and removed via the API using the host endpoint.
As for where the facts are being persisted right now, I am using memcache (I’m using Docker and the provided compose file).
Also, can the flushing of the cache be disabled?
Thanks for the response Kai. Can you elaborate on how I would be using
variables for this?
Facts are variables so that would be the same.
The goal is to grab pieces of information for devices
which do not have Python (by using the raw module and grabbing stdout) and
then store them persistently for each host. Are you suggesting I could do
this exact same process but rather than using set_fact (and cacheable:true)
I could set host variables instead? Do these persist until removed?
host_vars is a folder that has one yaml file per host, these files will presist until you delete them.
I would this people usually create them manually, but you can always create them with Ansible.
I would
only be able to interact with these variables via the API (no cmdline
access and no disk access), so I think these variables can be added,
modified, and removed via the API using the host endpoint.
I'm not sure what you mean by this.
But it sound like you should check out Ansible dynamic inventroy
https://docs.ansible.com/ansible/latest/user_guide/intro_dynamic_inventory.html