File: //proc/self/root/lib/python3.9/site-packages/ansible/modules/__pycache__/group.cpython-39.pyc
a
�)gHN � @ s d dl mZmZmZ eZdZdZdZd dl Z d dl
Z
d dlmZ d dl
mZ d dlmZ G d d
� d
e�ZG dd� de�ZG d
d� de�ZG dd� de�ZG dd� de�ZG dd� de�ZG dd� de�ZG dd� de�ZG dd� de�ZG dd� de�Zdd� Zedk�re� dS ) � )�absolute_import�division�print_functionab
---
module: group
version_added: "0.0.2"
short_description: Add or remove groups
requirements:
- groupadd
- groupdel
- groupmod
description:
- Manage presence of groups on a host.
- For Windows targets, use the M(ansible.windows.win_group) module instead.
options:
name:
description:
- Name of the group to manage.
type: str
required: true
gid:
description:
- Optional I(GID) to set for the group.
type: int
state:
description:
- Whether the group should be present or not on the remote host.
type: str
choices: [ absent, present ]
default: present
system:
description:
- If I(yes), indicates that the group created is a system group.
type: bool
default: no
local:
description:
- Forces the use of "local" command alternatives on platforms that implement it.
- This is useful in environments that use centralized authentication when you want to manipulate the local groups.
(for example, it uses C(lgroupadd) instead of C(groupadd)).
- This requires that these commands exist on the targeted host, otherwise it will be a fatal error.
type: bool
default: no
version_added: "2.6"
non_unique:
description:
- This option allows to change the group ID to a non-unique value. Requires C(gid).
- Not supported on macOS or BusyBox distributions.
type: bool
default: no
version_added: "2.8"
extends_documentation_fragment: action_common_attributes
attributes:
check_mode:
support: full
diff_mode:
support: none
platform:
platforms: posix
seealso:
- module: ansible.builtin.user
- module: ansible.windows.win_group
author:
- Stephen Fromm (@sfromm)
z�
- name: Ensure group "somegroup" exists
ansible.builtin.group:
name: somegroup
state: present
- name: Ensure group "docker" exists with correct gid
ansible.builtin.group:
name: docker
state: present
gid: 1750
a�
gid:
description: Group ID of the group.
returned: When C(state) is 'present'
type: int
sample: 1001
name:
description: Group name.
returned: always
type: str
sample: users
state:
description: Whether the group is present or not.
returned: always
type: str
sample: 'absent'
system:
description: Whether the group is a system group or not.
returned: When C(state) is 'present'
type: bool
sample: False
N)�to_bytes)�
AnsibleModule)�get_platform_subclassc sl e Zd ZdZdZdZdZ� fdd�Zdd� Zd d
� Z dd� Z
d
d� Zdd� Zdd� Z
dd� Zdd� Z� ZS )�Groupa-
This is a generic Group manipulation class that is subclassed
based on platform.
A subclass may wish to override the following action methods:-
- group_del()
- group_add()
- group_mod()
All subclasses MUST define platform and distribution (which may be None).
�GenericN�
/etc/groupc s t t�}t| |��|�S �N)r r �super�__new__)�cls�args�kwargsZnew_cls�� __class__� �9/usr/lib/python3.9/site-packages/ansible/modules/group.pyr
� s z
Group.__new__c C sR || _ |jd | _|jd | _|jd | _|jd | _|jd | _|jd | _d S )N�state�name�gid�system�local�
non_unique)�module�paramsr r r r r r )�selfr r r r �__init__� s zGroup.__init__c C s | j �|�S r )r Zrun_command�r �cmdr r r �execute_command� s zGroup.execute_commandc C s. | j rd}nd}| j�|d�| jg}| �|�S )NZ lgroupdel�groupdelT)r r �get_bin_pathr r! )r �command_namer r r r � group_del� s
zGroup.group_delc C sJ | j rFt�� D ]6}| j |jkr| j|jkr| jjd�| j |j�d� qd S )Nz)GID '{0}' already exists with group '{1}'��msg) r �grp�getgrall�gr_gidr �gr_namer � fail_json�format)r Zgrr r r �_local_check_gid_exists� s zGroup._local_check_gid_existsc K s� | j rd}| �� nd}| j�|d�g}|D ]d}|dkrr|| d urr|�d� |�t|| �� | jr�|�d� q,|dkr,|| du r,|�d� q,|�| j� | �|�S ) NZ lgroupadd�groupaddTr �-g�-or z-r) r r. r r# �append�strr r r! )r r r$ r �keyr r r � group_add� s
zGroup.group_addc K s� | j rd}| �� nd}| j�|d�g}| �� }|D ]X}|dkr4|| d ur4|d t|| �kr4|�d� |�t|| �� | jr4|�d� q4t |�dkr�d S | jj
r�d
S |�| j� | �|�S )NZ lgroupmod�groupmodTr � r0 r1 � �N� r: �r r: r: )
r r. r r# �
group_info�intr2 r3 r �len�
check_moder r! )r r r$ r �infor4 r r r � group_mod� s&