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

Create Ansible groups based on facts

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

Authors: Jeroen Hoekx (@jhoekx)

This plugin has a corresponding action plugin.

Install Ansible via pip

Install with pip install ansible-core==2.16.5

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.
- name: Create groups based on the machine architecture
  ansible.builtin.group_by:
    key: machine_{{ ansible_machine }}
  • Success
    Steampunk Spotter scan finished with no errors, warnings or hints.
- name: Create groups like 'virt_kvm_host'
  ansible.builtin.group_by:
    key: virt_{{ ansible_virtualization_type }}_{{ ansible_virtualization_role }}
  • Success
    Steampunk Spotter scan finished with no errors, warnings or hints.
- name: Create nested groups
  ansible.builtin.group_by:
    key: el{{ ansible_distribution_major_version }}-{{ ansible_architecture }}
    parents:
      - el{{ ansible_distribution_major_version }}
  • Success
    Steampunk Spotter scan finished with no errors, warnings or hints.
- name: Add all active hosts to a static group
  ansible.builtin.group_by:
    key: done

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.
    elements: str
    type: list
    version_added: '2.4'
    version_added_collection: ansible.builtin

See also