What are facts and how are they gathered?
BeginnerConceptVariables, Facts and Precedence
Answer
Facts are data about a managed node: OS and version, IP addresses, CPU, memory, mounts, devices, environment. They are gathered by the setup module, run automatically at the start of each play unless gather_facts: false.
ansible web1 -m ansible.builtin.setup
ansible web1 -m ansible.builtin.setup -a "filter=ansible_distribution*"
Used in conditions and templates: when: ansible_facts['os_family'] == 'Debian'.
More on Variables, Facts and Precedence
Where can you define variables in Ansible?BeginnerHow do you reference a variable, and when must you quote it?BeginnerGive a summary of variable precedence.IntermediateWhat are the lowest and highest precedence sources, and why does that matter?IntermediateWhat is the difference between a role's `defaults/` and `vars/`?IntermediateWhat is the difference between `ansible_facts['x']` and the older `ansible_x` variables?Intermediate