Organize Hosts and Group Variables

Organize hosts and group variables to keep inventories clean and manageable.

Storing variables in the inventory works well when it is small. However, as more hosts and variables are added, it quickly becomes cluttered. Storing host and group variables in separate files helps you to keep the inventory clean and organize the variables.

Ansible allows you to define your variables in separate files. It searches for these files under a directory called group_vars relative to the inventory or playbook file. Within the group_vars directory, you place files with names that correlate to the group names or hostnames listed in the inventory.

Host and group variable files must use YAML syntax. A file extension for these files is optional, but valid file extensions include .yml, .yaml, and .json.

Group variables files

We have created a group_vars directory and variable files for the linux and windows groups.

We have performed the following steps:

  1. Created the group_vars directory.

Get hands-on with 1200+ tech skills courses.