Showing results for 
Search instead for 
Did you mean: 

RH 294 Ansible Facts

How are Ansible Facts variables derived?  Is there a naming syntax/format?  Can I refer to a doc similar to ansible-doc -l ?

I have run the example play in Chapter 4 (below) but see no direct relationship between the values that are outputted and the variables that are listed in table 4.3.  Yes, I see a relationship but it seems to me it is only a loose one.  We are after all, writing code and syntax matters!

- name: Fact dump
hosts: all
- name: Print all facts
var: ansible_facts names that are used.


This is one area that I felt was poorly explained.  Any clarification would be appreciated.  Thanks


Labels (2)
0 Kudos
1 Reply
Starfighter Starfighter

Facts are collected by a play by default if gather_facts: no (or other false boolean) isn't declared.  You can also collect facts at any time by running the setup module in a task.  Essentially, plays automatically have an implicit setup task as their first task unless you turn off fact gathering for the play.

The documentation for what facts are gathered seems to be pretty sparse upstream (at least the last time we looked).  All the facts should be stored in the ansible_facts variable in modern Ansible, so as the book shows, the easiest way to see them is to use debug to dump them.  If you're really ambitious, the setup module is Python code so you can see what it's doing to collect facts, but....

It used to be that all facts were "injected" as variables with names starting with the pattern ansible_ but that was a mess to explore.  That's likely to go away in future versions of Ansible.

Join the discussion
You must log in to join this conversation.