LOGBOOK

HELP

Quiz Entry - updated: 2026.11.05

How do you use a fact in a task, and what does Ansible do with it at run time?

Reference it like any variable, {{ ansible_facts['default_ipv4']['address'] }}; Ansible substitutes each host's own value when the task runs. The same task therefore produces a different, correct result on every host.

- name: Debug and print IPv4 address
  hosts: all
  tasks:
    - name: Prints various Ansible facts
      ansible.builtin.debug:
        msg: >
          The default IPv4 address of {{ ansible_facts.fqdn }}
          is {{ ansible_facts.default_ipv4.address }}

Output for one host:

TASK [Prints various Ansible facts]
ok: [demo1.example.com] => {
    "msg": "The default IPv4 address of demo1.example.com is 10.176.118.15\n"
}

That is the whole idea behind facts: one playbook, no per-host values written by hand, and each host describes itself. The same works in file content, templates and conditions (when: ansible_facts['distribution'] == 'Debian'), and facts can even be used to build groups of hosts dynamically, such as "all hosts running Debian 12".

Go deeper:

From Quiz: ITIA / Ansible Variables, Secrets and Facts | Updated: Nov 05, 2026