Use it when configuring, checking or troubleshooting Facts in Ansible.
Facts
Ansible facts are discovered or supplied host data used by automation logic; gathered facts represent observations at a point in time and may be disabled, cached, stale or extended by custom facts.
1. Facts are gathered system information.
2. gather_facts: false when not needed.
3. Cache facts for speed.
4. Custom facts in /etc/ansible/facts.d.
5. Use ansible_facts namespace.
setup module → facts → variables
Context & applicabilityCommon mistakes · platform/version boundaries
Operational reference
Fast context before you go deeper.
Verification & Troubleshooting
Start with the observed symptom, prove the nearest boundary, and move outward only when the current state is understood.
Use the operational verification above to establish the expected state.
Capture the concrete output, symptom, packet, log or counter before changing anything.
Step 1 Operational evidence path Verify boundary
target observation → fact plugin/gathering → cache/hostvars → conditional/template/task use → target action
Healthy evidence: fact source/time and host context are explicit, cache semantics are known and critical values are corroborated when required.
Step 2 Failure modes and next checks Narrow the fault
Suspicious evidence: stale cache, disabled gathering assumptions, custom-fact drift, cross-platform key mismatch or treating facts as timeless truth.
Step 3 Common mistakes Narrow the fault
- Gathering facts when not needed (slow).
- Stale cached facts.
Evidence · 1 on this Topic
Expected observations and documentation recipes are reference material. Record actual output, device identity, scope and time before claiming a verified result.
- Fact present ≠ fact current; cached facts can outlive target changes.
- gather_facts disabled ≠ facts unavailable necessarily; cached/custom/set facts may still exist.
- Fact value ≠ authoritative business truth; it reflects the collection method and scope.
- Same fact key across platforms ≠ identical semantics.
ansible <h> -m setup— all factsansible <h> -m setup -a 'filter=ansible_default_ipv4'— filtered- Fact caching (jsonfile/redis) — performance
ReferenceWhat it is1 section · depth on demand
Core model
Establish whether gathering occurred, which subset/plugin produced the fact, cache age/source and the exact host context before using a fact as current-state evidence.
ReferenceImportant terms & boundaries2 sections · depth on demand
What this shows and what it does not
A fact shows what its collection path reported for a host at a point in time; it does not guarantee freshness or complete target truth.
Deep hardware/OS/application telemetry remains in target domains.
In depth
Facts are information Ansible gathers about managed hosts — OS, interfaces, IP addresses, memory, software versions — and makes available as variables. For servers they come from the setup module; for network devices from platform fact modules.
- hosts: switches
gather_facts: false
tasks:
- cisco.ios.ios_facts:
gather_subset: [min]
gather_network_resources: [vlans, interfaces]
- debug:
msg: "{{ ansible_net_hostname }} runs {{ ansible_net_version }}"
ansible web01 -m ansible.builtin.setup -a 'filter=ansible_default_ipv4'
Gathering facts takes time; disable it where not needed and gather only the subsets you use. Fact caching (fact_caching = jsonfile or redis) speeds up repeated runs.
Additional reference context Scope · expected state · examples · history · terminology Open only when you need the supporting context
Verification history & basis
When and against what this Topic was checked. Later text edits do not count as a new check.
Authoritative/upstream documentation reviewed for bounded claims in Ansible > Facts. Documentation verification only; this is not observed lab or production Evidence.
Basis: https://docs.ansible.com/ansible/latest/ · confidence 94%Terms & aliases
Hover a linked term for a quick definition; click it to open its glossary entry. Aliases are other names that find this Topic in search.
Quick lookup tables
Facts Ansible boundary map
Fast input/selection, execution/result and target-proof boundaries for Facts.
| Boundary | Healthy evidence | Suspicious evidence |
|---|---|---|
| Inputs / selection | Correct inventory, hosts, variables/facts and content are explicit | Wrong scope, stale facts, hidden precedence or content-version drift |
| Execution | Connection, privilege, module/task context and ordering match intent | Unreachable, wrong execution host, privilege/plugin failure or misleading skip/change state |
| Result semantics | Per-host/item results are preserved and interpreted correctly | Aggregate recap hides partial/skipped/handled failures |
| Target proof | Resource/workload read-back and rerun confirm convergence | Green Ansible status treated as end-to-end acceptance |