
    VhT              
      P   d dl mZ d dlmZ d dlmZmZmZm	Z	 d dl
mZ d dlmZ d dlmZ d dlmZmZ d dlmZ d d	lmZ d d
lmZ d dlmZ d dlmZ d dlmZ d dlm Z  d dl!m"Z" d dl#m$Z$ d dl%m&Z& d dl'm(Z( d dl)m*Z* d dl+m,Z, d dl-m.Z. d dl/m0Z0 dgZ1 e,       Z2 G d deee(ee$e       Z3y)    )annotations)	constants)AnsibleErrorAnsibleParserErrorAnsibleUndefinedVariableAnsibleAssertionError)	to_native)string_types)ModuleArgsParser)AnsibleBaseYAMLObjectAnsibleMapping)lookup_loader)NonInheritableFieldAttribute)Base)Block)CollectionSearch)Conditional)Delegatable)LoopControl)
Notifiable)Role)Taggable)AnsibleCollectionConfig)Display)Sentinel)isidentifierTaskc                      e Zd ZdZ ede      Z ed      Z eddd	      Z ed
e	      Z
 edd      Z ed
e	      Z ed
      Z edee      Z edej"                        Z edd      Z ed      Z ed
e	      Z edd      Zd/ fd	Zd0dZd Zed1d       Zd Zd Z fdZd Z fdZ d Z!d Z"d Z# fdZ$d Z%d  Z&d! Z'd" Z(d# Z)d$ Z*d% Z+d& Z,d2 fd'	Z- fd(Z. fd)Z/d* Z0d3d+Z1d, Z2d- Z3d. Z4 xZ5S )4r   z
    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)isadefaultstring)r    intr   async)r    r!   aliaslistfloat   class)r    
class_typer!   T)r    static)r    privatec                    || _         d| _        d| _        d| _        |r|| _        n|| _        t        t
        |           y)zQ constructors a task, without the Task.load classmethod, it will be pretty blank NF)_role_parentimplicitresolved_actionsuperr   __init__)selfblockroletask_include	__class__s       E/home/dcms/DCMS/lib/python3.12/site-packages/ansible/playbook/task.pyr3   zTask.__init__W   s@     
#'DL DLdD"$    c                (   | j                   r| j                   j                  |      }| j                   r| j                  rd| j                  S | j                  r| j                  S | j                   rd| j                  S | j                  S )z return the name of the task )include_role_fqcnz : )r.   get_namenameaction)r4   r<   	role_names      r9   r=   zTask.get_namef   sp     ::

++>O+PI::$)) )49955YY99zz$-t{{;;#{{,r:   c                    |yt        |t              r|S t        |t              rId}|j                         D ]"  \  }}|j	                  d      r||d|dz   }$ |j                         }|S y )N _= )
isinstancer
   r   items
startswithstrip)r4   dsbufkvs        r9   	_merge_kvzTask._merge_kvv   sv    :L)ID!C((* .A<<$1--. ))+CJ "r:   c                F    t        |||      }|j                  | ||      S )N)r5   r6   r7   )variable_managerloader)r   	load_data)datar5   r6   r7   rP   rQ   ts          r9   loadz	Task.load   s&    u4lC{{42B6{RRr:   c                    | j                   t        j                  v rd| j                  d   z  S d| j	                         z  S )z5 returns a human-readable representation of the task zTASK: meta (%s)_raw_paramszTASK: %s)r?   C_ACTION_METAargsr=   r4   s    r9   __repr__zTask.__repr__   s7    ;;!..($tyy'???//r:   c                    |j                  d      }|j                  d      |j                  d      t        d|z  |      |t        d|z  |      ||d<   ||d<   y)z2 take a lookup plugin name and store it correctly with_loopN	loop_withzduplicate loop in task: %sobjz&you must specify a value when using %s)removeprefixgetr   )r4   rJ   new_dsrL   rM   	loop_names         r9   _preprocess_with_loopzTask._preprocess_with_loop   sn     NN7+	::f)VZZ-D-P;iGRPP9G!KQSTT'{vr:   c                X   t        |t              st        d|dt        |            t	               }t        |t
              r|j                  |_        t        j                  }|j                  d      }|| j                  }n-| j                  d| j                  j                  d      |d      }|r(| j                  s|r||vr|j                  d|       n|g}|rd|vrd|vr|j                  d       |r||d<   t!        ||      }	 |j#                         \  }}}|j$                  | _        |t,        j.                  v r:d
