# fact disappears after regather

**URL:** <https://forum.ansible.com/t/fact-disappears-after-regather/38564>\
**Category:** Ansible Project\
**Created:** [November 2, 2023, 5:44pm UTC](https://forum.ansible.com/t/fact-disappears-after-regather/38564 "2023-11-02T17:44:12Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![mdidomenico](https://avatars.discourse-cdn.com/v4/letter/m/c4cdca/32.png) [@mdidomenico](https://forum.ansible.com/u/mdidomenico)\
**Post date:** [November 2, 2023, 5:44pm UTC](https://forum.ansible.com/t/fact-disappears-after-regather/38564/1 "2023-11-02T17:44:12Z")

</div>

i have a local fact defined. when i first run ansible and it runs  
through the gather facts stage, the fact shows up just fine. i do  
some tasks and then regather the facts with setup

- name: regather facts  
&nbsp;&nbsp;ansible.builtin.setup:

i can see the gather task run, but when i look for that same variable  
after the regather of the facts it's missing. the fact is  
ansible\_local.fstab and there's a dictionary under it, but the entire  
ansible\_local tree disappears

i tried adding gather\_subset: all but that didn't see to make a  
difference. is there something else i need to do to rerun a fact and  
refresh the data?

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/ansible/original/1X/1882d9a01da5d8996a862359b0913cc568a39b84.svg) [@system](https://forum.ansible.com/u/system)\
**Post date:** [November 2, 2023, 5:48pm UTC](https://forum.ansible.com/t/fact-disappears-after-regather/38564/2 "2023-11-02T17:48:47Z")

</div>

Fact gathering overwrites all facts for a host, it does not update.  
ansible\_local is actually a subset of the facts gathered, it is  
updated to what ansible\_facts['local'] returns.

---

<div class="post-metadata">

**Author:** ![mdidomenico](https://avatars.discourse-cdn.com/v4/letter/m/c4cdca/32.png) [@mdidomenico](https://forum.ansible.com/u/mdidomenico)\
**Post date:** [November 2, 2023, 5:57pm UTC](https://forum.ansible.com/t/fact-disappears-after-regather/38564/3 "2023-11-02T17:57:39Z")

</div>

ok, my terminology was a little off, i'm okay with it overwriting then  
entire fact tree. but i'm still not sure why the entire branch of  
ansible\_local disappears after the second run of gathering. is there  
something different happening when the play runs "gather\_facts"  
version ansible.builtin.setup? (i wouldn't have thought so)

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/ansible/original/1X/1882d9a01da5d8996a862359b0913cc568a39b84.svg) [@system](https://forum.ansible.com/u/system)\
**Post date:** [November 2, 2023, 7:51pm UTC](https://forum.ansible.com/t/fact-disappears-after-regather/38564/4 "2023-11-02T19:51:41Z")

</div>

No, but it overwrites it even if the results from the current run are  
empty. Fact gathering is supposed to reflect 'current state' so if for  
example you remove a network interface, but had gathered facts about  
it before hand, when you refresh facts, it will disappear from those  
also.

---

<div class="post-metadata">

**Author:** ![mdidomenico](https://avatars.discourse-cdn.com/v4/letter/m/c4cdca/32.png) [@mdidomenico](https://forum.ansible.com/u/mdidomenico)\
**Post date:** [November 3, 2023, 1:13pm UTC](https://forum.ansible.com/t/fact-disappears-after-regather/38564/5 "2023-11-03T13:13:18Z")

</div>

okay, that’s understood. but i’m not sure my behavior is reflecting what you’re saying. either because ansible is doing something unexpected, or more likely i’m doing something wrong. what i see is

using this playbook

- name: dump vars  
hosts: all  
connection: local  
gather\_facts: true  
tasks:
- name: disp var  
debug:  
var: ansible\_local.fstab
- name: regather  
ansible.builtin.setup:
- name: redisp var  
debug:  
var: ansible\_local.fstab

ansible start  
gather facts

the debug will output the variable (which is just a dict of /etc/fstab)  
regather the facts through setup  
the second debug then outputs  
ansible\_local.fstab: ‘VARIABLE IS NOT DEFINED’

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/ansible/original/1X/1882d9a01da5d8996a862359b0913cc568a39b84.svg) [@system](https://forum.ansible.com/u/system)\
**Post date:** [November 3, 2023, 6:04pm UTC](https://forum.ansible.com/t/fact-disappears-after-regather/38564/6 "2023-11-03T18:04:14Z")

</div>

I cannot reproduce, either both have it defined or undefined  
(depending if i add /etc/ansible/facts.d/fstab.fact or not).

---

<div class="post-metadata">

**Author:** ![mdidomenico](https://avatars.discourse-cdn.com/v4/letter/m/c4cdca/32.png) [@mdidomenico](https://forum.ansible.com/u/mdidomenico)\
**Post date:** [November 3, 2023, 7:03pm UTC](https://forum.ansible.com/t/fact-disappears-after-regather/38564/7 "2023-11-03T19:03:54Z")

</div>

it looks like it’s related to my fact pathing in some manner. in ansible.cfg we defined fact\_path=/ansible/facts and there are no facts in /etc/ansible/facts.d. if i copy the fstab.fact file from /ansible/facts to /etc/ansible/facts.d then i do in get the variable before and after the setup module runs in the play

so does ansible reset like literally everything when you run the setup module? does it not re pull in the ansible.cfg where i have paths defined?

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/ansible/original/1X/1882d9a01da5d8996a862359b0913cc568a39b84.svg) [@system](https://forum.ansible.com/u/system)\
**Post date:** [November 3, 2023, 7:16pm UTC](https://forum.ansible.com/t/fact-disappears-after-regather/38564/8 "2023-11-03T19:16:47Z")

</div>

No, the cfg setting affects 'fact gathering' but not specific module  
executions, you executing the 'setup' module or any other that returns  
facts is not exactly the same thing.

Use module\_defaults or just set the local facts dir when you invoke setup.
