Ansible Facts and Gathering Overhead
Facts are what a managed node knows about itself, and Ansible collects them before every play unless told not to. That is a real cost, measured here at more than three times the runtime of a play that skips it. This covers what a fact is, the handful you will use, what turning gathering off breaks, and how to publish your own facts from a file on the host.
Plays and Playbooks Guide 12 of 45 Intermediate
- OSUbuntu 26.04 LTS
- ansible-core2.20.1
- Python3.14.4
- TimeAbout 15 min
- Reviewed23 August 2026
Written against the versions above. Facts are being renamed. Running a play that uses `ansible_hostname` now prints a deprecation warning: top-level fact injection is going away in ansible-core 2.24, and the supported form is `ansible_facts['hostname']` - the same value without the `ansible_` prefix, inside the `ansible_facts` dictionary. New playbooks should use the dictionary form.
| Server Name | IP Address | OS | Roles | CPU | RAM | HDD |
|---|---|---|---|---|---|---|
| ANS-CTL01 | 192.168.0.36 | Ubuntu 26.04 LTS | Ansible Control Node | 2 Core | 3 GB | 50 GB |
| ANS-A01 | 192.168.0.37 | Ubuntu 26.04 LTS | Managed Node (group: web) | 2 Core | 3 GB | 50 GB |
| ANS-B01 | 192.168.0.38 | Ubuntu 26.04 LTS | Managed Node (group: db) | 2 Core | 3 GB | 50 GB |
Before you start
- A control node configured as shown in the first step.
- The session writes a custom fact to
/etc/ansible/facts.d/on thewebhost and removes it at the end.
-
The configuration this guide assumes
-
What a fact is
-
The ones you will actually use
-
What gathering costs
-
Without facts, the variables are gone
-
Your own facts