Ansible - Child Group (Children|Group of Group)

> Infrastructure as code > Ansible

1 - About

A group of a group is called a child group.

The relation is defined through the use of the children key word.

Advertising

3 - Properties

  • Any host that is member of a child group is automatically a member of the parent group.
  • A child group’s variables will have higher precedence (override) a parent group’s variables.
  • Groups can have multiple parents and children, but not circular relationships.
  • Hosts can also be in multiple groups, but there will only be one instance of a host, merging the data from the multiple groups.

4 - Management

4.1 - Definition

Create a group of a group relation using :

  • the :children suffix in INI
  • or the children: entry in YAML

Example: The group parent1 has two children group1 and group2

  • ini
host.ini
[childgroup2]
host1
host2
 
[childgroup1]
host2
host3
 
[parent1:children]
childgroup1
childgroup2
  • yaml
inventory.yml
all:
    children:
        parent1:
            children:
                childgroup1:
                    host1:
                    host2:
                childgroup2:
                    host3:
                    host4:
Advertising

5 - Documentation / Reference