ansible.builtin.generator – Uses Jinja2 to construct hosts and groups from patterns¶
Note
This module is part of ansible-base
and included in all Ansible
installations. In most cases, you can use the short module name
generator even without specifying the collections:
keyword.
Despite that, we recommend you use the FQCN for easy linking to the module
documentation and to avoid conflicting with other collections that may have
the same module name.
New in version 2.6: of ansible.builtin
Synopsis¶
Uses a YAML configuration file with a valid YAML or
.config
extension 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¶
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: 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