Pcornel
Automation · Ansible

Facts

Cheat sheet · https://pcornel.dk/topic.php?topic=5404

Back to the Topic

Answer

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.

Remember

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

First checks

  • ansible <h> -m setup — all facts
  • ansible <h> -m setup -a 'filter=ansible_default_ipv4' — filtered
  • Fact caching (jsonfile/redis) — performance

Verify in this order

setup module → facts → variables

Where it usually breaks

A fact proves what its collection path reported for a host at a point in time; it does not guarantee freshness or complete target truth.

Inventory/vars → play/task selection → connection/become → module request → module result → target object read-back → handler/service effective state → workload verification.

Facts Ansible boundary map

BoundaryHealthy evidenceSuspicious evidence
Inputs / selectionCorrect inventory, hosts, variables/facts and content are explicitWrong scope, stale facts, hidden precedence or content-version drift
ExecutionConnection, privilege, module/task context and ordering match intentUnreachable, wrong execution host, privilege/plugin failure or misleading skip/change state
Result semanticsPer-host/item results are preserved and interpreted correctlyAggregate recap hides partial/skipped/handled failures
Target proofResource/workload read-back and rerun confirm convergenceGreen Ansible status treated as end-to-end acceptance

Read-only verification commands unless stated otherwise. Confirm syntax for your platform and release. Full reference: https://pcornel.dk/topic.php?topic=5404

Confirmation

Confirm action

Continue?