o nnhMF@sddlmZdZddlmZddlmZmZm Z ddl m Z ddl m Z ddlmZddlmZdd lmZdd lmZdd lmZeZGd d d eZdS)) annotationsa name: linear short_description: Executes tasks in a linear fashion description: - Task execution is in lockstep per host batch as defined by C(serial) (default all). Up to the fork limit of hosts will execute each task at the same time and then the next series of hosts until the batch is done, before going on to the next task. version_added: "2.0" notes: - This was the default Ansible behaviour before 'strategy plugins' were introduced in 2.0. author: Ansible Core Team ) constants) AnsibleErrorAnsibleAssertionErrorAnsibleParserError)to_text)Handler) IncludedFile) action_loader) StrategyBase)Templar)Displaycs$eZdZddZfddZZS)StrategyModulec Cs8i}|D]}|j|dd\}}|dur||f||<q|sgSdd|D}d}|dkrWz|j|j} WntyEd|_|d7}Ynw|jd7_| j|vrSn|dks-tdg} |D]\}\}}| j|jkr{||j || ||fqa| j t j vr| jd d krd d |jjD|j|j|j<| S) z Returns a list of (host, task) tuples, where the task may be a noop task to keep the iterator in lock step across all hosts. T)peekNcSsh|]\}}|jqS)_uuid).0strrJ/usr/local/lib/python3.10/dist-packages/ansible/plugins/strategy/linear.py >sz9StrategyModule._get_next_task_lockstep..rzOBUG: There seems to be a mismatch between tasks in PlayIterator and HostStates. _raw_paramsflush_handlerscSg|] }|jD]}|qqSrblockrbhrrr Xz:StrategyModule._get_next_task_lockstep..)get_next_task_for_hostvalues all_taskscur_task IndexErrorrritemsset_state_for_hostnameappendactionC _ACTION_METAargsget_playhandlers) selfhostsiteratorstate_task_per_hosthoststatetask task_uuids _loop_cntr% host_tasksrrr_get_next_task_lockstep/sB       z&StrategyModule._get_next_task_lockstepc% sH|jj}d}||j|r|jjsztd||}tdd}d}|||}d}d} d} g} |D]P\} } |jjrEnFd}d}t | t sl| j rl| | |j}| | rl| j jjdurltd| q9td|jj|j| | |j|jd}|j||jdt|j|d }td || j}z tj|d| jd }Wn tyd }Ynw|tjvr| | | ||| | j!d d dvrd}| j"s|r| j#sd} n|j$r| r|%| rd} nd}n|rt&|ddp|| j'}zt(|j| j)dddd| _)Wnt*y#}ztd| j)d|WYd }~nd }~ww| j"s+|r1| j#s1d} |sMt | t rB|j+d| n |jj+d| ddd}d|j,| -<|.| | ||~t | t rp|rk| /n| 0| |run| |j1|t2dt3t4|jj5ddq9|rWq td|j6dkr| |7||8| t9j:| ||j|jd}t4|dkrtdtdt;d d!|D}td"g}t<}|D]}td#|j=d}z|j>r|?|}|j@|j|j|jd$\}}nt |jAt }|jB|||dd%}d&d'|jjCD|_Ctd(|D]P}|r5|jDD] } |jEd d | _Fq&|}n|jj|j|G|j|jd)}td*|H|}td+||I|D]} | |jEvrk|| J|q\qtd,WnOtKy~tLy}z:tjMt(|dd-|jND]&} d| jOd.<tP|| jOd/<|jjQRd0| jSj)|j+d1| |T| jSqWYd }~qd }~ww|jED] } |jjQRd2| j)q|j+d3|q|D]} d|jjU| j)<|V| qtd4|D] } |W| || q||jX|jY|jY<td5td6td7td8g}!g}"| D]}#|#Zr6|!J|#jSj)q&|#[rB|"J|#jSj)q&| re|!sM|"re|D]} | j)|!vrcd|jjU| j)<|V| qOtd9td:|jj\d urt4| dkr|jj\d;}$t4|jjU|j]|$kr|D]} | j)|!vrd|jjU| j)<|V| q|j+d<||jj^O}td=t4|jjU|j]|$ftd>td?||jjkrt4|jjUt4|krtd@|j+d<|WStdAWn t_t`fy}ztdB||jjaWYd }~Sd }~ww|r|jjrtbtc|d|||S)Cz The linear strategy is simple - get the next task and queue it for all hosts, then wait for the queue to drain before moving on to the next task Tz)getting the remaining hosts for this loopz.done getting the remaining hosts for this loopFz)'%s' skipped because role has already runzgetting variables)playr6r8_hosts _hosts_all)r=)loader variableszdone getting variables) class_onlycollection_listNr)noopreset_connectionend_host role_completerBYPASS_HOST_LOOP)fail_on_undefinedempty) nonstringzFailed to templalte task name (z"), ignoring error and continuing: !v2_playbook_on_handler_task_startv2_playbook_on_task_start)is_conditionalrg?) max_passesz>done queuing things up, now waiting for results queue to drainr)r4r@variable_managerz!we have included files to processzgenerating all_blocks datacss|]}|gfVqdS)Nr)rr6rrr sz%StrategyModule.run..zdone generating all_blocks datazprocessing included file: %s)r=rPr@)r4 is_handlerhandle_stats_and_callbackscSrrrrrrrr r!z&StrategyModule.run..z2iterating over new_blocks loaded from include file)r=r8r>r?zfiltering new block on tagsz done filtering new block on tagsz7done iterating over new_blocks loaded from include file) wrap_textfailedreasonfailuresv2_runner_on_failedokv2_playbook_on_includez7extending task lists for all hosts with included blockszdone extending task listszdone processing included fileszresults queue emptyzchecking for any_errors_fatalz"done checking for any_errors_fatalz checking for max_fail_percentagegY@!v2_playbook_on_no_hosts_remainingz$(%s failed / %s total )> %s max failz%done checking for max_fail_percentagezIchecking to see if all hosts have failed and the running result is not okz!^ not ok, so returning result nowz-done checking to see if all hosts have failedz%got IOError/EOFError in task loop: %s)e_tqmRUN_OK_set_hosts_cacher0 _terminateddisplaydebugget_hosts_leftr< isinstancer_role_get_cached_rolehas_run _metadataallow_duplicates_variable_managerget_vars _hosts_cache_hosts_cache_alladd_tqm_variablesr _loadertemplater+r r/ collectionsKeyErrorr,r-extend _execute_metar.any_errors_fatal ignore_errors_step _take_stepgetattrrun_oncerr) Exception send_callback_blocked_hostsget_name _queue_task clear_hosts remove_host_process_pending_resultsmaxintlen_workers_pending_results_wait_on_pending_resultsupdate_active_connectionsr process_include_resultsdictset _filename_is_role_copy_included_fileget_block_list_task_load_included_filer1rr>notified_hostsget_first_parent_includefilter_tagged_tasks get_tasksr*rrerror_results_resultstr_stats increment_hostadd _failed_hostsmark_host_failed add_tasksr$r% is_failedis_unreachablemax_fail_percentage batch_sizeRUN_FAILED_BREAK_PLAYIOErrorEOFErrorRUN_UNKNOWN_ERRORsuperrrun)%r2r4 play_contextresult work_to_do hosts_left callback_sentr; skip_rest choose_steprtresultsr6r8ryrole_obj task_varstemplar task_actionr+eincluded_files all_blocksincluded_tasksfailed_includes_hosts included_filerRnew_ir new_blockshandler_blocks new_block final_blockr failed_hostsunreachable_hostsres percentage __class__rrr\s            $    ,                                    $  zStrategyModule.run)__name__ __module__ __qualname__r<r __classcell__rrrrr-s-rN) __future__r DOCUMENTATIONansiblerr,ansible.errorsrrr+ansible.module_utils.common.text.convertersransible.playbook.handlerransible.playbook.included_filer ansible.plugins.loaderr ansible.plugins.strategyr ansible.templater ansible.utils.displayr r`rrrrrs