|v r6|j                  dd      dk7  rt1        d|      |j3                  d
      |d<   ||d<   ||d<   ||d<   d|v r%| j5                  d|j                  d            |d<   nt               |d<   |j7                         D ]  \  }
}|
dv s
|
|k(  s|
dk(  r|
j9                  d      r,|
j;                  d      t<        v r| j?                  |||
|       Rt,        j@                  s|
| j                  v r|||
<   vtB        jE                  d|
z          tF        tH        |   |      S # t&        $ r)}	|	j(                  r t'        t+        |	      ||		      d}	~	ww xY w)zg
        tasks are especially complex arguments so need pre-processing.
        keep it short.
        zds (z) should be a dict but was a collectionsNr   zansible.builtinzansible.legacy)task_dscollection_list)rb   orig_exccmdrW   rB   z{The 'cmd' argument cannot be used when other raw parameters are specified. Please put everything in one or the other place.ra   r?   rZ   delegate_tovars)r?   local_actionrZ   rn   shellr^   zIgnoring invalid attribute: %s)&rF   r   r   typer   r   ansible_posr   default_collectionrd   ri   get_validated_valuefattributesr.   insertappendr   parser1   r   rb   r	   rX   _ACTION_HAS_CMDr   pop
_load_varsrG   rH   rc   r   rg   INVALID_TASK_ATTRIBUTE_FAILEDdisplaywarningr2   r   preprocess_data)r4   rJ   re   rt   collections_listargs_parserr?   rZ   rn   erL   rM   r8   s               r9   r   zTask.preprocess_data   s    "d#'SUW[\^W_(`aa
  !b/0!#F 5GG66-0##//  $77tGWGWG[G[\iGjl|  C   Ddjj%-==$++A/AB$6#7  19I IN^fvNv##$45 0B}
 'rCST	?*5*;*;*='VT; $/#>#>D 
 Q&&&}88M2."4& ([`bd d&*hhuo]#!xv +}
 R< "__T266&>BF6N!VF6Nhhj 
	FFQEEfXY]dXdg&1>>'+Bm+S**2vq!<00A9I9I4Iq	 @1 DE
	F T4088_ " 	G uu$Yq\rAFF	Gs   I7 7	J) $J$$J)c                    t        |t              st        d|      t        j                  || j
                  | j                        S )Nz|the `loop_control` value must be specified as a dictionary and cannot be a variable itself (though it can contain variables)ra   )rS   rP   rQ   )rF   r   r   r   rU   _variable_manager_loader)r4   attrrJ   s      r9   _load_loop_controlzTask._load_loop_control   sF    "d#$I  R$:P:PY]YeYeffr:   c                ~    	 t         t        |   |       y # t        $ r}|xj                  dz  c_        |d }~ww xY w)Nzb
