o nnhQ@sddlmZdZdZdZddlZddlZddlmZddl m Z ddl m Z Gd d d e ZGd d d eZGd ddeZGdddeZGdddeZGdddeZGdddeZGdddeZGdddeZGdddeZGdddeZdd Zed!kredSdS)") annotationsa --- 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 force: description: - Whether to delete a group even if it is the primary group of a user. - Only applicable on platforms which implement a --force flag on the group deletion command. type: bool default: false version_added: "2.15" system: description: - If V(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 O(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 O(state) is C(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 O(state) is C(present) type: bool sample: False N)to_bytes) AnsibleModule)get_platform_subclasscsleZdZdZdZdZdZfddZddZd d Z d d Z d dZ ddZ ddZ ddZddZZS)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/groupcstt}t|||SN)rrsuper__new__)clsargskwargsnew_cls __class__@/usr/local/lib/python3.10/dist-packages/ansible/modules/group.pyr sz Group.__new__cCs^||_|jd|_|jd|_|jd|_|jd|_|jd|_|jd|_|jd|_dS)Nstatenameforcegidsystemlocal non_unique) moduleparamsrrrrrrr)selfrrrr__init__s      zGroup.__init__cCs |j|Sr )r run_commandrcmdrrrexecute_commands zGroup.execute_commandcCs.|jrd}nd}|j|d|jg}||S)N lgroupdelgroupdelT)rr get_bin_pathrr"r command_namer!rrr group_dels  zGroup.group_delcCsN|jr#tD]}|j|jkr"|j|jkr"|jjd|j|jdqdSdS)Nz)GID '{0}' already exists with group '{1}'msg) rgrpgetgrallgr_gidrgr_namer fail_jsonformat)rgrrrr_local_check_gid_existss zGroup._local_check_gid_existscKs|jr d}|nd}|j|dg}|D]2}|dkr9||dur9|d|t|||jr8|dq|dkrH||durH|dq||j||S) N lgroupaddgroupaddTr-g-orz-r) rr2rr%appendstrrrr")rrr'r!keyrrr group_adds"      zGroup.group_addcKs|jr d}|nd}|j|dg}|}|D],}|dkrF||durF|dt||krF|d|t|||jrF|dqt |dkrOd S|jj rUd S||j | |S) N lgroupmodgroupmodTrr5r6Nr@rr@r@) rr2rr% group_infointr7r8rlen check_moderr")rrr'r!infor9rrr group_mods(       zGroup.group_modcCs|jrWtj|js|jjd|jdd}d|j}t |jd*}| ddd}|D] }| t |rdS||j| |S) NchgroupTrr=rir>r?rA) rr%rBrCr7r8rDrErr")rrr!rFr9rrrrGIs    z AIX.group_mod rYrZr[r\r]r^rMr(r:rGrrrrrc-  rcc@4eZdZdZdZdZdZddZddZd 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() FreeBSDNrcCs |jddd|jg}||S)NpwTr$rfr rrrr(hs zFreeBsdGroup.group_delcKsT|jddd|jg}|jdur%|d|t|j|jr%|d||S)NrpTr4r5r6)rr%rrr7r8rr"rrr!rrrr:ls    zFreeBsdGroup.group_addcKs|jddd|jg}|}t|}|jdur6t|j|dkr6|d|t|j|j r6|d|t|krG|jj rBdS| |SdS) NrpTr<r=r5r6rAr?) rr%rrBrDrrCr7r8rrEr")rrr!rFcmd_lenrrrrGus    zFreeBsdGroup.group_modrkrrrrrnZs  rnc@eZdZdZdZdS)DragonFlyBsdGroupzq This is a DragonFlyBSD Group manipulation class. It inherits all behaviors from FreeBsdGroup class. DragonFlyN)rYrZr[r\r]rrrrrtsrtc@s:eZdZdZdZdZddZddZd dd 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). DarwinNcKs|jddg}|ddg7}|jdur|dt|jg7}n d|vr=|ddur=|}|dur=t||_|dt|jg7}|d|jg7}||\}}}|||fS) N dseditgroupTr6create-irF-L)rr%rr8get_lowest_available_system_gidrr")rrr!rrcouterrrrrr:s    zDarwinGroup.group_addcCsD|jddg}|ddg7}|d|jg7}||\}}}|||fS)NrxTr6deleter{rf)rr!r}r~rrrrr(s   zDarwinGroup.group_delcCs|}|jdur@t|j|dkr@|jddg}|ddg7}|dur,|dt|g7}|d|jg7}||\}}}|||fSdS) Nr=rxTr6editrzr{r?)rBrrCrr%r8rr")rrrFr!r}r~rrrrrGs  zDarwinGroup.group_modc CszL|jddg}|gd7}||\}}}|}d}|D]}|d}t|dkrrIiiF)rr%r" splitlinessplitrDrC Exception) rr!r}r~rlineshighestrBpartsrrrrr|s&      z+DarwinGroup.get_lowest_available_system_gidr ) rYrZr[r\r]r^r:r(rGr|rrrrrvs   rvc@rm) OpenBsdGroupz This is a OpenBSD Group manipulation class. This overrides the following methods from the generic class:- - group_del() - group_add() - group_mod() OpenBSDNrcCrdNr$Trfr rrrr(rgzOpenBsdGroup.group_delcKZ|jddg}|jdur"|d|t|j|jr"|d||j||SNr4Tr5r6rr%rr7r8rrr"rqrrrr:     zOpenBsdGroup.group_addcK|jddg}|}|jdur/t|j|dkr/|d|t|j|jr/|dt|dkr7dS|jj r=dS||j | |S Nr<Tr=r5r6r>r?rA rr%rBrrCr7r8rrDrErr"rrr!rFrrrrG     zOpenBsdGroup.group_modrkrrrrrrlrc@rm) NetBsdGroupz This is a NetBSD Group manipulation class. This overrides the following methods from the generic class:- - group_del() - group_add() - group_mod() NetBSDNrcCrdrrfr rrrr(rgzNetBsdGroup.group_delcKrrrrqrrrr:rzNetBsdGroup.group_addcKrrrrrrrrG rzNetBsdGroup.group_modrkrrrrrrlrc@s(eZdZdZddZddZddZdS) BusyBoxGroupz BusyBox group manipulation class for systems that have addgroup and delgroup. It overrides the following methods: - group_add() - group_del() - group_mod() cKsT|jddg}|jdur|dt|jg|jr|d||j||S)NaddgroupTr5z-S) rr%rextendr8rr7rr"rqrrrr:=s    zBusyBoxGroup.group_addcCrd)NdelgroupTrfr rrrr(IrgzBusyBoxGroup.group_delc Ks|}|jdury|j|dkrytdd }|}Wdn1s$wYt|j}d||df}d||jf}d|j|vrP|jjdj|jdd|jj rVd S| ||}tdd }| |Wdd S1srwYd Sd S) Nr=rrHs%s:x:%d:s:%d:zgid '{gid}' in userr)rAwbr?) rBrrNreadrrrr/r0rEreplacewrite) rrrFrTb_groupsb_nameb_current_group_stringb_new_group_string b_new_groupsrrrrGMs(       zBusyBoxGroup.group_modN)rYrZr[r\r:r(rGrrrrr3s   rc@rs) AlpineGroupr`AlpineN)rYrZr[r]r^rrrrresrc Cstttddddgdtdddtddd td d tddd tddd tddd d dd ddgggd}|jdrC|jdrC|jddt|}|d|j|jrZ|d|jd}d}d}i}|j|d<|j |d<|j dkr| r|j r~|j dd| \}}}|dkr|j|j|dn9|j dkr| s|j r|j dd|j|j|jd\}}}n |j|jd\}}}|dur|dkr|j|j|d|durd|d<nd|d<|r||d<|r||d <| r|}|j|d!<|d"|d<|j d#i|dS)$Nr8presentabsent)typedefaultchoicesT)rrequiredboolF)rrrC)r)rrrrrrrrr) argument_specsupports_check_mode required_ifrrzWforce is not a valid option for local, force=True and local=True are mutually exclusiver)z Group instantiated - platform %sz$Group instantiated - distribution %sr@rr)changedr)rr*)rrrrstdoutstderrrr=r)rdictrr/rdebugr]r^rrrWrE exit_jsonr(r:rrrGrB)rgroupr}r~rresultrFrrrmainksl                r__main__) __future__r DOCUMENTATIONEXAMPLESRETURNr+rJ+ansible.module_utils.common.text.convertersransible.module_utils.basicr$ansible.module_utils.common.sys_inforobjectrr`rarcrnrtrvrrrrrrYrrrrs0 G    }-, E./2G