Interview Prep/Ansible/Variables, Facts and Precedence

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

All Ansible questions Roadmap: Ansible

More on Variables, Facts and Precedence