This error can be suppressed as a warning using the "invalid_task_attribute_failed" configuration)r2   r   _validate_attributesr   message)r4   rJ   r   r8   s      r9   r   zTask._validate_attributes  s;    	$226! 	II~~IG	s    	<7<c                B    t        |t              st        | ||g       y y NrF   r&   setattrr4   r   r>   values       r9   _validate_changed_whenzTask._validate_changed_when      %&D$( 'r:   c                B    t        |t              st        | ||g       y y r   r   r   s       r9   _validate_failed_whenzTask._validate_failed_when  r   r:   c                >    |t        |      st        d| d      y y )Nz0Invalid variable name in 'register' specified: '')r   r   r   s       r9   _validate_registerzTask._validate_register  s/    \%%8$'WX]W^^_%`aa &9r:   c                    | j                   r| j                   j                  |       t        j                  r	 t        t
        |   |       y)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_validater   rt   r2   r   )r4   templarr8   s     r9   r   zTask.post_validate  s9     <<LL&&w/"55dD'0r:   c                   || _         |j                  |      }d|v rj|j                  d      }t        |t              r:t
        j                  rt        j                  d       |j                  |       |}|S t        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_argstemplater{   rF   r   rX   INJECT_FACTS_AS_VARSr~   r   updater   )r4   r   r   r   rZ   variable_paramss         r9   _post_validate_argszTask._post_validate_args(  s     !& & %"hh'9:O/40))OO %A B&&t,&  #%EoEVVW#XYYr:   c                    |S )z
        Override post validation for the loop field, which is templated
        specially in the TaskExecutor class when evaluating loops.
         r4   r   r   r   s       r9   _post_validate_loopzTask._post_validate_loop@  	    
 r:   c                    i |ǈ fd}t        |t              rn|D ]g  }t        |t              r|D ]  } ||||           'j                  |d      }t        |t              r|z  Pt        j                  d|z         i S t        |t              rt               |D ]  } ||||           S j                  |d      S )zu
        Override post validation of vars on the play, as we don't want to
        template these too early.
        c                    	 j                  |d      | <   y # t        $ r:}t        |      }j                  t        j
                  v rd|v sd|v rY d }~y  d }~ww xY w)NFconvert_barezansible_facts.envansible_env)r   r   r	   r?   rX   _ACTION_FACT_GATHERING)rL   rM   r   errorenvr4   r   s       r9   _parse_env_kvz6Task._post_validate_environment.<locals>._parse_env_kvO  sd    $--ae-DCF/ %aLE{{a&>&>>CVZ_C_cptycys    	A/AAAFr   z/could not parse environment value, skipping: %s)rF   r&   r   r   r~   r   )	r4   r   r   r   r   env_itemrL   isdictr   s	   `  `    @r9   _post_validate_environmentzTask._post_validate_environmentG  s    
  %& % 	gH!(D1!) :A)!Xa[9: ")!1!1(!1!O%fd36MC#OO,]`e,ef	g( 
 E4(f % =H!(E(O<= 
 &&u5&A
r:   c                    |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.
        r   r   s       r9   _post_validate_changed_whenz Task._post_validate_changed_whenp  r   r:   c                    |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.
        r   r   s       r9   _post_validate_failed_whenzTask._post_validate_failed_whenw  r   r:   c                    |S )z
        until is evaluated after the execution of the task is complete,
        and should not be templated during the regular post_validate step.
        r   r   s       r9   _post_validate_untilzTask._post_validate_until~  r   r:   c                    t               }| j                  r|| j                  j                         z  }|| j                  z  }d|v r|d= d|v r|d= |S )Ntagswhen)r   r/   get_varsro   r4   all_varss     r9   r   zTask.get_vars  sZ    6<<--//HDIIX X r:   c                    t               }| j                  r|| j                  j                         z  }| j                  t        j
                  v r|| j                  z  }|S r   )r   r/   get_include_paramsr?   rX   _ACTION_ALL_INCLUDESro   r   s     r9   r   zTask.get_include_params  sL    6<<7799H;;!000		!Hr:   c                F   t         t        |          }d |_        | j                  r#|s!| j                  j                  |      |_        d |_        | j                  r| j                  |_        | j
                  |_        | j                  |_        | j                  |_        |S )N)exclude_tasks)r2   r   copyr/   r.   r0   r1   _uuid)r4   exclude_parentr   new_mer8   s       r9   r   z	Task.copy  s}    tT')<<!\\..].KFN::::FL--!%!5!5zzr:   c                   t         t        |          }| j                  s| j                  s| j
                  r@| j
                  j                         |d<   | j
                  j                  j                  |d<   | j                  r| j                  j                         |d<   | j                  |d<   | j                  |d<   |S )Nparentparent_typer6   r0   r1   )r2   r   	serialize	_squashed
