fact disappears after regather

26 views
Skip to first unread message

Michael DiDomenico

unread,
Nov 2, 2023, 1:44:41 PM11/2/23
to ansible...@googlegroups.com
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
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?

Brian Coca

unread,
Nov 2, 2023, 1:49:14 PM11/2/23
to ansible...@googlegroups.com
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.

----------
Brian Coca

Michael DiDomenico

unread,
Nov 2, 2023, 1:58:10 PM11/2/23
to ansible...@googlegroups.com
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)
> --
> You received this message because you are subscribed to the Google Groups "Ansible Project" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to ansible-proje...@googlegroups.com.
> To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/CACVha7cQ-j-efohvG5yKpRuVq8zAWSvHw8F7rz1-tR9a3hxeUg%40mail.gmail.com.

Brian Coca

unread,
Nov 2, 2023, 3:52:06 PM11/2/23
to ansible...@googlegroups.com
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.


--
----------
Brian Coca

Michael DiDomenico

unread,
Nov 3, 2023, 9:13:47 AM11/3/23
to ansible...@googlegroups.com
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'



--
You received this message because you are subscribed to the Google Groups "Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ansible-proje...@googlegroups.com.

Brian Coca

unread,
Nov 3, 2023, 2:04:41 PM11/3/23
to ansible...@googlegroups.com
I cannot reproduce, either both have it defined or undefined
(depending if i add /etc/ansible/facts.d/fstab.fact or not).


--
----------
Brian Coca

Michael DiDomenico

unread,
Nov 3, 2023, 3:04:24 PM11/3/23
to ansible...@googlegroups.com
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?



--
You received this message because you are subscribed to the Google Groups "Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ansible-proje...@googlegroups.com.

Brian Coca

unread,
Nov 3, 2023, 3:17:12 PM11/3/23
to ansible...@googlegroups.com
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.



--
----------
Brian Coca

Reply all
Reply to author
Forward
0 new messages