o nnh?@sddlmZddlmZddlmZddlmZmZddl m Z ddl m Z ddl mZmZmZddlmZdd lmZdd lmZdd lmZdd lmZmZdd lmZmZddlm Z ddl!m"Z"ddl#m$Z$e$Z%dgZ&Gdddee"eZ'dS)) annotations) constants)context)AnsibleParserErrorAnsibleAssertionError) to_native) is_sequence) binary_type string_types text_type)NonInheritableFieldAttribute)Base)Block)CollectionSearch)load_list_of_blocksload_list_of_roles)Role hash_params)Task)Taggable)DisplayPlaycseZdZdZeddedddZeddddZedd d edd Zed e j ddZ ed e j dZ ededdZededdZededdZededdZededdZededdZededdZededddZedddZededdZed e jddZed ddZfddZddZe ddZ!ddZ"dd Z#e$dGd!d"Z%fd#d$Z&d%d&Z'd'd(Z(d)d*Z)d+d,Z*d-d.Z+d/d0Z,d1d2Z-d3d4Z.d5d6Z/d7d8Z0d9d:Z1d;d<Z2d=d>Z3d?d@Z4fdAdBZ5fdCdDZ6fdEdFZ7Z8S)Hrz A play is a language feature that represents a list of roles and/or task/handler blocks to execute on a given set of hosts. Usage: Play.load(datastructure) -> Play Play.something(...) listT)isarequiredlistofalways_post_validatepriorityboolN)rdefaultrcCstjSN)CDEFAULT_GATHER_SUBSETr$r$@/usr/local/lib/python3.10/dist-packages/ansible/playbook/play.py=sz Play.)rr rrintstring)rr c)rr rFZforce_handlerspercent)rrcsftt|d|_d|_g|_i|_ttj dgpt d|_ ttj dg|_ i|_i|_dS)Ntags)all skip_tags)superr__init___included_conditional_included_path_removed_hosts role_cachesetrCLIARGSget frozenset only_tagsr0_action_groups_group_actionsself __class__r$r%r2Ws z Play.__init__cCs|Sr!)get_namer>r$r$r%__repr__esz Play.__repr__cCsXtjdddi}|jD]\}}|D]}|}t|}|||i|<qq|S)zIBackwards compat for custom strategies using ``play.ROLE_CACHE`` z[Play.ROLE_CACHE is deprecated in favor of Play.role_cache, or StrategyBase._get_cached_rolez2.18)version)display deprecatedr6itemsrBr_get_hash_dict setdefault)r?cachepathrolesrolename hashed_paramsr$r$r% ROLE_CACHEhs zPlay.ROLE_CACHEcCsxd|jvr8|s tdt|r-|D]}|durtdt|ttfs*tdj|dqdSt|ttfs:tddSdS)Nhostsz6Hosts list cannot be empty. Please check your playbookzFHosts list cannot contain values of 'None'. Please check your playbookz5Hosts list contains an invalid host value: '{host!s}')hostzDHosts list must be a sequence or string. Please check your playbook.)_dsrr isinstancer r format)r? attributerNvalueentryr$r$r%_validate_hostsxs  zPlay._validate_hostscCs<|jr|jSt|jrd|j|_|jS|jpd|_|jS)z return the name of the Play ,)rNrrQjoinr>r$r$r%rBs  z Play.get_namecCs$t}|r ||_|j|||dS)N)variable_managerloader)rcopyvars load_data)datar]r^r`pr$r$r%loads z Play.loadcs\t|tstd|t|fd|vr&d|vrtd|d|d|d<|d=tt||S)zH Adjusts play datastructure to cleanup old/legacy items z?while preprocessing data (%s), ds should be a dict but was a %suser remote_userzkboth 'user' and 'remote_user' are set for this play. The use of 'user' is deprecated, and should be removedobj)rTdictrtyperr1rpreprocess_data)r?dsr@r$r%rks  zPlay.preprocess_datac CsHz t|||j|jdWSty#}z tdt||j|dd}~ww) Loads a list of blocks from a list which may be mixed tasks/blocks. Bare tasks outside of a block are given an implicit block. rlplayr]r^z9A malformed block was encountered while loading tasks: %srhorig_excN)r_variable_manager_loaderAssertionErrorrrrSr?attrrler$r$r% _load_taskss zPlay._load_tasksc C@z t|||j|jdWSty}ztd|j|dd}~ww)rmrnz9A malformed block was encountered while loading pre_tasksrpNrrrrsrtrrSrur$r$r%_load_pre_tasks zPlay._load_pre_tasksc Cry)rmrnz:A malformed block was encountered while loading post_tasksrpNrzrur$r$r%_load_post_tasksr|zPlay._load_post_tasksc CsPz|j|jt||d|j|jdddWSty'}ztd|j|dd}~ww)z Loads a list of blocks from a list which may be mixed handlers/blocks. Bare handlers outside of a block are given an implicit block. T)rlro use_handlersr]r^)prependz8A malformed block was encountered while loading handlersrpN) _extend_valuehandlersrrrrsrtrrSrur$r$r%_load_handlersszPlay._load_handlersc Cs|durg}zt|||j|j|jd}Wnty(}ztd|j|dd}~wwg}|D] }|tj ||dq-||j dd<|j S)z Loads and returns a list of RoleInclude objects from the datastructure list of role definitions and creates the Role from those objects N)ror]r^collection_search_listz-A malformed role declaration was encountered.rpror) rrrrs collectionsrtrrSappendrrdrL)r?rvrl role_includesrwrLrir$r$r% _load_roless  zPlay._load_rolescCsnddlm}||}g}|dur5|D]"}d|vrtd|d|D]}|dvr.td||dq ||q|S)Nr)preprocess_varsrNz6Invalid vars_prompt data structure, missing 'name' keyrg) rNpromptr privateconfirmencrypt salt_sizesaltunsafez>Invalid vars_prompt data structure, found unsupported key '%s')ansible.vars.managerrrr)r?rvrlrnew_ds vars_prompts prompt_datakeyr$r$r%_load_vars_prompts   zPlay._load_vars_promptcC<g}t|jdkr|jD]}|jrq ||j|dq |S)a| Handles the role compilation step, returning a flat list of tasks with the lowest level dependencies first. For example, if a role R has a dependency D1, which also has a dependency D2, the tasks from D2 are merged first, followed by D1, and lastly by the tasks from the parent role R last. This is done for all roles in the Play. rr)lenrL from_includeextendcompiler? block_listrr$r$r%_compile_roless  zPlay._compile_rolescCr)z Handles the role handler compilation step, returning a flat list of Handlers This is done for all roles in the Play. rr)rrLrrget_handler_blocksrr$r$r%compile_roles_handlerss zPlay.compile_roles_handlerscCs@tjddi||j|jd}|jD]}d|_qg}|jrvt}d|_d|j d<d|_| |jt|d}|j p9|g|_|g|_ | |||j}t|d}|pT|g|_|g|_ | |t|d}|jpi|g|_|g|_ | ||S||j | |||||j| |||j| ||S)z Compiles and returns the task list for this play, compiled from the roles (which are themselves compiled recursively) and/or the list of tasks specified in the play. metaflush_handlers)rbror]r^Tnoop _raw_paramsr)rrdrrrsblockimplicitr,ractionargs set_loader pre_tasksalwaysrrtasks post_tasksr)r? flush_blocktaskr noop_taskbrr$r$r%r+sJ                 z Play.compilecCs |jSr!)r`r_r>r$r$r%get_varscs z Play.get_varscCs(|jdurgSt|jts|jgS|jSr!) vars_filesrTrr>r$r$r%get_vars_filesfs  zPlay.get_vars_filescC|jddSr!)rr>r$r$r% get_handlersmzPlay.get_handlerscCrr!)rLr>r$r$r% get_rolesprzPlay.get_rolescCsNg}|j|j|jD]}t|tr||j|j|jq ||q |Sr!) rrrrTrrrrescuer)r?tasklistrr$r$r% get_tasksss   zPlay.get_taskscsXtt|}g}|D] }||q ||d<|j|d<|j|d<|j|d<|S)NrL included_path action_groups group_actions)r1r serializerrr4r<r=)r?rbrLrMr@r$r%r|s    zPlay.serializecstt|||dd|_|di|_|di|_d|vrF|dg}g}|D]}t}||||q+t |d||d=dSdS)NrrrrL) r1r deserializer9r4r<r=rrsetattr)r?rb role_datarLrMrr@r$r%rs     zPlay.deserializecs>tt|}|j|_|j|_|j|_|j|_|j|_|Sr!)r1rr_r6r3r4r<r=)r?new_mer@r$r%r_s z Play.copy)NNN)9__name__ __module__ __qualname____doc__r r rQ gather_facts gather_subsetr"DEFAULT_GATHER_TIMEOUTgather_timeoutDEFAULT_FACT_PATH fact_pathrr vars_promptrLrrrrrcliargs_deferred_getr,max_fail_percentageserialDEFAULT_STRATEGYstrategyorderr2rCpropertyrPrYrB staticmethodrdrkrxr{r}rrrrrrrrrrrrrr_ __classcell__r$r$r@r%r*sZ          8 N)( __future__ransiblerr"ransible.errorsrr+ansible.module_utils.common.text.convertersr'ansible.module_utils.common.collectionsransible.module_utils.sixr r r ansible.playbook.attributer ansible.playbook.baser ansible.playbook.blockr!ansible.playbook.collectionsearchransible.playbook.helpersrransible.playbook.rolerransible.playbook.taskransible.playbook.taggableransible.utils.displayrrE__all__rr$r$r$r%s&