Debian Codegraph @

lib/ansible/modules/group_by.py

raw
1 # -*- mode: python -*-
2
3 # Copyright: (c) 2012, Jeroen Hoekx (@jhoekx)
4 # Copyright: Ansible Team
5 # GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
6
7 from __future__ import annotations
8
9
10 DOCUMENTATION = r"""
11 ---
12 module: group_by
13 short_description: Create Ansible groups based on facts
14 extends_documentation_fragment:
15 - action_common_attributes
16 - action_common_attributes.conn
17 - action_common_attributes.flow
18 - action_core
19 description:
20 - Use facts to create ad-hoc groups that can be used later in a playbook.
21 - This module is also supported for Windows targets.
22 version_added: "0.9"
23 options:
24 key:
25 description:
26 - The variables whose values will be used as groups.
27 type: str
28 required: true
29 parents:
30 description:
31 - The list of the parent groups.
32 type: list
33 elements: str
34 default: all
35 version_added: "2.4"
36 attributes:
37 action:
38 support: full
39 become:
40 support: none
41 bypass_host_loop:
42 support: none
43 bypass_task_loop:
44 support: none
45 check_mode:
46 details: While this makes no changes to target systems the 'in memory' inventory will still be altered
47 support: partial
48 core:
49 details: While parts of this action are implemented in core, other parts are still available as normal plugins and can be partially overridden
50 support: partial
51 connection:
52 support: none
53 delegation:
54 support: none
55 diff_mode:
56 support: none
57 platform:
58 platforms: all
59 notes:
60 - Spaces in group names are converted to dashes '-'.
61 - Though this module does not change the remote host,
62 we do provide 'changed' status as it can be useful
63 for those trying to track inventory changes.
64 seealso:
65 - module: ansible.builtin.add_host
66 author:
67 - Jeroen Hoekx (@jhoekx)
68 """
69
70 EXAMPLES = r"""
71 - name: Create groups based on the machine architecture
72 ansible.builtin.group_by:
73 key: machine_{{ ansible_machine }}
74
75 - name: Create groups like 'virt_kvm_host'
76 ansible.builtin.group_by:
77 key: virt_{{ ansible_virtualization_type }}_{{ ansible_virtualization_role }}
78
79 - name: Create nested groups
80 ansible.builtin.group_by:
81 key: el{{ ansible_distribution_major_version }}-{{ ansible_architecture }}
82 parents:
83 - el{{ ansible_distribution_major_version }}
84
85 - name: Add all active hosts to a static group
86 ansible.builtin.group_by:
87 key: done
88 """