a )g6S@s*ddlmZmZmZeZddlmZddl m Z m Z m Z m Z ddlmZddlmZddlmZddlmZmZddlmZdd lmZmZdd lmZdd lmZdd l m!Z!dd l"m#Z#ddl$m%Z%ddl&m'Z'ddl(m)Z)ddl*m+Z+ddl,m-Z-ddl.m/Z/dgZ0e-Z1Gdddee#e)e!Z2dS))absolute_importdivisionprint_function) constants) AnsibleErrorAnsibleParserErrorAnsibleUndefinedVariableAnsibleAssertionError) to_native) string_types)ModuleArgsParser)AnsibleBaseYAMLObjectAnsibleMapping) lookup_loader)FieldAttributeNonInheritableFieldAttribute)Base)Block)CollectionSearch) Conditional) LoopControl)Role)Taggable)AnsibleCollectionConfig)Display)SentinelTaskcseZdZdZededZeddZedddd Zed e dZ edd dZ e ddZ e d dZed e dZeZed eedZe d dZedejdZedddZedddZed e dZedddZdKfdd ZdLddZddZedMddZddZ ddZ!fd d!Z"d"d#Z#fd$d%Z$d&d'Z%d(d)Z&fd*d+Z'd,d-Z(d.d/Z)d0d1Z*d2d3Z+d4d5Z,d6d7Z-d8d9Z.d:d;Z/dNfd=d> Z0fd?d@Z1fdAdBZ2dCdDZ3dOdEdFZ4dGdHZ5dIdJZ6Z7S)Prz A task is a language feature that represents a call to a module, with given arguments and other parameters. A handler is a subclass of a task. Usage: Task.load(datastructure) -> Task Task.something(...) dict)isadefaultstring)rintrasync)rraliaslistboolclass)rZ class_typerT)rZstatic)rZprivateNcs<||_d|_d|_d|_|r$||_n||_tt|dS)zQ constructors a task, without the Task.load classmethod, it will be pretty blank NF)_role_parentimplicitresolved_actionsuperr__init__)selfblockrole task_include __class__9/usr/lib/python3.9/site-packages/ansible/playbook/task.pyr.Ysz Task.__init__cCs^|jr|jj|d}|jr.|jr.d||jfS|jr:|jS|jrNd||jfSd|jfSdS)z return the name of the task )include_role_fqcnz%s : %sz%sN)r)get_namenameaction)r/r7Z role_namer5r5r6r8hs z Task.get_namecCsf|dur dSt|tr|St|trbd}|D]$\}}|drDq0|d||f}q0|}|SdS)N_z%s=%s ) isinstancer ritems startswithstrip)r/dsbufkvr5r5r6 _merge_kvxs   zTask._merge_kvcCst|||d}|j|||dS)N)r0r1r2)variable_managerloader)rZ load_data)datar0r1r2rFrGtr5r5r6loadsz Task.loadcCs,|tjvrd|jdSd|SdS)z5 returns a human readable representation of the task zTASK: meta (%s) _raw_paramszTASK: %sN)r8CZ _ACTION_METAargsr/r5r5r6__repr__sz Task.__repr__cCsb|d}|ddus&|ddur6td||d|durNtd||d||d<||d<dS)z2 take a lookup plugin name and store it correctly with_loopN loop_withzduplicate loop in task: %sobjz&you must specify a value when using %s) removeprefixgetr)r/rAnew_dsrCrDZ loop_namer5r5r6_preprocess_with_loops zTask._preprocess_with_loopc sRt|tstd|t|ft}t|tr6|j|_tj}| d}|durV|j }n| d|j d|d}|r|j s|r||vr|d|n|g}|rd|vrd|vr|d|r||d<t||d}z|\}}}Wn@ty } z&| jrtt| || dWYd} ~ nd} ~ 00|j|_|tjvrld |vrl| d d d kr^td |d |d |d <||d<||d<||d<d|vr|d| d|d<n t|d<|D]\} } | dvs| |ks| dkrqnZ| dr| dtvr|||| | n,tj s&| |j vr0| || <nt!"d| qt#t$|%|S)zg tasks are especially complex arguments so need pre-processing. keep it short. z%ds (%s) should be a dict but was a %s collectionsNrzansible.builtinzansible.legacy)Ztask_dsZcollection_list)rTZorig_exccmdrKr;z{The 'cmd' argument cannot be used when other raw parameters are specified. Please put everything in one or the other place.rSr:rM delegate_tovars)r:Z local_actionrMr[shellrPzIgnoring invalid attribute: %s)&r=rr typerr Z ansible_posrdefault_collectionrVrYZget_validated_value fattributesr)insertappendr parserrTr r,rLZ_ACTION_HAS_CMDrpopZ _load_varsr>r?rUrrXZINVALID_TASK_ATTRIBUTE_FAILEDdisplaywarningr-rpreprocess_data) r/rArWr_Zcollections_listZ args_parserr:rMr[erCrDr3r5r6rgsb      (     zTask.preprocess_datacCs*t|tstd|dtj||j|jdS)Nz|the `loop_control` value must be specified as a dictionary and cannot be a variable itself (though it can contain variables)rS)rHrFrG)r=rrrrJZ_variable_manager_loader)r/attrrAr5r5r6_load_loop_controls  zTask._load_loop_controlc sPztt||Wn6tyJ}z|jd7_|WYd}~n d}~00dS)Nzb This error can be suppressed as a warning using the "invalid_task_attribute_failed" configuration)r-r_validate_attributesrmessage)r/rArhr3r5r6rls zTask._validate_attributescCst|tst|||gdSNr=r$setattrr/rjr9valuer5r5r6_validate_changed_whens zTask._validate_changed_whencCst|tst|||gdSrnrorqr5r5r6_validate_failed_whens zTask._validate_failed_whencs,|jr|j|tjrtt||dS)z Override of base class post_validate, to also do final validation on the block and task include (if any) to which this task belongs. N)r* post_validaterr_r-r)r/templarr3r5r6rus zTask.post_validatecCs`||_||}d|vr\|d}t|trLtjr._parse_env_kvFr}z/could not parse environment value, skipping: %s)r=r$rrxrerf)r/rjrrrvrZenv_itemrCZisdictr5rr6_post_validate_environmentDs$     zTask._post_validate_environmentcCs|S)z changed_when is evaluated after the execution of the task is complete, and should not be templated during the regular post_validate step. r5r{r5r5r6_post_validate_changed_whenmsz Task._post_validate_changed_whencCs|S)z failed_when is evaluated after the execution of the task is complete, and should not be templated during the regular post_validate step. r5r{r5r5r6_post_validate_failed_whentszTask._post_validate_failed_whencCs|S)z until is evaluated after the execution of the task is complete, and should not be templated during the regular post_validate step. r5r{r5r5r6_post_validate_until{szTask._post_validate_untilcCsDt}|jr||jO}||jO}d|vr2|d=d|vr@|d=|S)NtagsZwhen)rr*get_varsr\r/Zall_varsr5r5r6rs z Task.get_varscCs4t}|jr||jO}|jtjvr0||jO}|Srn)rr*get_include_paramsr:rLZ_ACTION_ALL_INCLUDESr\rr5r5r6rs   zTask.get_include_paramsFcs^tt|}d|_|jr.|s.|jj|d|_d|_|jrB|j|_|j|_|j|_|j|_|S)N) exclude_tasks)r-rcopyr*r)r+r,Z_uuid)r/Zexclude_parentrZnew_mer3r5r6rs z Task.copycshtt|}|jsd|jsd|jr<|j|d<|jjj|d<|jrP|j|d<|j |d<|j |d<|S)Nparent parent_typer1r+r,) r-r serializeZ _squashedZ _finalizedr*r4__name__r)r+r,)r/rHr3r5r6rs   zTask.serializec sddlm}ddlm}|dd}|rv|d}|dkrBt}n|dkrR|}n|dkr`|}||||_|d=|d }|rt}||||_ |d =|d d |_ |d |_ t t ||dS) Nr TaskInclude)HandlerTaskIncluderrrrrr1r+Fr,)ansible.playbook.task_includerZ%ansible.playbook.handler_task_includerrVr deserializer*rr)r+r,r-r) r/rHrrZ parent_datarpZ role_datarr3r5r6rs.        zTask.deserializecCs||_|jr|j|dS)z Sets the loader on this object and recursively on parent, child objects. This is used primarily after the Task has been serialized/deserialized, which does not preserve the loader. N)rir* set_loader)r/rGr5r5r6rszTask.set_loaderc Cs|j|}|j}|j}z|r"t}nt|d|t}t|jddrJ|j}n|jj}|r|tusb|rt|ddr|dkrt|dr||}nt|d|t}|r||||}n|}Wnt yYn0|S)zZ Generic logic to get the attribute or parent attribute for a task value. r<Zstatically_loadedTr\_get_parent_attribute) r`extendprependrgetattrr*hasattrrZ _extend_valueKeyError) r/rjZomitZfattrrrrrr*Z parent_valuer5r5r6rs*    zTask._get_parent_attributecCs|jr|jSdS)NT)r*all_parents_staticrNr5r5r6r s zTask.all_parents_staticcCs2ddlm}|jr.t|j|r$|jS|jSdS)Nrr)rrr*r=get_first_parent_include)r/rr5r5r6rs    zTask.get_first_parent_include)NNN)T)NNNNN)FF)F)8r __module__ __qualname____doc__rrrMr:Z async_valr$Z changed_whenZdelayrr[Zdelegate_factsZ failed_whenrQrZ loop_controlnotifyrLZDEFAULT_POLL_INTERVALZpollregisterZretriesZuntilrRr.r8rE staticmethodrJrOrXrgrkrlrsrtrurzr|rrrrrrrrrrrrr __classcell__r5r5r3r6r.sZ               _  )   (N)3Z __future__rrrr^Z __metaclass__ZansiblerrLZansible.errorsrrrr Zansible.module_utils._textr Zansible.module_utils.sixr Zansible.parsing.mod_argsr Zansible.parsing.yaml.objectsr rZansible.plugins.loaderrZansible.playbook.attributerrZansible.playbook.baserZansible.playbook.blockrZ!ansible.playbook.collectionsearchrZansible.playbook.conditionalrZansible.playbook.loop_controlrZansible.playbook.rolerZansible.playbook.taggablerZansible.utils.collection_loaderrZansible.utils.displayrZansible.utils.sentinelr__all__rerr5r5r5r6s,