What are `group_vars` and `host_vars` directories?
IntermediateConceptInventory
Answer
Directories placed next to the inventory file (or the playbook) that hold variables by group or host name, instead of cluttering the inventory.
inventory/
hosts.ini
group_vars/
all.yml
web.yml
db/
main.yml
secrets.yml # vault-encrypted
host_vars/
web1.yml
A group can use either web.yml or a web/ directory whose files are all loaded. Splitting a vaulted secrets.yml from plain main.yml keeps diffs readable.
More on Inventory
What is an inventory and why does Ansible need one?BeginnerWhat are the INI and YAML inventory formats and how do they differ?BeginnerHow do you create groups of groups?BeginnerExplain host patterns: `:`, `:&`, `:!` and wildcards.IntermediateWhich connection variables can you set per host in inventory?BeginnerHow do you define a range of hosts in an inventory?Beginner