o nnh@ @sddlmZddlmZddlmZddlmZddl m Z ddl m Z ddl mZddlmZdd lmZdd lmZdd lmZdd lmZdd lmZGddde e eeeeZdS)) annotationsN)AnsibleParserError)NonInheritableFieldAttribute)Base) Conditional)CollectionSearch) Delegatable)load_list_of_tasks) Notifiable)Role)Taggable)SentinelcseZdZededZededZededZd5fdd ZddZ d d Z d d Z d dZ e d6ddZe ddZfddZddZddZddZddZeZddZd7fdd Zd!d"Zd#d$Zd%d&Zd8d'd(Zd)d*Zd+d,Zd-d.Zd/d0Zd1d2Z d3d4Z!Z"S)9Blocklist)isadefaultNFcsL||_||_d|_d|_||_||_|r||_n|r||_tt|dSN) _play_role_parent _dep_chain _use_handlers _implicitsuperr__init__)selfplay parent_blockrole task_include use_handlersimplicit __class__A/usr/local/lib/python3.10/dist-packages/ansible/playbook/block.pyr-szBlock.__init__cCsd|jt||jfS)Nz BLOCK(uuid=%s)(id=%s)(parent=%s))_uuididrrr$r$r%__repr__<szBlock.__repr__cCs |j|jkSz object comparison based on _uuidr&rotherr$r$r%__eq__? z Block.__eq__cCs |j|jkSr*r+r,r$r$r%__ne__Cr/z Block.__ne__cCs*i}|jr ||jO}||jO}|S)z Blocks do not store variables directly, however they may be a member of a role or task include which does, so return those if present. )rget_varsvarscopyrall_varsr$r$r%r1Gs zBlock.get_varsc Cs0t| }t||||||d} | j|||dS)N)rrrrr r!)variable_managerloader)ris_block load_data) datarrrrr r6r7r!br$r$r%loadVs z Block.loadcCs.d}t|trdD] }||vrd}|Sq |S)NFblockrescuealwaysT) isinstancedict)dsr8attrr$r$r%r8\s zBlock.is_blockcsRt|s!t|trtt|t|dStt|t|gdStt||S)z If a simple task is given, an implicit block for that single task is created, which goes in the main portion of the block )r>)rr8rArrpreprocess_datarB)rrCr"r$r%rEfs  zBlock.preprocess_datac CNzt||j||jd|j|j|jdWSty&}ztd|j|dd}~ww)Nrr>rrr6r7r z7A malformed block was encountered while loading a blockobjorig_exc r rr_variable_manager_loaderrAssertionErrorr_dsrrDrCer$r$r% _load_blockt zBlock._load_blockc CrF)NrGz7A malformed block was encountered while loading rescue.rHrKrPr$r$r% _load_rescuerSzBlock._load_rescuec CrF)NrGz6A malformed block was encountered while loading alwaysrHrKrPr$r$r% _load_alwaysrSzBlock._load_alwayscCs$|r|jstd||jddSdS)Nz+'%s' keyword cannot be used without 'block')rI)r>rrO)rrDnamevaluer$r$r%_validate_alwayss zBlock._validate_alwayscCs,|jdur|jr |jSdS|jddSr)rr get_dep_chainr(r$r$r%rYs  zBlock.get_dep_chaincsdd}tt|}|j|_|j|_|jdur |jdd|_d|_|jr0|s0|jjdd|_|sM||jp7g||_||jp@g||_||j pIg||_ d|_ |j rW|j |_ | |S)NcSsg}|D]>}|jdd}|jr:|jjdd|_|j|kr ||_n|j}|jr6|j|kr6|j}|jr6|j|ks+||_n||_||q|S)NT)exclude_parent exclude_tasks)r3rappend) task_list new_block new_task_listtasknew_taskcur_objr$r$r%_dupe_task_lists   z#Block.copy.._dupe_task_listTr[) rrr3rrrrr>r?r@rvalidate)rrZr\rdnew_mer"r$r%r3s$  z Block.copycCs~t}|jD] }|dvrt||||<q||d<|jdur&|j|d<|jdur=|jjdd|d<|jjj |d<|S) z Override of the default serialize method, since when we're serializing a task we don't want to include the attribute list of tasks. r= dep_chainNrTr[parent parent_type) rB fattributesgetattrrYr serializerr3r#__name__)rr:rDr$r$r%rls    zBlock.serializec Csddlm}ddlm}|jD]}||vr"|dvr"t||||q|dd|_|d}|r.evaluate_and_append_taskcs>|jddd}|j|_|j|_|j|_|j|_|S)NT)rZr\)r3rr>r?r@)r>r_rr$r%r~s    z1Block.filter_tagged_tasks..evaluate_blockr$r4r$)r5rrrr%filter_tagged_tasksms zBlock.filter_tagged_taskscs fddfdd|S)Ncs6g}|D]}t|tr||q||q|Sr)rArrr])rrra)rr$r%rs   z1Block.get_tasks..evaluate_and_append_taskcs.|j}||j||j|Sr)r>rr?r@)r>rvrr$r%rs z'Block.get_tasks..evaluate_blockr$r(r$)rrr% get_taskss  zBlock.get_taskscCs*t|jdkpt|jdkpt|jdkS)Nr)lenr>r?r@r(r$r$r%rs*zBlock.has_taskscCs|jr|jStSr)rget_include_paramsrBr(r$r$r%rs zBlock.get_include_paramscCs8ddlm}|jrt|j|r|jjsdS|jSdS)a7 Determine if all of the parents of this block were statically loaded or not. Since Task/TaskInclude objects may be in the chain, they simply call their parents all_parents_static() method. Only Block objects in the chain check the statically_loaded value of the parent. rrnFT)rqrorrAr}all_parents_staticrror$r$r%rs  zBlock.all_parents_staticcCs2ddlm}|jrt|j|r|jS|jSdS)Nrrn)rqrorrAget_first_parent_includerr$r$r%rs   zBlock.get_first_parent_include)NNNNFF)NNNNFNN)FF)F)#rm __module__ __qualname__rrr>r?r@rr)r.r0r1 staticmethodr<r8rErRrTrUrX_validate_rescuerYr3rlrurzr~rrrrrr __classcell__r$r$r"r%r"s>       -& Ir) __future__ransible.constants constantsransible.errorsransible.playbook.attributeransible.playbook.baseransible.playbook.conditionalr!ansible.playbook.collectionsearchransible.playbook.delegatableransible.playbook.helpersr ansible.playbook.notifiabler ansible.playbook.roler ansible.playbook.taggabler ansible.utils.sentinelr rr$r$r$r%s