a ì)gHNã@sddlmZmZmZeZdZdZdZddl Z ddl Z ddl m Z ddl mZddlmZGd d „d eƒZGd d „d eƒZGd d„deƒZGdd„deƒZGdd„deƒZGdd„deƒZGdd„deƒZGdd„deƒZGdd„deƒZGdd„deƒZdd„Zedkreƒ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_subclasscsleZdZdZdZdZdZ‡fdd„Zdd„Zd d „Z d d „Z d d„Z dd„Z dd„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/groupcsttƒ}t||ƒ |¡S©N)rrÚsuperÚ__new__)ÚclsÚargsÚkwargsZnew_cls©Ú __class__©ú9/usr/lib/python3.9/site-packages/ansible/modules/group.pyr ‡sz Group.__new__cCsR||_|jd|_|jd|_|jd|_|jd|_|jd|_|jd|_dS)NÚstateÚnameÚgidÚsystemÚlocalÚ non_unique)ÚmoduleÚparamsrrrrrr)ÚselfrrrrÚ__init__‹s     zGroup.__init__cCs |j |¡Sr )rZ run_command©rÚcmdrrrÚexecute_command”szGroup.execute_commandcCs.|jr d}nd}|j |d¡|jg}| |¡S)NZ lgroupdelÚgroupdelT)rrÚ get_bin_pathrr!)rÚ command_namer rrrÚ group_del—s zGroup.group_delcCsJ|jrFt ¡D]6}|j|jkr|j|jkr|jjd |j|j¡dqdS)Nz)GID '{0}' already exists with group '{1}'©Úmsg) rÚgrpÚgetgrallÚgr_gidrÚgr_namerÚ fail_jsonÚformat)rZgrrrrÚ_local_check_gid_existsŸs zGroup._local_check_gid_existscKs¨|jrd}| ¡nd}|j |d¡g}|D]d}|dkrr||durr| d¡| t||ƒ¡|jr| d¡q,|dkr,||dur,| d¡q,| |j¡| |¡S) NZ lgroupaddÚgroupaddTrú-gú-orz-r) rr.rr#ÚappendÚstrrrr!)rrr$r ÚkeyrrrÚ group_add¥s     zGroup.group_addcKsÀ|jrd}| ¡nd}|j |d¡g}| ¡}|D]X}|dkr4||dur4|dt||ƒkr4| d¡| t||ƒ¡|jr4| d¡q4t |ƒdkržd S|jj rªd S| |j ¡|  |¡S) NZ lgroupmodÚgroupmodTrér0r1é©NÚr:©rr:r:) rr.rr#Ú group_infoÚintr2r3rÚlenÚ check_moderr!)rrr$r Úinfor4rrrÚ group_mod·s&      zGroup.group_modcCsæ|jr¶tj |j¡s*|jjd |j¡dd}d |j¡}t |jdƒB}|  ¡ddd…}|D]}|  t |ƒ¡r^d}qzq^Wdƒn1sŽ0Y|s²|j  dj|jd ¡|Szt |j¡rÊWdSWntyàYdS0dS) 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Ú GROUPFILErr,r-rÚopenÚ readlinesÚ startswithrÚwarnr(ÚgetgrnamÚKeyError)rrGZ name_testÚfZreversed_linesÚlinerrrÚ group_existsÍs. $ÿÿ   zGroup.group_existscCs:| ¡s dSztt |j¡ƒ}Wnty4YdS0|S)NF)rQÚlistr(rMrrN)rr@rrrr<ís zGroup.group_info)Ú__name__Ú __module__Ú __qualname__Ú__doc__ÚplatformÚ distributionrHr rr!r%r.r5rArQr<Ú __classcell__rrrrrvs    rc@s$eZdZdZdZdZdZdd„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 cKsp|j dd¡g}|D]D}|dkr||dur| d¡| t||ƒ¡|jr| d¡q| |j¡| |¡S)Nr/Trr0r1)rr#r2r3rrr!©rrr r4rrrr5s   zSunOS.group_add)rSrTrUrVrWrXrHr5rrrrrZùs rZc@s4eZdZdZdZdZdZdd„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 cCs|j dd¡|jg}| |¡S)NZrmgroupT©rr#rr!rrrrr%"sz AIX.group_delcKsz|j dd¡g}|D]N}|dkrD||durD| dt||ƒ¡q|dkr||dur| d¡q| |j¡| |¡S)NZmkgroupTrúid=rz-a)rr#r2r3rr!r[rrrr5&s  z AIX.group_addcKs’|j dd¡g}| ¡}|D]B}|dkr||dur|dt||ƒkr| dt||ƒ¡qt|ƒdkrpdS|jjr|dS| |j¡|  |¡S) NZchgroupTrr7r^r8r9r;) rr#r<r=r2r3r>r?rr!)rrr r@r4rrrrA0s   z AIX.group_mod© rSrTrUrVrWrXrHr%r5rArrrrr\s  r\c@s4eZdZdZdZdZdZdd„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 cCs |j dd¡d|jg}| |¡S)NÚpwTr"r]rrrrr%OszFreeBsdGroup.group_delcKsT|j dd¡d|jg}|jdurJ| d¡| t|jƒ¡|jrJ| d¡| |¡S)NraTr/r0r1)rr#rrr2r3rr!©rrr rrrr5Ss   zFreeBsdGroup.group_addcKs’|j dd¡d|jg}| ¡}t|ƒ}|jdurlt|jƒ|dkrl| d¡| t|jƒ¡|j rl| d¡|t|ƒkrŽ|jj r„dS|  |¡SdS) NraTr6r7r0r1r;r9) rr#rr<r>rr=r2r3rr?r!)rrr r@Zcmd_lenrrrrA\s    zFreeBsdGroup.group_modr_rrrrr`As  r`c@seZdZdZdZdS)ÚDragonFlyBsdGroupzq This is a DragonFlyBSD Group manipulation class. It inherits all behaviors from FreeBsdGroup class. Z DragonFlyN)rSrTrUrVrWrrrrrcmsrcc@s:eZdZdZdZdZdd„Zdd„Zd 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). ZDarwinNcKs¢|j dd¡g}|ddg7}|jdur:|dt|jƒg7}n@d|vrz|ddurz| ¡}|durzt|ƒ|_|dt|jƒg7}|d|jg7}| |¡\}}}|||fS) NÚ dseditgroupTr1Zcreateú-irFú-L)rr#rr3Úget_lowest_available_system_gidrr!)rrr rÚrcÚoutÚerrrrrr5‡s   zDarwinGroup.group_addcCsD|j dd¡g}|ddg7}|d|jg7}| |¡\}}}|||fS)NreTr1Údeletergr])rr rirjrkrrrr%•s  zDarwinGroup.group_delcCs„| ¡}|jdur€t|jƒ|dkr€|j dd¡g}|ddg7}|durX|dt|ƒg7}|d|jg7}| |¡\}}}|||fSdS) Nr7reTr1Zeditrfrgr9)r<rr=rr#r3rr!)rrr@r rirjrkrrrrAœs  zDarwinGroup.group_modc Cs²z˜|j dd¡g}|gd¢7}| |¡\}}}| ¡}d}|D]:}| d¡}t|ƒdkr>t|dƒ} | |kr>| dkr>| }q>|dksŠ|d krWd S|dWSty¬Yd S0dS) NZdsclT)z/Local/Defaultz-listz/GroupsZPrimaryGroupIDrú r8rCiôióF)rr#r!Ú splitlinesÚsplitr>r=Ú Exception) rr rirjrkÚlinesZhighestr<Úpartsrrrrrh¨s"      z+DarwinGroup.get_lowest_available_system_gid)N) rSrTrUrVrWrXr5r%rArhrrrrrdxs  rdc@s4eZdZdZdZdZdZdd„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 cCs|j dd¡|jg}| |¡S©Nr"Tr]rrrrr%ËszOpenBsdGroup.group_delcKsZ|j dd¡g}|jdurD| d¡| t|jƒ¡|jrD| d¡| |j¡| |¡S©Nr/Tr0r1©rr#rr2r3rrr!rbrrrr5Ïs    zOpenBsdGroup.group_addcKs|j dd¡g}| ¡}|jdur^t|jƒ|dkr^| d¡| t|jƒ¡|jr^| d¡t|ƒdkrndS|jj rzdS| |j ¡|  |¡S© Nr6Tr7r0r1r8r9r;© rr#r<rr=r2r3rr>r?rr!©rrr r@rrrrAÙs    zOpenBsdGroup.group_modr_rrrrrs½s  rsc@s4eZdZdZdZdZdZdd„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 cCs|j dd¡|jg}| |¡Srtr]rrrrr%ùszNetBsdGroup.group_delcKsZ|j dd¡g}|jdurD| d¡| t|jƒ¡|jrD| d¡| |j¡| |¡Srurvrbrrrr5ýs    zNetBsdGroup.group_addcKs|j dd¡g}| ¡}|jdur^t|jƒ|dkr^| d¡| t|jƒ¡|jr^| d¡t|ƒdkrndS|jj rzdS| |j ¡|  |¡SrwrxryrrrrAs    zNetBsdGroup.group_modr_rrrrrzës  rzc@s(eZdZdZdd„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() cKsT|j dd¡g}|jdur.| dt|jƒg¡|jr>| d¡| |j¡| |¡S)NÚaddgroupTr0z-S) rr#rÚextendr3rr2rr!rbrrrr5$s   zBusyBoxGroup.group_addcCs|j dd¡|jg}| |¡S)NZdelgroupTr]rrrrr%0szBusyBoxGroup.group_delc Ksô| ¡}|jdurð|j|dkrðtddƒ}| ¡}Wdƒn1sH0Yt|jƒ}d||df}d||jf}d|j|vr |jjdj|jdd|jj r¬d S|  ||¡}tdd ƒ}|  |¡Wdƒn1sâ0Yd Sd S) Nr7r rBs%s:x:%d:s:%d:zgid '{gid}' in use©rr&r;Úwbr9) r<rrIÚreadrrrr,r-r?ÚreplaceÚwrite) rrr@rOZb_groupsZb_nameZb_current_group_stringZb_new_group_stringZ b_new_groupsrrrrA4s  &   (zBusyBoxGroup.group_modN)rSrTrUrVr5r%rArrrrr{s  r{c@seZdZdZdZdS)Ú AlpineGroupZLinuxZAlpineN)rSrTrUrWrXrrrrrƒLsrƒc Csêtttddddgdtdddtddtd 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|dn||jdkrv| ¡s>|j r$|j dd|j |j|jd\}}}n|j|jd\}}}|durv|dkrv|j |j|d|durŠd |d<nd|d<|r ||d<|r®||d<| ¡rÖ| ¡}|j|d<|d|d<|j fi|¤ŽdS)Nr3ZpresentZabsent)ÚtypeÚdefaultÚchoicesT)r„Úrequiredr=)r„ÚboolF)r„r…)rrrrrrrr)Z argument_specZsupports_check_modeZ required_ifz Group instantiated - platform %sz$Group instantiated - distribution %sr:rr)Úchangedr)rr')rrr~r‰ÚstdoutÚstderrrr7)rÚdictrÚdebugrWrXrrrQr?Z exit_jsonr%r,r5rrrAr<)rÚgrouprirjrkÚresultr@rrrÚmainRsd    ú ÿö            rÚ__main__)Z __future__rrrr„Z __metaclass__Z DOCUMENTATIONZEXAMPLESZRETURNr(rEZansible.module_utils._textrZansible.module_utils.basicrZ$ansible.module_utils.common.sys_inforÚobjectrrZr\r`rcrdrsrzr{rƒrrSrrrrÚs.@    -, E./2C