a )gpR@s"ddlmZmZmZeZddlZddlZddlZddl Z ddl Z ddl Z ddl m Z ddlmZddlmZddlmZmZddlmZddlmZdd lmZmZdd lmZmZdd lm Z dd l!m"Z"dd l#m$Z$ddl%m&Z&ddl'm(Z(m)Z)e&Z*ej+e,dddZ-Gddde.Z/dS))absolute_importdivisionprint_functionN)MutableSequence)rmtree)context) AnsibleErrorAnsibleParserError) GalaxyAPI) user_agent) to_nativeto_text) yaml_dump yaml_load) LooseVersion)open_url)RoleRequirement)Display) is_subpath unfrackpath)returncCsTd}ttdrPtd}tj|_d|_zt|dWntjyJYn0d}|S)zj Check if tarfile.data_filter implementation is working for the current Python version or not F data_filterzdocs/README.mdz ../README.mdz/fooT)hasattrtarfileZTarInfoZSYMTYPEtypelinknamerZLinkOutsideDestinationError)retZtir7/usr/lib/python3.9/site-packages/ansible/galaxy/role.py_check_working_data_filter2s   rc@seZdZeddgZejddejddfZejddZ ejddejddfZ d Z d'd d Z d dZ ddZeddZeddZeddZeddZeddZddZddZdd Zd!d"Zed#d$Zed%d&Zd S)( GalaxyRolegitZhgmetazmain.ymlz main.yamlz.galaxy_install_infozrequirements.ymlzrequirements.yaml)defaultsfileshandlersr"ZtasksZ templatesvarsZtestsNc sd_d_d_d_tjd _tdj|_ |_ |_ |_ |pT|_ d_|_fdd|jD_|dur|tjtjjj stj|j }n8jD]0}tjtj|||rtj|j }qq|_n jd_dS)NZ ignore_certszValidate TLS certificates: %scsg|]}tj|jqSr)ospathjoinname).0xselfrr fz'GalaxyRole.__init__..r) _metadata_metadata_dependencies _requirements _install_inforCLIARGS_validate_certsdisplaydebuggalaxy_apir*versionsrc download_urlscmZ roles_pathspathsendswithr'r(r)sep META_MAINexists) r.r9apir*r<r;r>r( meta_mainrr-r__init__Ts.  zGalaxyRole.__init__cCs |jrd|j|jfS|jSdS)zj Returns "rolename (version)" if version is not null Returns "rolename" otherwise z%s (%s)N)r;r*r-rrr__repr__zszGalaxyRole.__repr__cCs |j|jkSN)r*)r.otherrrr__eq__szGalaxyRole.__eq__cCst|jts|jjS|jSrH) isinstancer:r rDr-rrrrDs zGalaxyRole.apic Cs|jdur|jD]}|jD]}tj||}tj|rz8t|d}t||_Wdn1sd0YWn(t yt d|j YdS0qqq|jS)z' Returns role metadata NrzUnable to load metadata for %sF) r1r?rBr'r(r)isfileopenr Exceptionr7vvvvvr*)r.r(rE meta_pathfrrrmetadatas     ,  zGalaxyRole.metadatacCsT|jdur,g|_|jdur,|jdp(g|_t|jtsNtd|d|j|jS)zC Returns a list of dependencies from role metadata NZ dependencies.Expected role dependencies to be a list. Role z% has meta/main.yml with dependencies )r2rSgetrKrr r-rrrmetadata_dependenciess   z GalaxyRole.metadata_dependenciescCs|jdurtj|j|j}tj|rzTzt|d}t||_Wn.typt d|j YW| dS0W| n | 0|jS)z+ Returns role install info NrLz)Unable to load Galaxy install info for %sF) r4r'r(r) META_INSTALLrMrNrrOr7rPr*close)r. info_pathrRrrr install_infos    zGalaxyRole.install_infocCs"|jD]}tj|rdSqdS)NTF)r?r'r(isdir)r.r(rrr_existss  zGalaxyRole._existsc Cst|jtjdd}tjtj|jdsHt tj|jdtj|j|j }t |dB}zt |||_ Wn tyYWddS0Wdn1s0YdS)z Writes a YAML-formatted file to the role's meta/ directory (named .galaxy_install_info) which contains some information we can use later for commands like 'list' and 'info'. z%c)r;Z install_dater"zw+NFT)dictr;datetimeZutcnowstrftimer'r(rCr)makedirsrWrNrr4rO)r.inforYrRrrr_write_galaxy_install_infos  2z%GalaxyRole._write_galaxy_install_infocCs.|jr*zt|jWdSty(Yn0dS)z Removes the specified role from the roles path. There is a sanity check to make sure there's a meta/main.yml file at this path so the user doesn't blow away random directories. TF)rSrr(rOr-rrrremoves  zGalaxyRole.removec Cs|r|jdur|j}n0d|vr@d|vr@d|d|d|jf}n|j}td|zNt||jtd}tjdd}| }|r| || }q|| |j WSt y}ztd t|WYd}~n d}~00dS) zS Downloads the archived role to a temp location based on role data NZ github_userZ github_repoz*https://github.com/%s/%s/archive/%s.tar.gzz- downloading role from %s)Zvalidate_certsZ http_agentF)deletezfailed to download the file: %s)r=r;r<r7rr6r tempfileZNamedTemporaryFilereadwriterXr*rOerrorr )r. role_dataZ archive_urlZurl_fileZ temp_filedataerrrfetchs&    (zGalaxyRole.fetchc Cs|jr&tjfdtjdi|j}n|jrtj |jrF|j}qd|jvrd|j}| |}q|j |j}|st d|j|j jf|ddkrtd|j|j d|d}|jsPt|d kr.d d |D}z |Wn0tyt d d dd |DYn0t|d|_n |ddrH|d|_nd|_nB|jdkr|rt|jdd |Dvrt d|j|j|f|D]N}|d|jkrd|vr|d|_|d|jkrd|vr|d|_q| |}nt d|rtd|t|s&t dnt|d}d}|}|D]`} |j D]R} | | jvrLtj!tj!| j} |s| } | }nt| t| krL| } | }qLqB|st dn2zt"|#||_$Wnt%yt dYn0|j&} |j| d kr |j| dd <t| }t'| D]V\}}||_td|j|jfztj(|jrtj)|jsnt dn8tjdd st d!|jn|*st d"|jn t+|jt,| d d#}|D].} | -s| .sqd$D]}t/| |d}sq|d%kr tj!t/| dd&}n&|0| d&d'}tjj|1tj2}d&}tj|||}t3||d(d)sd*|d+|d,|}t |tj||}tjj|0|d&d'1tj2}t4| ||qt5r|j6| t7|jd-d.n|6| t7|jq|8WqtWnft9yn}zL|j:t:j;krD||d'krDWYd}~qt d/|jt7|fWYd}~n d}~00qtd0t<||jrtj |jszt=|Wn@t9t>fy}z"td1|t|fWYd}~n d}~00d(Sd S)2NZ keep_scm_metaz://z - sorry, %s was not found on %s.Z role_typeZAPPzP%s is a Container App role, and should only be installed using Ansible ContainerZversionsidrcSsg|]}t|ddqSr*N)rrUr+arrrr/-r0z&GalaxyRole.install..zUnable to compare role versions (%s) to determine the most recent version due to incompatible version formats. Please contact the role author to resolve versioning conflicts, or specify an explicit role version to install.z, cSsg|] }|jqSr)Zvstring)r+vrrrr/4r0Z github_branchZmastercSsg|]}|ddqSrn)rUrorrrr/<r0zX- the specified version (%s) of %s was not found in the list of available versions (%s).r*sourcer=zNo valid role data foundzinstalling from %sz>the downloaded file does not appear to be a valid tar archive.rLz7this role does not appear to have a meta/main.yml file.z=this role does not appear to have a valid meta/main.yml file.z- extracting %s to %sz7the specified roles path exists and is not a directory.forceFzJthe specified role %s appears to already exist. Use --force to replace it.zu%s doesn't appear to contain a role. please remove this directory manually if you really want to put the role here.)follow)r*rrT)realzInvalid z for tarfile member: path z is not a subpath of the role rj)filterz Could not update files in %s: %sz- %s was installed successfullyz"Unable to remove tmp file (%s): %s)?r>rZscm_archive_rolerr5specr<r'r(rMrlrDZlookup_role_by_namerZ api_serverrUr7Zwarningr*Zfetch_role_relatedr;lensort TypeErrorr)r r=r8rZ is_tarfilerNZ getmembersrBdirnamerZ extractfiler1rOr? enumeraterCr[rcr`rZisregZissymgetattrreplacesplitrArsetattrrextractr rbOSErrorerrnoZEACCESstrunlinkIOError)r.Ztmp_fileriZ role_versionsZloose_versionsZ role_versionZ role_tar_fileZ meta_filemembersmemberrEZmeta_parent_dirZarchive_parent_dirr?Z paths_lenidxr(Zresolved_archiveattrZ attr_value relative_to full_patherrZrelative_path_dir relative_pathrkrrrinstalls                        0,zGalaxyRole.installcCst|j|j|j|jdS)z Returns role spec info { 'scm': 'git', 'src': 'http://git.example.com/repos/repo.git', 'version': 'v1.0', 'name': 'repo' } )r>r<r;r*)r]r>r<r;r*r-rrrrzs zGalaxyRole.specc Cs|jdurg|_|jD]x}tj|j|}tj|rzHzt|d}t||_Wn"tyrt d|j Yn0W| n | 0qqt |jtstd|d|j|jS)z+ Returns role requirements NrLz"Unable to load requirements for %srTz has meta/requirements.yml )r3META_REQUIREMENTSr'r(r)rMrNrrOr7rPr*rXrKrr )r.Zmeta_requirementsrQrRrrr requirementss      zGalaxyRole.requirements)NNNN)__name__ __module__ __qualname__setZSUPPORTED_SCMSr'r(r)rBrWrZ ROLE_DIRSrFrGrJpropertyrDrSrVrZr\rbrcrlrrzrrrrrr Ls6  &      2 r )0Z __future__rrrrZ __metaclass__rr^ functoolsr'rrecollections.abcrshutilrZansiblerZansible.errorsrr Zansible.galaxy.apir Zansible.galaxy.user_agentr Zansible.module_utils._textr r Z ansible.module_utils.common.yamlrrZ#ansible.module_utils.compat.versionrZansible.module_utils.urlsrZ!ansible.playbook.role.requirementrZansible.utils.displayrZansible.utils.pathrrr7cacheboolrobjectr rrrrs0