# Removing a manually set fact from the fact cache

**URL:** <https://forum.ansible.com/t/removing-a-manually-set-fact-from-the-fact-cache/27855>\
**Category:** Ansible Project\
**Created:** [June 22, 2018, 10:07pm UTC](https://forum.ansible.com/t/removing-a-manually-set-fact-from-the-fact-cache/27855 "2018-06-22T22:07:37Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Matt\_Hickok](https://avatars.discourse-cdn.com/v4/letter/m/7c8e57/32.png) [@Matt\_Hickok](https://forum.ansible.com/u/Matt_Hickok)\
**Post date:** [June 22, 2018, 10:07pm UTC](https://forum.ansible.com/t/removing-a-manually-set-fact-from-the-fact-cache/27855/1 "2018-06-22T22:07:37Z")

</div>

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!

---

<div class="post-metadata">

**Author:** ![Kai\_Stian\_Olstad](https://avatars.discourse-cdn.com/v4/letter/k/e19adc/32.png) [@Kai\_Stian\_Olstad](https://forum.ansible.com/u/Kai_Stian_Olstad)\
**Post date:** [June 23, 2018, 6:44am UTC](https://forum.ansible.com/t/removing-a-manually-set-fact-from-the-fact-cache/27855/2 "2018-06-23T06:44:22Z")

</div>

> 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.

---

<div class="post-metadata">

**Author:** ![Matt\_Hickok](https://avatars.discourse-cdn.com/v4/letter/m/7c8e57/32.png) [@Matt\_Hickok](https://forum.ansible.com/u/Matt_Hickok)\
**Post date:** [June 25, 2018, 3:37pm UTC](https://forum.ansible.com/t/removing-a-manually-set-fact-from-the-fact-cache/27855/3 "2018-06-25T15:37:05Z")

</div>

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).

---

<div class="post-metadata">

**Author:** ![Matt\_Hickok](https://avatars.discourse-cdn.com/v4/letter/m/7c8e57/32.png) [@Matt\_Hickok](https://forum.ansible.com/u/Matt_Hickok)\
**Post date:** [June 25, 2018, 3:46pm UTC](https://forum.ansible.com/t/removing-a-manually-set-fact-from-the-fact-cache/27855/4 "2018-06-25T15:46:33Z")

</div>

Also, can the flushing of the cache be disabled?

---

<div class="post-metadata">

**Author:** ![Kai\_Stian\_Olstad](https://avatars.discourse-cdn.com/v4/letter/k/e19adc/32.png) [@Kai\_Stian\_Olstad](https://forum.ansible.com/u/Kai_Stian_Olstad)\
**Post date:** [June 28, 2018, 4:35pm UTC](https://forum.ansible.com/t/removing-a-manually-set-fact-from-the-fact-cache/27855/5 "2018-06-28T16:35:59Z")

</div>

> 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](https://docs.ansible.com/ansible/latest/user_guide/intro_dynamic_inventory.html)
