ansible.builtin.generator inventory – Uses Jinja2 to construct hosts and groups from patterns
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
generator.
However, we recommend you use the Fully Qualified Collection Name (FQCN) ansible.builtin.generator for easy linking to the
plugin documentation and to avoid conflicting with other collections that may have
the same inventory plugin name.
Synopsis
Uses a YAML configuration file with a valid YAML or
.configextension to define var expressions and group conditionalsCreate a template pattern that describes each host, and then use independent configuration layers
Every element of every layer is combined to create a host for every layer combination
Parent groups can be defined with reference to hosts and other groups using the same template variables
Parameters
Parameter |
Comments |
|---|---|
The The Parents can also contain |
|
A dictionary of layers, with the key being the layer name, used as a variable name in the |
|
token that ensures this is a source file for the ‘generator’ plugin. Choices:
|
|
Merge extra vars into the available variables for composition (highest precedence). Choices:
Configuration:
|
Note
Configuration entries listed above for each entry type (Ansible variable, environment variable, and so on) 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. The entry types are also ordered by precedence from low to high priority order. For example, an ansible.cfg entry (further up in the list) is overwritten by an Ansible variable (further down in the list).
Examples
# inventory.config file in YAML format
# remember to enable this inventory plugin in the ansible.cfg before using
# View the output using `ansible-inventory -i inventory.config --list`
plugin: ansible.builtin.generator
hosts:
name: "{{ operation }}_{{ application }}_{{ environment }}_runner"
parents:
- name: "{{ operation }}_{{ application }}_{{ environment }}"
parents:
- name: "{{ operation }}_{{ application }}"
parents:
- name: "{{ operation }}"
- name: "{{ application }}"
- name: "{{ application }}_{{ environment }}"
parents:
- name: "{{ application }}"
vars:
application: "{{ application }}"
- name: "{{ environment }}"
vars:
environment: "{{ environment }}"
- name: runner
layers:
operation:
- build
- launch
environment:
- dev
- test
- prod
application:
- web
- api