o nnhXA@sddlmZdZddlZddlmZddlmZm Z ddl m Z ddl m Z ddlmZdd lmZdd lmZdd lmZdd lmZeZGd ddeZdS)) annotationsa name: free short_description: Executes tasks without waiting for all hosts description: - Task execution is as fast as possible per batch as defined by C(serial) (default all). Ansible will not wait for other hosts to finish the current task before queuing more tasks for other hosts. All hosts are still attempted for the current task, but it prevents blocking new tasks for hosts that have already finished. - With the free strategy, unlike the default linear strategy, a host that is slow or stuck on a specific task won't hold up the rest of the hosts and tasks. version_added: "2.0" author: Ansible Core Team N) constants) AnsibleErrorAnsibleParserError)Handler) IncludedFile) action_loader) StrategyBase)Templar)to_text)Displaycs,eZdZdZfddZfddZZS)StrategyModuleFcstt||d|_dS)NF)superr __init__ _host_pinned)selftqm __class__H/usr/local/lib/python3.10/dist-packages/ansible/plugins/strategy/free.pyr4s zStrategyModule.__init__c$ sd}|jj}t|j}||j|jjdurtdd}|r|jj s| |}t|dkr;|j dd}nwd}|}g} d} ||} t d| | } |j| dd\} }tj d | | d tj d || d |sw|j| dr|jj| dstj d | d d}|jj| ds,|r,|j| ds%tj d | d |jj|j| ||j|jd}|j||jdt|j|d}tj d| d z t||j}Wnty}ztd|j|dd}~ww|dkrd}|jD]}|r|r|j j!|j!kr|d7}qt d| |f||krn8d|j| <|"| j#| t$|t%r0|&| z t'j|j(d|j)d}Wn t*yHd}Ynwzt+|j|j#dddd|_#tj d| d Wntyptj d| d Ynw||j,p|ot-|dd}|r|rt-|ddrtd|j(|jdtdt$|t%s|j.r|/||j}|0| r|j.j1j2durtj d || d |j| =qC|j(t3j4vr|j5r| d7} |d8}|j6|||| d!d|j| <n@|j7r|8|| r$|j9rtd"t$|t%r|j d#|n |jj d$|dd%|:| ||||d8}~nt d&| |j5r;|dkr;|r;|}n|d7}|t|dkrJd}||krPnqD|;|}| <||t|| 7}|=|t>j?| ||j|jd'}t|dkrt@d(d)|D}tA}|D]}t d*|d}z2|jBr|C|}|jD|j|j|jd+\}} nt$|j t%}|jE|||dd,}d-d.|jjFD|_FWnOtGyty}z:tjHt+|dd/|jID]&}!d|!jJd0<tK||!jJd1<|jjLMd2|!jNj#|j d3|!|O|!jNqWYd}~qd}~ww|jPD] } |jjLMd4| j#q|j d5||D]?}"|rE|"jQD] }|jPdd|_Rq6|"}#n|jj|j|"S|j|jd6}|"T|}#|D]} | |jPvrj|| U|#q[q.t d7|q|D]} d|jjV| j#<|W| qyt d8t||D] } |X| || qt d9tYZt3j[|r|jj r&|\|}t]t^|_|||S):am The "free" strategy is a bit more complex, in that it allows tasks to be sent to hosts as quickly as they can be processed. This means that some hosts may finish very quickly if run tasks result in little or no work being done versus other systems. The algorithm used here also tries to be more "fair" when iterating through hosts by remembering the last host in the list to be given a task and starting the search from there as opposed to the top of the hosts list again, which would end up favoring hosts near the beginning of the list. rNzsUsing max_fail_percentage with the free strategy is not supported, as tasks are executed independently on each hostT!v2_playbook_on_no_hosts_remainingFznext free host: %s)peekzfree host state: %s)hostzfree host task: %szthis host has work to dozgetting variables)playrtask_hosts _hosts_all)r)loader variableszdone getting variablesz3Failed to convert the throttle value to an integer.)objorig_excztask: %s, same_tasks: %d) class_onlycollection_list)fail_on_undefinedempty) nonstringzdone templatingz!templating failed for some reasonBYPASS_HOST_LOOPzThe '%s' module bypasses the host loop, which is currently not supported in the free strategy and would instead execute for every host in the inventory list.)r zUsing run_once with the free strategy is not currently supported. This task will still be executed for every host in the inventory list.z)'%s' skipped because role has already run) target_hostzpUsing any_errors_fatal with the free strategy is not supported, as tasks are executed independently on each host!v2_playbook_on_handler_task_startv2_playbook_on_task_start)is_conditionalz%s is blocked, skipping for now)iteratorrvariable_managercss|]}|gfVqdS)Nr).0rrrr sz%StrategyModule.run..zcollecting new blocks for %s)rr.r)r- is_handlerhandle_stats_and_callbackscSsg|] }|jD]}|qqSr)block)r/bhrrr sz&StrategyModule.run..) wrap_textfailedreasonfailuresv2_runner_on_failedokv2_playbook_on_include)rrrrz!done collecting new blocks for %sz@adding all collected blocks from %d included file(s) to iteratorz(done adding collected blocks to iterator)`_tqmRUN_OKlen_workers_set_hosts_cache_playmax_fail_percentagedisplaywarning _terminatedget_hosts_left send_callbackdebugget_nameget_next_task_for_host_blocked_hostsget_unreachable_hosts_variable_managerget_vars _hosts_cache_hosts_cache_alladd_tqm_variablesr _loaderinttemplatethrottle Exceptionr_dsis_alive_task_uuidset_state_for_hostname isinstancer remove_hostraction collectionsKeyErrorr run_oncegetattr_role_get_cached_rolehas_run _metadataallow_duplicatesC _ACTION_METAr _execute_meta_step _take_stepany_errors_fatal _queue_task_process_pending_resultsextendupdate_active_connectionsrprocess_include_resultsdictset_is_role_copy_included_fileget_block_list_load_included_filehandlersrerror_results_resultstr_stats increment_hostaddrr3notified_hostsget_first_parent_includefilter_tagged_tasksappend _failed_hostsmark_host_failed add_taskstimesleepDEFAULT_INTERNAL_POLL_INTERVAL_wait_on_pending_resultsrr run)$rr- play_context last_hostresult workers_free work_to_do hosts_left starting_host host_resultsmeta_task_dummy_results_countr host_namestater task_varstemplarrXe same_tasksworkerrbrerole_objresultsincluded_files all_blocksfailed_includes_hosts included_filer1new_ir new_blockshandler_blocksr new_block final_blockrrrr8sv       "              |              gzStrategyModule.run)__name__ __module__ __qualname__ALLOW_BASE_THROTTLINGrr __classcell__rrrrr /s r ) __future__r DOCUMENTATIONransiblerrlansible.errorsrransible.playbook.handlerransible.playbook.included_fileransible.plugins.loaderransible.plugins.strategyr ansible.templater +ansible.module_utils.common.text.convertersr ansible.utils.displayr rEr rrrrs