_finalizedr/   r8   __name__r.   r0   r1   )r4   rS   r8   s     r9   r   zTask.serialize  s    T4*,~~doo||!%!7!7!9X&*ll&<&<&E&E]#zz#zz335V#}}D&*&:&:D"#r:   c                   ddl m} ddlm} |j	                  dd       }|rU|j	                  d      }|dk(  rt               }n|dk(  r |       }n|dk(  r |       }j                  |       || _        |d= |j	                  d	      }|r%t               }|j                  |       || _	        |d	= |j	                  d
d      | _
        |j	                  d      | _        t        t        |   |       y )Nr   TaskInclude)HandlerTaskIncluder   r   r   r   r   r6   r0   Fr1   )ansible.playbook.task_includer   %ansible.playbook.handler_task_includer   rd   r   deserializer/   r   r.   r0   r1   r2   r   )
r4   rS   r   r   parent_datar   p	role_datarr8   s
            r9   r   zTask.deserialize  s     	>Lhhx.((=1Kg%G-M 44&(MM+&DLXHHV$	AMM)$DJVU3#xx(9:dD%d+r:   c                b    || _         | j                  r| j                  j                  |       yy)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)r4   rQ   s     r9   r   zTask.set_loader  s)     <<LL##F+ r:   c                   | j                   |   }|j                  }|j                  }	 |rt        }nt	        | d| t              }t	        | j
                  dd      r| j
                  }n| j
                  j
                  }|rg|t        u s|r]t	        |dd      rP|dk7  rt        |d      r|j                  |      }nt	        |d| t              }|r| j                  |||      }|S |}|S # t        $ r Y S w xY w)zZ
        Generic logic to get the attribute or parent attribute for a task value.
        rC   statically_loadedTro   _get_parent_attribute)
rv   extendprependr   getattrr/   hasattrr   _extend_valueKeyError)	r4   r   omitfattrr   r   r   r/   parent_values	            r9   r   zTask._get_parent_attribute  s      &--	 $j(; t||%8$?,,,,..EX-7$7>v~'';R*S'.'D'DT'J'.w!D6
H'M $ 2 25, P 	 !-   		s   B<C+ 'C+ +	C87C8c                P    | j                   r| j                   j                         S y)NT)r/   all_parents_staticr[   s    r9   r   zTask.all_parents_static  s    <<<<2244r:   c                    ddl m} | j                  r<t        | j                  |      r| j                  S | j                  j	                         S y )Nr   r   )r   r   r/   rF   get_first_parent_include)r4   r   s     r9   r   zTask.get_first_parent_include  s:    =<<$,,4||#<<88::r:   c                    | j                   }t        |t              s|j                   }t        |t              s|j                  S r   )r/   rF   r   _play)r4   r   s     r9   get_playzTask.get_play  s4    VU+^^F VU+||r:   )NNN)T)NNNNN)FF)F)6r   
__module____qualname____doc__r   r   rZ   r?   	async_valr&   changed_whendelayfailed_whenr_   r   loop_controlrX   DEFAULT_POLL_INTERVALpollregisterretriesuntilr`   r3   r=   rN   staticmethodrU   r\   rg   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   __classcell__)r8   s   @r9   r   r   /   sU   * (FDAD)h7F,QI/FDIL(Wa@E.64HK'F3D/G]hiL'E1;R;RSD+FH*u5G(VTBE -4HI%-  S S0	^9@g))b10'R" ,>
,&P
r:   N)4
__future__r   ansibler   rX   ansible.errorsr   r   r   r   +ansible.module_utils.common.text.convertersr	   ansible.module_utils.sixr
   ansible.parsing.mod_argsr   ansible.parsing.yaml.objectsr   r   ansible.plugins.loaderr   ansible.playbook.attributer   ansible.playbook.baser   ansible.playbook.blockr   !ansible.playbook.collectionsearchr   ansible.playbook.conditionalr   ansible.playbook.delegatabler   ansible.playbook.loop_controlr   ansible.playbook.notifiabler   ansible.playbook.roler   ansible.playbook.taggabler   ansible.utils.collection_loaderr   ansible.utils.displayr   ansible.utils.sentinelr   ansible.utils.varsr   __all__r~   r   r   r:   r9   <module>r     ss   $ # " l l A 1 5 N 0 C & ( > 4 4 5 2 & . C ) + +(
)q4h(8*k qr:   