o nnhT @sBddlmZddlmZddlmZmZmZm Z ddl m Z ddl m Z ddlmZddlmZmZddlmZdd lmZdd lmZdd lmZdd lmZdd lmZddlm Z ddl!m"Z"ddl#m$Z$ddl%m&Z&ddl'm(Z(ddl)m*Z*ddl+m,Z,ddl-m.Z.ddl/m0Z0dgZ1e,Z2Gdddeee(ee$e Z3dS)) annotations) constants) AnsibleErrorAnsibleParserErrorAnsibleUndefinedVariableAnsibleAssertionError) to_native) string_types)ModuleArgsParser)AnsibleBaseYAMLObjectAnsibleMapping) lookup_loader)NonInheritableFieldAttribute)Base)Block)CollectionSearch) Conditional) Delegatable) LoopControl) Notifiable)Role)Taggable)AnsibleCollectionConfig)Display)Sentinel) isidentifierTaskcseZdZdZededZeddZedddd Zed e dZ ed d dZ ed e dZ ed dZ ed eedZedejdZedddZeddZed e dZedddZdNfdd ZdOddZddZedPddZddZddZfdd Zd!d"Zfd#d$Z d%d&Z!d'd(Z"d)d*Z#fd+d,Z$d-d.Z%d/d0Z&d1d2Z'd3d4Z(d5d6Z)d7d8Z*d9d:Z+d;d<Z,dQfd>d? Z-fd@dAZ.fdBdCZ/dDdEZ0dRdFdGZ1dHdIZ2dJdKZ3dLdMZ4Z5S)Srz 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)rraliaslistfloatclass)r class_typerT)rstatic)rprivateNcs<||_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__@/usr/local/lib/python3.10/dist-packages/ansible/playbook/task.pyr0Wsz Task.__init__cCsZ|jr |jj|d}|jr|jrd||jfS|jr|jS|jr'd||jfSd|jfS)z return the name of the task )include_role_fqcnz%s : %sz%s)r+get_namenameaction)r1r9 role_namer7r7r8r:fs  z Task.get_namecCsf|durdSt|tr |St|tr1d}|D]\}}|dr"q|d||f}q|}|SdS)N_z%s=%s ) isinstancer ritems startswithstrip)r1dsbufkvr7r7r8 _merge_kvvs   zTask._merge_kvcCst|||d}|j|||dS)N)r2r3r4)variable_managerloader)r load_data)datar2r3r4rIrJtr7r7r8loadsz Task.loadcCs&|jtjvr d|jdSd|S)z5 returns a human-readable representation of the task zTASK: meta (%s) _raw_paramszTASK: %s)r<C _ACTION_METAargsr:r1r7r7r8__repr__s  z Task.__repr__cCsb|d}|ddus|ddurtd||d|dur'td||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)r1rDnew_dsrFrG loop_namer7r7r8_preprocess_with_loops  zTask._preprocess_with_loopc s,t|tstd|t|ft}t|tr|j|_tj}| d}|dur+|j }n | d|j d|d}|rL|j sL|rI||vrH|d|n|g}|r[d|vr[d|vr[|d|ra||d<t||d}z |\}}}Wnty} z | jr|tt| || dd} ~ ww|j|_|tjvrd |vr| d d d krtd |d |d |d <||d<||d<||d<d|vr|d| d|d<nt|d<|D]<\} } | dvs| |ks| dkrq| dr| dtvr|||| | qtj s| |j vr| || <qt!"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)task_dscollection_list)rYorig_exccmdrOr>z{The 'cmd' argument cannot be used when other raw parameters are specified. Please put everything in one or the other place.rXr<rR delegate_tovars)r< local_actionrRrdshellrUzIgnoring invalid attribute: %s)&r@rrtyper r ansible_posrdefault_collectionr[r_get_validated_value fattributesr+insertappendr parserrYrr.rP_ACTION_HAS_CMDrpop _load_varsrArBrZr r^INVALID_TASK_ATTRIBUTE_FAILEDdisplaywarningr/rpreprocess_data) r1rDr\rjcollections_list args_parserr<rRrderFrGr5r7r8rvsh          zTask.preprocess_datacCs*t|ts td|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)rX)rLrIrJ)r@rrrrN_variable_manager_loader)r1attrrDr7r7r8_load_loop_controls zTask._load_loop_controlc sBz tt||WdSty }z |jd7_|d}~ww)Nzb This error can be suppressed as a warning using the "invalid_task_attribute_failed" configuration)r/r_validate_attributesrmessage)r1rDryr5r7r8r~szTask._validate_attributescC t|tst|||gdSdSNr@r$setattrr1r|r;valuer7r7r8_validate_changed_when zTask._validate_changed_whencCrrrrr7r7r8_validate_failed_whenrzTask._validate_failed_whencCs(|durt|std|ddSdS)Nz0Invalid variable name in 'register' specified: '')rrrr7r7r8_validate_registerszTask._validate_registercs.|jr |j|tjr tt||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_validaterrjr/r)r1templarr5r7r8rs  zTask.post_validatecCsb||_||}d|vr/|d}t|tr'tjrtd| ||}|St d|d|S)N_variable_paramszUsing a variable for a task's 'args' is unsafe in some situations (see https://docs.ansible.com/ansible/devel/reference_appendices/faq.html#argsplat-unsafe)z invalid or malformed argument: 'r) untemplated_argstemplaterqr@rrPINJECT_FACTS_AS_VARSrtruupdater)r1r|rrrRvariable_paramsr7r7r8_post_validate_args(s     zTask._post_validate_argscC|S)z Override post validation for the loop field, which is templated specially in the TaskExecutor class when evaluating loops. r7r1r|rrr7r7r8_post_validate_loop@zTask._post_validate_loopcsi|durafdd}t|trD|D],}t|tr)|D] }||||qqj|dd}t|tr:|Oqtd|qSt|trZt|D] }||||qNSj|ddS)zu Override post validation of vars on the play, as we don't want to template these too early. Nc sfz j|dd|<WdSty2}zt|}jtjvr"d|vs&d|vr-WYd}~dSd}~ww)NF convert_barezansible_facts.env ansible_env)rrrr<rP_ACTION_FACT_GATHERING)rFrGryerrorenvr1rr7r8 _parse_env_kvOsz6Task._post_validate_environment.._parse_env_kvFrz/could not parse environment value, skipping: %s)r@r$rrrtru)r1r|rrrenv_itemrFisdictr7rr8_post_validate_environmentGs*     zTask._post_validate_environmentcCr)z changed_when is evaluated after the execution of the task is complete, and should not be templated during the regular post_validate step. r7rr7r7r8_post_validate_changed_whenprz Task._post_validate_changed_whencCr)z failed_when is evaluated after the execution of the task is complete, and should not be templated during the regular post_validate step. r7rr7r7r8_post_validate_failed_whenwrzTask._post_validate_failed_whencCr)z until is evaluated after the execution of the task is complete, and should not be templated during the regular post_validate step. r7rr7r7r8_post_validate_until~rzTask._post_validate_untilcCsDt}|jr ||jO}||jO}d|vr|d=d|vr |d=|S)Ntagswhen)rr,get_varsrer1all_varsr7r7r8rs z Task.get_varscCs4t}|jr ||jO}|jtjvr||jO}|Sr)rr,get_include_paramsr<rP_ACTION_ALL_INCLUDESrerr7r7r8rs   zTask.get_include_paramsFcs^tt|}d|_|jr|s|jj|d|_d|_|jr!|j|_|j|_|j|_|j|_|S)N) exclude_tasks)r/rcopyr,r+r-r._uuid)r1exclude_parentrnew_mer5r7r8rs z Task.copycshtt|}|js2|js2|jr|j|d<|jjj|d<|jr(|j|d<|j |d<|j |d<|S)Nparent parent_typer3r-r.) r/r serialize _squashed _finalizedr,r6__name__r+r-r.)r1rLr5r7r8rs   zTask.serializec sddlm}ddlm}|dd}|r;|d}|dkr!t}n|dkr)|}n|dkr0|}||||_|d=|d }|rPt}||||_ |d =|d d |_ |d |_ t t ||dS) Nr TaskInclude)HandlerTaskIncluderrrrrr3r-Fr.)ansible.playbook.task_includer%ansible.playbook.handler_task_includerr[r deserializer,rr+r-r.r/r) r1rLrr parent_datarp role_datarr5r7r8rs.        zTask.deserializecCs ||_|jr|j|dSdS)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)r{r, set_loader)r1rJr7r7r8rszTask.set_loaderc Cs|j|}|j}|j}z]|rt}n t|d|t}t|jddr%|j}n|jj}|r`|tus1|rft|ddrc|dkrFt|drF||}n t|d|t}|r[||||}W|S|}W|SW|SW|SW|St yrY|Sw)zZ Generic logic to get the attribute or parent attribute for a task value. r?statically_loadedTre_get_parent_attribute) rlextendprependrgetattrr,hasattrr _extend_valueKeyError) r1r|omitfattrrrrr, parent_valuer7r7r8rs<    zTask._get_parent_attributecCs|jr|jSdS)NT)r,all_parents_staticrSr7r7r8rs zTask.all_parents_staticcCs2ddlm}|jrt|j|r|jS|jSdS)Nrr)rrr,r@get_first_parent_include)r1rr7r7r8rs   zTask.get_first_parent_includecCs&|j}t|ts|j}t|tr|jSr)r,r@r_play)r1rr7r7r8get_plays   z Task.get_play)NNN)T)NNNNN)FF)F)6r __module__ __qualname____doc__rrrRr< async_valr$ changed_whendelay failed_whenrVr loop_controlrPDEFAULT_POLL_INTERVALpollregisterretriesuntilrWr0r:rH staticmethodrNrTr^rvr}r~rrrrrrrrrrrrrrrrrrrr __classcell__r7r7r5r8r/sZ             `  )   (N)4 __future__ransiblerrPansible.errorsrrrr+ansible.module_utils.common.text.convertersransible.module_utils.sixr ansible.parsing.mod_argsr ansible.parsing.yaml.objectsr r ansible.plugins.loaderr ansible.playbook.attributeransible.playbook.baseransible.playbook.blockr!ansible.playbook.collectionsearchransible.playbook.conditionalransible.playbook.delegatableransible.playbook.loop_controlransible.playbook.notifiableransible.playbook.roleransible.playbook.taggableransible.utils.collection_loaderransible.utils.displayransible.utils.sentinelransible.utils.varsr__all__rtrr7r7r7r8s2