a )g%y@sddlmZmZmZeZddlZddlmZm Z ddl m Z ddl mZddlmZddlmZddlmZdd lmZeZgd ZGd d d eZGd dde ZGdddZGdddZdS))absolute_importdivisionprint_functionN)IntEnumIntFlag) constants)AnsibleAssertionError)boolean)Block)Task)Display) PlayIteratorIteratingStates FailedStatesc@s$eZdZdZdZdZdZdZdZdS)rrN) __name__ __module__ __qualname__SETUPTASKSRESCUEALWAYSHANDLERSCOMPLETErrB/usr/lib/python3.9/site-packages/ansible/executor/play_iterator.pyr(s rc@s$eZdZdZdZdZdZdZdZdS)rrrrrN) rrrNONErrrrrrrrrr1s rc@s<eZdZddZddZddZddZd d Zd d Zd S) HostStatecCsv|dd|_g|_d|_d|_d|_d|_d|_tj|_ t j |_ d|_ d|_d|_d|_d|_d|_d|_d|_dS)NrTF)_blockshandlers cur_blockcur_regular_taskcur_rescue_taskcur_always_taskcur_handlers_taskrr run_staterr" fail_statepre_flushing_run_stateupdate_handlers pending_setuptasks_child_staterescue_child_statealways_child_state did_rescuedid_start_at_task)selfblocksrrr__init__;s"zHostState.__init__cCs d|jS)Nz HostState(%r))r$r5rrr__repr__OszHostState.__repr__cCsDd|j|j|j|j|j|j|j|j|j|j |j |j |j |j |jfS)NaHOST STATE: block=%d, task=%d, rescue=%d, always=%d, handlers=%d, run_state=%s, fail_state=%s, pre_flushing_run_state=%s, update_handlers=%s, pending_setup=%s, tasks child state? (%s), rescue child state? (%s), always child state? (%s), did rescue? %s, did start at task? %s)r&r'r(r)r*r+r,r-r.r/r0r1r2r3r4r8rrr__str__Rs$zHostState.__str__cCs6t|tsdSdD]}t||t||krdSqdS)NF)r$r&r'r(r)r*r+r,r-r.r/r0r1r2T) isinstancer#getattr)r5otherattrrrr__eq__hs  zHostState.__eq__cCs |j|jSN)r$r&r8rrrget_current_blockuszHostState.get_current_blockcCst|j}|jdd|_|j|_|j|_|j|_|j|_|j|_|j|_|j |_ |j |_ |j |_ |j |_ |j |_ |j|_|jdur|j|_|jdur|j|_|jdur|j|_|Sr@)r#r$r%r&r'r(r)r*r+r,r-r.r/r3r4r0copyr1r2)r5Z new_staterrrrBxs*       zHostState.copyN) rrrr7r9r:r?rArBrrrrr#:s  r#c@seZdZd4ddZddZddZd5dd Zd d Zd d ZddZ ddZ ddZ ddZ ddZ eddddZddZddZd d!Zd"d#Zd$d%Zed&d'Zeed(d)d*Zeedd+d,d-Zeedd.d/d0Zeedd1d2d3ZdS)6r FcCsN||_g|_||_t|jd}d|_t|d}d|_d|_d|_i|_ |jj sVdg|_ dD]$} t |j| d} | durZ| |j | <qZ| |jj |jjdur|jjdd|_|g|_||}|j|||_|jD]2} | |} | r|j| |j| qd d |jjD|_i|_d} |j|jj|jjd }t||_|D]}||jt |jd |j!durT|sT|j"|d d\}}|j#t$j%krq |j|j!ks|jrt&&|j|j!s|'|j!kst&&|'|j!rd } q ||j|q| rTd |j|j_(t$j)|j|j_#qT| r>d|_!d|_*d|_+dS)N)playFblock gather_factszansible.builtin.gather_factszGathering Factsalways)Z gather_subsetZgather_timeoutZ fact_pathcSsg|]}|jD]}|qqSrrD.0bhrrr z)PlayIterator.__init__..)orderr6T)peekr),_playr$_variable_managerr Zrun_oncer actionZresolved_actionnameargstagsr< set_loaderZ_loaderZ_included_conditionalZwhenrEZfilter_tagged_tasksappendZ get_tasksZ all_taskscompile has_tasksextendr% _host_statesZ get_hostshostsrNlenZ batch_sizeset_state_for_hostr#Z start_at_taskget_next_task_for_hostr+rrfnmatchZget_namer4rZend_playZcur_task)r5Z inventoryrCZ play_contextZvariable_managerZall_varsZ start_at_done setup_blockZ setup_taskoptionvaluerEZ new_blockZstart_at_matchedZbatchhoststaskrrrr7sl          ( zPlayIterator.__init__cCs0|j|jvr ||jtgd|j|jS)NrO)rTr\r_r#rBr5rerrrget_host_states zPlayIterator.get_host_statecCstjddddS)NzlPlayIterator.cache_block_tasks is now noop due to the changes in the way tasks are cached and is deprecated.HzG@versiondisplayZ deprecated)r5rErrrcache_block_tasksszPlayIterator.cache_block_taskscCstd|j||}d}|jtjkrBtd|j|dfS|j||d\}}|sf||j|td|jtd|td|||fS)Nz!getting the next task for host %sz$host %s is done iterating, returningrez"done getting next task for host %sz ^ task is: %sz ^ state is: %s) rndebugrTrir+rr_get_next_task_from_stater_)r5rerPrfrgrrrr`s  z#PlayIterator.get_next_task_for_hostcCs:d}z|j|j}Wn"ty6tj|_|dfYS0|jtjkr6|jsd|_tj }|j j duprt |j j dd}|dkr|s|dkrt |j j dds|dkr|r|j j|jidds|jd}|rt|jdkr|jd}nHd|_tj|_|js(|jd 7_d|_d|_d|_d|_d|_d|_n|jtjkr,|jrRd|_|jr|j|j|d \|_}||jrd|_||n"|dus|jjtjkr(d|_qnt||rtj|_n^|jt|jkrtj |_nB|j|j}t!|t"rt#|gd |_tj|j_d}|jd 7_n|jtjkr:|jr|j|j|d \|_}||jrxd|_||n"|dus|jjtjkr6d|_qn|j$t%j@t%jkrtj |_n||jt|j&krt|j&dkrt%j'|_$tj |_d|_(nB|j&|j}t!|t"r(t#|gd |_tj|j_d}|jd 7_n|jtj krZ|jr|j|j|d \|_}||jrd|_||n"|dus|jjtjkrXd|_qn|jt|j)kr|j$t%j'krtj|_n@|jd 7_d|_d|_d|_tj|_d|_d|_d|_d|_(nB|j)|j}t!|t"rJt#|gd |_tj|j_d}|jd 7_n|jtj*kr|j+r|j,dd|_,d|_+d|_-|j$t%j*@t%j*krd|_+tj|_n`z|j,|j-}Wn,tyd}|j.|_d|_+Yq(Yn 0|j-d 7_-|/|rq(qn|jtjkr(|dfS|rq2q||fS) NTF)strictZimplicitZexplicitZsmartZ_ansible_facts_gatheredrrrprO)0r$r& IndexErrorrrr+rr/CZDEFAULT_GATHERINGrQrFr rRZ _fact_cachegetrTrZr^rErr4r'r(r)r0r1r2rr_check_failed_state_set_failed_staterrr;r r#r,rrescuer"r3rGrr.r%r*r-Zis_host_notified)r5staterergrEZ gatheringZimpliedrbrrrrr s                          z&PlayIterator._get_next_task_from_statecCs|jtjkr(|jtjO_tj|_nl|jtjkr|jdurN||j|_nH|jtjO_|j |j j rvtj |_n |j |j j rtj|_ntj|_n|jtj kr|jdur||j|_n0|jtj O_|j |j j rtj|_ntj|_n|jtjkr4|jdur||j|_n|jtjO_tj|_n`|jtjkr|jtjO_d|_|j |j j rrtj |_n"|j |j j rtj|_ntj|_|S)NT)r+rrr,rrrr0rxr$r&ryrrGrr1r2rr.r5rzrrrrxsB               zPlayIterator._set_failed_statecCsV||}td||f||}td|||j||jj|jdS)Nz)marking host %s failed, current state: %sz^ failed state is now: %s) rirnrqrxr_rTrQZ_removed_hostsrXr5rerfrrrmark_host_faileds   zPlayIterator.mark_host_failedcstfddjDS)Nc3s$|]\}}|r|dfVqdS)TN)rw)rIrerzr8rr rMz0PlayIterator.get_failed_hosts..)dictr\itemsr8rr8rget_failed_hostsszPlayIterator.get_failed_hostscCs"|dur dS|jtjkr(||jr(dS|jtjkrD||jrDdS|jtjkrf|jt j@t jkrfdS|jt j kr|jtjkr|jt j@dkrdS|jtjkr|jt j@dkrdS|j o|jt j@dk SnR|jtj kr||j r|j|j}t|jdkr|jt j@dkrdSdSdS)NFTr)r+rrrwr1rr2rr,rr"r3rr0r$r&r^ry)r5rzr&rrrrws(  "z PlayIterator._check_failed_statecCs||}||Sr@)rirwr|rrr is_faileds zPlayIterator.is_failedcCs|||jdSr@)_clear_state_errorsget_state_for_hostrTrhrrrclear_host_errors szPlayIterator.clear_host_errorsN)rzreturncCsRtj|_|jdur ||jn.|jdur8||jn|jdurN||jdSr@)rr"r,r0rr1r2r{rrrr#s   z PlayIterator._clear_state_errorscCsj|jtjkr"|jdur"||jS|jtjkrD|jdurD||jS|jtjkrf|jdurf||jS|S)z_ Finds the active state, recursively if necessary when there are child states. N) r+rrr0get_active_staterr1rr2r{rrrr-s   zPlayIterator.get_active_statecCs`|jtjkr|jrdS|jdur0||jS|jdurF||jS|jdur\||jSdS)z Given the current HostState state, determines if the current block, or any child blocks, are in rescue mode. TNF) r+rrrAryr0is_any_block_rescuingr1r2r{rrrr9s      z"PlayIterator.is_any_block_rescuingcCstjddddS)NzlPlayIterator.get_original_task is now noop due to the changes in the way tasks are cached and is deprecated.rjrk)NNrm)r5rergrrrget_original_taskHs zPlayIterator.get_original_taskcCs|jtjkr|jtjks|s |S|jtjkr|jrD||j||_nJ|j|j  }|j d|j }|j |j d}||||_ ||j|j <n|jtj kr|jr||j||_nJ|j|j  }|jd|j}|j|jd}||||_||j|j <n|jtjkrx|jr,||j||_nJ|j|j  }|jd|j}|j|jd}||||_||j|j <n*|jtjkrdd|D|j|j|j<|S)NcSsg|]}|jD]}|qqSrrDrHrrrrLqrMz9PlayIterator._insert_tasks_into_state..)r,rr"r+rrr0_insert_tasks_into_stater$r&rBrEr'rr1ryr(rr2rGr)rr%r*)r5rz task_listZ target_blockbeforeZafterrrrrPs: z%PlayIterator._insert_tasks_into_statecCs ||j||||dSr@)r_rTrri)r5rerrrr add_tasksuszPlayIterator.add_taskscCs|jSr@r\r8rrr host_statesxszPlayIterator.host_states)hostnamercCs |j|Sr@r)r5rrrrr|szPlayIterator.get_state_for_host)rrzrcCs(t|tstdt|||j|<dS)Nz-Expected state to be a HostState but was a %s)r;r#rtyper\)r5rrzrrrr_s zPlayIterator.set_state_for_host)rr+rcCs*t|tstdt|||j|_dS)Nz5Expected run_state to be a IteratingStates but was %s)r;rrrr\r+)r5rr+rrrset_run_state_for_hosts z#PlayIterator.set_run_state_for_host)rr,rcCs*t|tstdt|||j|_dS)Nz3Expected fail_state to be a FailedStates but was %s)r;rrrr\r,)r5rr,rrrset_fail_state_for_hosts z$PlayIterator.set_fail_state_for_host)F)F)rrrr7riror`rrrxr}rrwrrr#rrrrrrpropertyrstrrr_rrrrrrrrr s0 V  E)  % r )Z __future__rrrrZ __metaclass__raenumrrZansiblerruZansible.errorsrZ)ansible.module_utils.parsing.convert_boolr Zansible.playbook.blockr Zansible.playbook.taskr Zansible.utils.displayr rn__all__rrr#r rrrrs        V