hostvars
The variables Ansible holds for each host; in a dynamic inventory's JSON they are supplied under _meta.hostvars.
In more detail
Including _meta in the output of an inventory script lets one call answer everything, instead of Ansible calling the script once per host with --host. In playbooks the special variable hostvars lets a task read another host's variables.
Related terms
- inventory script — An executable program that prints the inventory as JSON when Ansible runs it with --list, and one host's variables with --host.
- dynamic inventory — An inventory produced at run time by a program or plugin, usually by asking a cloud provider, instead of a file maintained by hand.
- 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
- Dynamic Inventory — Ansible Configuration Management at Scale
- Facts And Magic Variables: Let Each Node Describe Itself — RHCE in Ansible (EX294): Automate Red Hat Systems
- Conditionals: register, when, changed_when And failed_when — 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
- Mock Exam, Part 1: Seven Tasks Across Three Sections — RHCE in Ansible (EX294): Automate Red Hat Systems