fact
A variable Ansible discovers about a host itself, such as its operating system, host name, memory or network addresses.
In more detail
Facts are collected by the setup module, usually automatically at the start of a play, and live under the ansible_facts variable, for example ansible_facts.os_family. Each host gets values describing itself, which lets one play adapt to different kinds of target. A fact can be missing or differ between operating systems, so test the values you depend on.
Example
{{ ansible_facts.hostname }}Related terms
- fact gathering — The automatic first step of a play that runs the setup module on every host to collect its facts.
- setup module — The module that collects facts about a host, such as its operating system, memory and network addresses.
- OS family — A fact that groups operating systems by their lineage, such as Debian for Debian and Ubuntu, or RedHat for Red Hat Enterprise Linux and Fedora.
- fact caching — Storing gathered facts between runs, so later plays can reuse them instead of collecting them again from every host.
- Ansible variable — A named value, such as http_port or site_name, that tasks and templates refer to instead of writing the value in directly.
Taught in
- Installing Ansible — Ansible Configuration Management at Scale
- Your First Ad Hoc Command — Ansible Configuration Management at Scale
- The Static Inventory File — Ansible Configuration Management at Scale
- Host Groups And Host Variables — Ansible Configuration Management at Scale
- Playbook Syntax And YAML — Ansible Configuration Management at Scale
- Writing Your First Playbook — Ansible Configuration Management at Scale
- Variables And Precedence — Ansible Configuration Management at Scale
- Gathering Facts — Ansible Configuration Management at Scale
- Conditionals — Ansible Configuration Management at Scale
- Error Handling With Block, Rescue And Always — Ansible Configuration Management at Scale
- Performance, Forks And Best Practices — Ansible Configuration Management at Scale
- SSH Keys And An Account For Ansible — RHCE in Ansible (EX294): Automate Red Hat Systems
- Privilege Escalation: sudo Rules And become — RHCE in Ansible (EX294): Automate Red Hat Systems
- Anatomy Of A Playbook: Plays, Tasks And Modules — RHCE in Ansible (EX294): Automate Red Hat Systems
- Variables And Where They Win: group_vars, host_vars And Play Vars — RHCE in Ansible (EX294): Automate Red Hat Systems
- Facts And Magic Variables: Let Each Node Describe Itself — RHCE in Ansible (EX294): Automate Red Hat Systems
- Loops: One Task, Many Items — RHCE in Ansible (EX294): Automate Red Hat Systems
- Conditionals: register, when, changed_when And failed_when — RHCE in Ansible (EX294): Automate Red Hat Systems
- RHEL System Roles: timesync And selinux From A Collection — RHCE in Ansible (EX294): Automate Red Hat Systems
- Packages And Repositories: yum_repository And dnf — RHCE in Ansible (EX294): Automate Red Hat Systems
- Storage: Partitions, Volume Groups And Volumes Where The Disk Exists — RHCE in Ansible (EX294): Automate Red Hat Systems
- Jinja Templates: One File, A Different Text Per Host — RHCE in Ansible (EX294): Automate Red Hat Systems
- Drill: Storage Only Where The Disk Exists — RHCE in Ansible (EX294): Automate Red Hat Systems