a )ge=@s ddlmZmZmZeZddlmZddlm Z ddl m Z m Z ddl mZddlmZddlmZmZmZddlmZdd lmZdd lmZdd lmZdd lmZmZdd l m!Z!ddl"m#Z#ddl$m%Z%ddl&m'Z'ddl(m)Z)e)Z*dgZ+Gdddee%eZ,dS))absolute_importdivisionprint_function) 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)Task)Taggable)preprocess_vars)DisplayPlaycseZdZdZeddedddZeddddZedd d edd Zed e j ddZ ed e j dZ ededdZededdZededdZededdZededdZededdZededdZededddZedddZededdZed e jddZed ddZfddZddZddZ ddZ!e"dEdd Z#fd!d"Z$d#d$Z%d%d&Z&d'd(Z'd)d*Z(d+d,Z)d-d.Z*d/d0Z+d1d2Z,d3d4Z-d5d6Z.d7d8Z/d9d:Z0d;d<Z1d=d>Z2fd?d@Z3fdAdBZ4fdCdDZ5Z6S)Frz 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)CZDEFAULT_GATHER_SUBSETr%r%9/usr/lib/python3.9/site-packages/ansible/playbook/play.py@z Play.)rr"rrintstring)rr"c)rr"r FZforce_handlerspercent)rrcsftt|d|_d|_g|_i|_ttj dgp>t d|_ ttj dg|_ i|_i|_dS)Ntags)all skip_tags)superr__init___included_conditional_included_pathZ_removed_hosts ROLE_CACHEsetrZCLIARGSget frozensetZ only_tagsr2_action_groups_group_actionsself __class__r%r&r4Zsz Play.__init__cCs|Sr#)get_namer=r%r%r&__repr__hsz Play.__repr__cCstd|jvrp|stdt|rZ|D]4}|dur8tdq"t|ttfs"tdj|dq"nt|ttfsptddS)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>Z attributenamevalueentryr%r%r&_validate_hostsks  zPlay._validate_hostscCs8|jr |jSt|jr&d|j|_n |jp.d|_|jS)z return the name of the Play ,)rHr rCjoinr=r%r%r&rA|s   z Play.get_namecCs$t}|r||_|j|||dS)N)variable_managerloader)rcopyvarsZ load_data)datarOrPrRpr%r%r&loads z Play.loadcs\t|tstd|t|fd|vrLd|vr:td|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 %suserZ remote_userzkboth 'user' and 'remote_user' are set for this play. The use of 'user' is deprecated, and should be removedobj)rFdictrtyperr3rpreprocess_data)r>dsr?r%r&r[s  zPlay.preprocess_datac CsXzt|||j|jdWStyR}z$tdt||j|dWYd}~n d}~00dS) 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. r\playrOrPz9A malformed block was encountered while loading tasks: %srXZorig_excN)r_variable_manager_loaderAssertionErrorrr rEr>attrr\er%r%r& _load_tasksszPlay._load_tasksc CsPzt|||j|jdWStyJ}ztd|j|dWYd}~n d}~00dS)r]r^z9A malformed block was encountered while loading pre_tasksr`NrrarbrcrrErdr%r%r&_load_pre_tasksszPlay._load_pre_tasksc CsPzt|||j|jdWStyJ}ztd|j|dWYd}~n d}~00dS)r]r^z:A malformed block was encountered while loading post_tasksr`Nrhrdr%r%r&_load_post_tasksszPlay._load_post_tasksc Cs`z&|j|jt||d|j|jdddWStyZ}ztd|j|dWYd}~n d}~00dS)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)r\r_Z use_handlersrOrP)Zprependz8A malformed block was encountered while loading handlersr`N)Z _extend_valuehandlersrrarbrcrrErdr%r%r&_load_handlersszPlay._load_handlersc Cs|dur g}zt|||j|j|jd}Wn4ty\}ztd|j|dWYd}~n d}~00g}|D]}|tj ||dqf||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)r_rOrPZcollection_search_listz-A malformed role declaration was encountered.r`r_r) rrarb collectionsrcrrEappendrrUroles)r>rer\Z role_includesrfrpZrir%r%r& _load_roless  &zPlay._load_rolescCsbt|}g}|dur^|D]D}d|vr0td|d|D]}|dvr4td||dq4||q|S)NrHz6Invalid vars_prompt data structure, missing 'name' keyrW) rHpromptr"ZprivateZconfirmZencryptZ salt_sizeZsaltZunsafez>Invalid vars_prompt data structure, found unsupported key '%s')rrro)r>rer\Znew_dsZ vars_promptsZ prompt_datakeyr%r%r&_load_vars_prompts  zPlay._load_vars_promptcCs<g}t|jdkr8|jD]}|jr$q||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. rrm)lenrp from_includeextendcompiler> block_listrr%r%r&_compile_roless  zPlay._compile_rolescCs<g}t|jdkr8|jD]}|jr$q||j|dq|S)z Handles the role handler compilation step, returning a flat list of Handlers This is done for all roles in the Play. rrm)rurprvrwZget_handler_blocksryr%r%r&compile_roles_handlers s zPlay.compile_roles_handlerscCs@tjddi||j|jd}|jD] }d|_q g}|jrt}d|_d|j d<d|_| |jt|d}|j pr|g|_|g|_ | |||j}t|d}|p|g|_|g|_ | |t|d}|jp|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. metaZflush_handlers)rSr_rOrPTZnoopZ _raw_paramsrm)rrUrarbblockZimplicitr.ractionargs set_loader pre_tasksalwaysror|tasks post_tasksrw)r>Z flush_blocktaskrzZ noop_taskbrr%r%r&rxsJ                 z Play.compilecCs |jSr#)rRrQr=r%r%r&get_varsSsz Play.get_varscCs(|jdurgSt|jts"|jgS|jSr#) vars_filesrFrr=r%r%r&get_vars_filesVs   zPlay.get_vars_filescCs|jddSr#)rkr=r%r%r& get_handlers]szPlay.get_handlerscCs|jddSr#)rpr=r%r%r& get_roles`szPlay.get_rolescCsNg}|j|j|jD]2}t|tr>||j|j|jq||q|Sr#) rrrrFrrorZrescuer)r>Ztasklistrr%r%r& get_taskscs   zPlay.get_taskscsXtt|}g}|D]}||q||d<|j|d<|j|d<|j|d<|S)Nrp included_path action_groups group_actions)r3r serializerror6r;r<)r>rSrproler?r%r&rls    zPlay.serializecstt|||dd|_|di|_|di|_d|vr|dg}g}|D]}t}||||qVt |d||d=dS)Nrrrrp) r3r deserializer9r6r;r<rrosetattr)r>rSZ role_datarprr{r?r%r&rys    zPlay.deserializecs>tt|}|j|_|j|_|j|_|j|_|j|_|Sr#)r3rrQr7r5r6r;r<)r>Znew_mer?r%r&rQs z Play.copy)NNN)7__name__ __module__ __qualname____doc__rr rCZ gather_factsZ gather_subsetr$ZDEFAULT_GATHER_TIMEOUTZgather_timeoutZDEFAULT_FACT_PATHZ fact_pathrrZ vars_promptrprkrrrrZcliargs_deferred_getr.Zmax_fail_percentageserialZDEFAULT_STRATEGYZstrategyorderr4rBrKrA staticmethodrUr[rgrirjrlrqrtr|r}rxrrrrrrrrQ __classcell__r%r%r?r&r-sT           8 N)-Z __future__rrrrZZ __metaclass__Zansiblerr$rZansible.errorsrrZansible.module_utils._textr Z'ansible.module_utils.common.collectionsr Zansible.module_utils.sixr r r Zansible.playbook.attributerZansible.playbook.baserZansible.playbook.blockrZ!ansible.playbook.collectionsearchrZansible.playbook.helpersrrZansible.playbook.rolerZansible.playbook.taskrZansible.playbook.taggablerZansible.vars.managerrZansible.utils.displayrZdisplay__all__rr%r%r%r&s(