ansible.builtin.group_by (v2.8.18) — module

Create Ansible groups based on facts

| "added in version" 0.9 of ansible.builtin"

Authors: Jeroen Hoekx (@jhoekx)

stableinterface | supported by core

Install Ansible via pip

Install with pip install ansible==2.8.18

Description

Use facts to create ad-hoc groups that can be used later in a playbook.

This module is also supported for Windows targets.

Usage examples

  • Success
    Steampunk Spotter scan finished with no errors, warnings or hints.
# Create groups based on the machine architecture
- group_by:
    key: machine_{{ ansible_machine }}
  • Success
    Steampunk Spotter scan finished with no errors, warnings or hints.
# Create groups like 'virt_kvm_host'
- group_by:
    key: virt_{{ ansible_virtualization_type }}_{{ ansible_virtualization_role }}
  • Success
    Steampunk Spotter scan finished with no errors, warnings or hints.
# Create nested groups
- group_by:
    key: el{{ ansible_distribution_major_version }}-{{ ansible_architecture }}
    parents:
      - el{{ ansible_distribution_major_version }}

Inputs

    
key:
    description:
    - The variables whose values will be used as groups.
    required: true
    type: str

parents:
    default: all
    description:
    - The list of the parent groups.
    type: list
    version_added: '2.4'
    version_added_collection: ansible.builtin

See also