ansible.builtin.yaml inventory – Uses a specific YAML file as an inventory source.
Note
This inventory plugin is part of ansible-core
and included in all Ansible
installations. In most cases, you can use the short
plugin name
yaml
.
However, we recommend you use the Fully Qualified Collection Name (FQCN) ansible.builtin.yaml
for easy linking to the
plugin documentation and to avoid conflicting with other collections that may have
the same inventory plugin name.
Synopsis
YAML-based inventory, should start with the
all
group and contain hosts/vars/children entries.Host entries can have sub-entries defined, which will be treated as variables.
Vars entries are normal group vars.
Children are ‘child groups’, which can also have their own vars/hosts/children and so on.
File MUST have a valid extension, defined in configuration.
Parameters
Parameter |
Comments |
---|---|
list of ‘valid’ extensions for files containing YAML Default: Configuration:
|
Notes
Note
If you want to set vars for the
all
group inside the inventory file, theall
group must be the first entry in the file.Enabled in configuration by default.
Examples
all: # keys must be unique, i.e. only one 'hosts' per group
hosts:
test1:
test2:
host_var: value
vars:
group_all_var: value
children: # key order does not matter, indentation does
other_group:
children:
group_x:
hosts:
test5 # Note that one machine will work without a colon
#group_x:
# hosts:
# test5 # But this won't
# test7 #
group_y:
hosts:
test6: # So always use a colon
vars:
g2_var2: value3
hosts:
test4:
ansible_host: 127.0.0.1
last_group:
hosts:
test1 # same host as above, additional group membership
vars:
group_last_var: value
Hint
Configuration entries for each entry type have a low to high priority order. For example, a variable that is lower in the list will override a variable that is higher up.