a )g%@sddlmZmZmZeZddlZddlmZ ddl m Z m Z ddl mZddlmZmZddlmZddlmZdd lmZdd lmZdd lmZdd lmZdd lmZddl m!Z!ddl"m#Z#ddl$m%Z%dgZ&e%Z'GdddeeeeZ(dS))absolute_importdivisionprint_functionN) constants) AnsibleErrorAnsibleAssertionError) string_types)AnsibleBaseYAMLObjectAnsibleMapping)NonInheritableFieldAttribute)Base)CollectionSearch) Conditional)Taggable)Templar)AnsibleCollectionRef)_get_collection_role_path) unfrackpath)DisplayRoleDefinitioncsteZdZeddZdfdd ZedddZfdd Zd d Z d d Z ddZ ddZ ddZ dddZZS)rstring)ZisaNcsDtt|||_||_||_d|_d|_||_t |_ ||_ dSN) superr__init___play_variable_manager_loader _role_path_role_collection _role_basedirdict _role_params_collection_list)selfplayZ role_basedirvariable_managerloaderZcollection_list __class__D/usr/lib/python3.9/site-packages/ansible/playbook/role/definition.pyr0szRoleDefinition.__init__cCs tddS)Nznot implemented)r)datar%r&r)r)r*loadAszRoleDefinition.loadcst|trd|}t|ts6t|ts6t|ts6tt|trPtt||}||_ t }t|trn|j |_ | |}| |\}}t|tr||\}}||O}||_||d<||_|S)Nz%srole) isinstanceintr rr rrrpreprocess_data_dsr Z ansible_pos_load_role_name_load_role_path_split_role_paramsr!r)r#dsZnew_ds role_name role_pathZ new_role_def role_paramsr'r)r*r0Es&     zRoleDefinition.preprocess_datacCslt|tr|S|d|d}|r.t|ts:td|d|jrh|jj|jd}t|j|d}| |}|S)z Returns the role name (either the role: or name: field) from the role definition, or (when the role definition is a simple string), just that string r-namez)role definitions must contain a role nameobjr$r&Z variables) r.rgetrrget_varsrrrtemplate)r#r5r6all_varstemplarr)r)r*r2rs   zRoleDefinition._load_role_namec CsV|jdur|jj|jd}nt}t|j|d}||}d}|jsNt |rZt ||j}|rt|d|_ |ddSt j |jdg}tjr|tj|jr||j||j|D]8}||}tt j ||}|j|r||fSqt|}|j|r&t j |}||fS|jp0g|}td|d|f|jd dS) a the 'role', as specified in the ds (or as a bare string), can either be a simple name or a full path. If it is a full path, we use the basename as the role name, otherwise we take the name as-given and append it to the default role path Nr<r=rZrolesz!the role '%s' was not found in %s:r:)rr?rr rrr@r"rZ is_valid_fqcrrrospathjoinZ get_basedirCZDEFAULT_ROLES_PATHextendrappendrZ path_existsbasenamerr1) r#r6rArBZ role_tupleZrole_search_pathsrFr7Zsearchesr)r)r*r3s:          zRoleDefinition._load_role_pathcCsJt}t}t|j}|D]"\}}||vr8|||<q|||<q||fS)z Splits any random role params off from the role spec and store them in a dictionary of params for parsing later )r frozensetZ fattributesitems)r#r5Zrole_defr8Zbase_attribute_nameskeyvaluer)r)r*r4s   z!RoleDefinition._split_role_paramscCs |jSr)r!copyr#r)r)r*get_role_paramsszRoleDefinition.get_role_paramscCs|jSr)rrQr)r)r* get_role_pathszRoleDefinition.get_role_pathTcCs&|r ddd|j|jfDS|jS)N.css|]}|r|VqdSrr)).0xr)r)r* z*RoleDefinition.get_name..)rGrr-)r#Zinclude_role_fqcnr)r)r*get_nameszRoleDefinition.get_name)NNNNN)NN)T)__name__ __module__ __qualname__r r-r staticmethodr,r0r2r3r4rRrSrY __classcell__r)r)r'r*r,s   -D))Z __future__rrrtypeZ __metaclass__rEZansiblerrHZansible.errorsrrZansible.module_utils.sixrZansible.parsing.yaml.objectsr r Zansible.playbook.attributer Zansible.playbook.baser Z!ansible.playbook.collectionsearchr Zansible.playbook.conditionalrZansible.playbook.taggablerZansible.templaterZansible.utils.collection_loaderrZ2ansible.utils.collection_loader._collection_finderrZansible.utils.pathrZansible.utils.displayr__all__Zdisplayrr)r)r)r*s&