관리-도구
편집 파일: 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&���� zGroup.group_modc�����������������C���s����|�j�r�tj�|�j�s*|�jjd�|�j�d��d}d�|�j�}t |�jd��B}|� ��d�d�d��}|D�]}|�t|��r^d}�qzq^W�d�����n1�s�0����Y��|s�|�j� dj|�jd ���|S�zt�|�j�r�W�dS�W�n�ty����Y�dS�0�d�S�) NzI'local: true' specified but unable to find local group file {0} to parse.r&���Fz{0}:�rb���Tz�'local: true' specified and group was not found in {file}. The local group may already exist if the local group database exists somewhere other than {file}.)�file)r����os�path�exists� GROUPFILEr���r,���r-���r����open� readlines� startswithr����warnr(����getgrnam�KeyError)r���rG���Z name_test�fZreversed_lines�liner���r���r����group_exists����s.����$�� zGroup.group_existsc�����������������C���s:���|�����sdS�ztt�|�j��}W�n�ty4���Y�dS�0�|S�)NF)rQ����listr(���rM���r���rN���)r���r@���r���r���r���r<�������s����zGroup.group_info)�__name__� __module__�__qualname__�__doc__�platform�distributionrH���r ���r���r!���r%���r.���r5���rA���rQ���r<���� __classcell__r���r���r���r���r���v���s��� r���c�������������������@���s$���e�Zd�ZdZd�ZdZdZdd��ZdS�)�SunOSz� This is a SunOS Group manipulation class. Solaris doesn't have the 'system' group concept. This overrides the following methods from the generic class:- - group_add() Nr ���c�����������������K���sp���|�j��dd�g}|D�]D}|dkr||�d�ur|�d��|�t||����|�jr|�d��q|�|�j��|��|�S�)Nr/���Tr���r0���r1���)r���r#���r2���r3���r���r���r!����r���r���r ���r4���r���r���r���r5�����s���� zSunOS.group_add)rS���rT���rU���rV���rW���rX���rH���r5���r���r���r���r���rZ�������s ���rZ���c�������������������@���s4���e�Zd�ZdZd�ZdZdZdd��Zdd��Zdd ��Z dS�) �AIXz� This is a AIX Group manipulation class. This overrides the following methods from the generic class:- - group_del() - group_add() - group_mod() Nr ���c�����������������C���s���|�j��dd�|�jg}|��|�S�)NZrmgroupT�r���r#���r���r!���r���r���r���r���r%���"��s����z AIX.group_delc�����������������K���sz���|�j��dd�g}|D�]N}|dkrD||�d�urD|�dt||�����q|dkr||�du�r|�d��q|�|�j��|��|�S�)NZmkgroupTr����id=r���z-a)r���r#���r2���r3���r���r!���r[���r���r���r���r5���&��s����z AIX.group_addc�����������������K���s����|�j��dd�g}|����}|D�]B}|dkr||�d�ur|d�t||��kr|�dt||�����qt|�dkrpdS�|�j�jr|dS�|�|�j��|�� |�S�) NZchgroupTr���r7���r^���r8���r9���r;���) r���r#���r<���r=���r2���r3���r>���r?���r���r!���)r���r���r ���r@���r4���r���r���r���rA���0��s���� z AIX.group_mod� rS���rT���rU���rV���rW���rX���rH���r%���r5���rA���r���r���r���r���r\�����s��� r\���c�������������������@���s4���e�Zd�ZdZdZdZdZdd��Zdd��Zd d ��Z dS�)�FreeBsdGroupz� This is a FreeBSD Group manipulation class. This overrides the following methods from the generic class:- - group_del() - group_add() - group_mod() ZFreeBSDNr ���c�����������������C���s ���|�j��dd�d|�jg}|��|�S�)N�pwTr"���r]���r���r���r���r���r%���O��s����zFreeBsdGroup.group_delc�����������������K���sT���|�j��dd�d|�jg}|�jd�urJ|�d��|�t|�j���|�jrJ|�d��|��|�S�)Nra���Tr/���r0���r1���)r���r#���r���r���r2���r3���r���r!����r���r���r ���r���r���r���r5���S��s���� zFreeBsdGroup.group_addc�����������������K���s����|�j��dd�d|�jg}|����}t|�}|�jd�urlt|�j�|d�krl|�d��|�t|�j���|�j rl|�d��|t|�kr�|�j�j r�dS�|��|�S�dS�) Nra���Tr6���r7���r0���r1���r;���r9���)r���r#���r���r<���r>���r���r=���r2���r3���r���r?���r!���)r���r���r ���r@���Zcmd_lenr���r���r���rA���\��s���� zFreeBsdGroup.group_modr_���r���r���r���r���r`���A��s��� r`���c�������������������@���s���e�Zd�ZdZdZdS�)�DragonFlyBsdGroupzq This is a DragonFlyBSD Group manipulation class. It inherits all behaviors from FreeBsdGroup class. Z DragonFlyN)rS���rT���rU���rV���rW���r���r���r���r���rc���m��s���rc���c�������������������@���s:���e�Zd�ZdZdZdZdd��Zdd��Zddd �Zd d��Z dS�) �DarwinGroupz� This is a Mac macOS Darwin Group manipulation class. This overrides the following methods from the generic class:- - group_del() - group_add() - group_mod() group manipulation are done using dseditgroup(1). ZDarwinNc�����������������K���s����|�j��dd�g}|ddg7�}|�jd�ur:|dt|�j�g7�}n@d|v�rz|d�du�rz|����}|durzt|�|�_|dt|�j�g7�}|d|�jg7�}|��|�\}}}|||fS�) N�dseditgroupTr1���Zcreate�-ir���F�-L)r���r#���r���r3����get_lowest_available_system_gidr���r!���)r���r���r ���r����rc�out�errr���r���r���r5������s���� zDarwinGroup.group_addc�����������������C���sD���|�j��dd�g}|ddg7�}|d|�jg7�}|��|�\}}}|||fS�)Nre���Tr1����deleterg���r]���)r���r ���ri���rj���rk���r���r���r���r%������s ����zDarwinGroup.group_delc�����������������C���s����|�����}|�jd�ur�t|�j�|d�kr�|�j�dd�g}|ddg7�}|d�urX|dt|�g7�}|d|�jg7�}|��|�\}}}|||fS�dS�) Nr7���re���Tr1���Zeditrf���rg���r9���)r<���r���r=���r���r#���r3���r���r!���)r���r���r@���r ���ri���rj���rk���r���r���r���rA������s���� zDarwinGroup.group_modc����������� ������C���s����z�|�j��dd�g}|g�d�7�}|��|�\}}}|���}d}|D�]:}|�d�}t|�dkr>t|d��} | |kr>| dk�r>| }q>|dks�|d kr�W�d S�|d�W�S��ty����Y�d S�0�d�S�)NZdsclT)z/Local/Defaultz-listz/GroupsZPrimaryGroupIDr���� r8���rC���i���i���F)r���r#���r!���� splitlines�splitr>���r=���� Exception) r���r ���ri���rj���rk����linesZhighestr<����partsr���r���r���r���rh������s"���� z+DarwinGroup.get_lowest_available_system_gid)N) rS���rT���rU���rV���rW���rX���r5���r%���rA���rh���r���r���r���r���rd���x��s��� rd���c�������������������@���s4���e�Zd�ZdZdZdZdZdd��Zdd��Zd d ��Z dS�)�OpenBsdGroupz� This is a OpenBSD Group manipulation class. This overrides the following methods from the generic class:- - group_del() - group_add() - group_mod() ZOpenBSDNr ���c�����������������C���s���|�j��dd�|�jg}|��|�S��Nr"���Tr]���r���r���r���r���r%������s����zOpenBsdGroup.group_delc�����������������K���sZ���|�j��dd�g}|�jd�urD|�d��|�t|�j���|�jrD|�d��|�|�j��|��|�S��Nr/���Tr0���r1����r���r#���r���r2���r3���r���r���r!���rb���r���r���r���r5������s���� zOpenBsdGroup.group_addc�����������������K���s����|�j��dd�g}|����}|�jd�ur^t|�j�|d�kr^|�d��|�t|�j���|�jr^|�d��t|�dkrndS�|�j�j rzdS�|�|�j ��|��|�S�� Nr6���Tr7���r0���r1���r8���r9���r;����r���r#���r<���r���r=���r2���r3���r���r>���r?���r���r!����r���r���r ���r@���r���r���r���rA������s���� zOpenBsdGroup.group_modr_���r���r���r���r���rs������s��� rs���c�������������������@���s4���e�Zd�ZdZdZdZdZdd��Zdd��Zd d ��Z dS�)�NetBsdGroupz� This is a NetBSD Group manipulation class. This overrides the following methods from the generic class:- - group_del() - group_add() - group_mod() ZNetBSDNr ���c�����������������C���s���|�j��dd�|�jg}|��|�S�rt���r]���r���r���r���r���r%������s����zNetBsdGroup.group_delc�����������������K���sZ���|�j��dd�g}|�jd�urD|�d��|�t|�j���|�jrD|�d��|�|�j��|��|�S�ru���rv���rb���r���r���r���r5������s���� zNetBsdGroup.group_addc�����������������K���s����|�j��dd�g}|����}|�jd�ur^t|�j�|d�kr^|�d��|�t|�j���|�jr^|�d��t|�dkrndS�|�j�j rzdS�|�|�j ��|��|�S�rw���rx���ry���r���r���r���rA�����s���� zNetBsdGroup.group_modr_���r���r���r���r���rz������s��� rz���c�������������������@���s(���e�Zd�ZdZdd��Zdd��Zdd��ZdS�) �BusyBoxGroupz� BusyBox group manipulation class for systems that have addgroup and delgroup. It overrides the following methods: - group_add() - group_del() - group_mod() c�����������������K���sT���|�j��dd�g}|�jd�ur.|�dt|�j�g��|�jr>|�d��|�|�j��|��|�S�)N�addgroupTr0���z-S) r���r#���r����extendr3���r���r2���r���r!���rb���r���r���r���r5���$��s���� zBusyBoxGroup.group_addc�����������������C���s���|�j��dd�|�jg}|��|�S�)NZdelgroupTr]���r���r���r���r���r%���0��s����zBusyBoxGroup.group_delc����������� ������K���s����|�����}|�jd�ur�|�j|d�kr�tdd��}|���}W�d�����n1�sH0����Y��t|�j�}d||d�f�}d||�jf�}d|�j�|v�r�|�jjdj|�jd�d��|�jj r�d S�|� ||�}tdd ��}|�|��W�d�����n1�s�0����Y��d S�dS�)Nr7���r ���rB���s���%s:x:%d:s���:%d:zgid '{gid}' in use�r���r&���r;����wbr9���)r<���r���rI����readr���r���r���r,���r-���r?����replace�write) r���r���r@���rO���Zb_groupsZb_nameZb_current_group_stringZb_new_group_stringZb_new_groupsr���r���r���rA���4��s ����& (zBusyBoxGroup.group_modN)rS���rT���rU���rV���r5���r%���rA���r���r���r���r���r{�����s��� r{���c�������������������@���s���e�Zd�ZdZdZdS�)�AlpineGroupZLinuxZAlpineN)rS���rT���rU���rW���rX���r���r���r���r���r����L��s���r����c������������������C���s���t�ttddddgd�tddd�tdd�td d d�td d d�td d d�d�dd ddgggd�}�t|��}|��d|j���|jr�|��d|j���d�}d}d}i�}|j|d<�|j|d<�|jdkr�|���r�|�j r�|�j dd��|���\}}}|dkr�|�j|j|d��n||jdk�rv|����s>|�j �r$|�j dd��|j |j|jd�\}}}n|j|jd�\}}}|d�u�rv|dk�rv|�j|j|d��|d�u��r�d |d<�nd|d<�|�r�||d<�|�r�||d<�|����r�|���}|j|d<�|d�|d<�|�j f�i�|���d�S�)Nr3���ZpresentZabsent)�type�default�choicesT)r�����requiredr=���)r�����boolF)r����r����)r���r���r���r���r���r���r���r���)Z argument_specZsupports_check_modeZrequired_ifz Group instantiated - platform %sz$Group instantiated - distribution %sr:���r���r���)�changedr���)r���r'���)r���r���r~���r�����stdout�stderrr���r7���)r����dictr����debugrW���rX���r���r���rQ���r?���Z exit_jsonr%���r,���r5���r���r���rA���r<���)r����groupri���rj���rk����resultr@���r���r���r����mainR��sd���� � �� r�����__main__)Z __future__r���r���r���r����Z __metaclass__Z DOCUMENTATIONZEXAMPLESZRETURNr(���rE���Zansible.module_utils._textr���Zansible.module_utils.basicr���Z$ansible.module_utils.common.sys_infor����objectr���rZ���r\���r`���rc���rd���rs���rz���r{���r����r����rS���r���r���r���r����<module>���s.���@ �-,E./2C