a ì)gX>ã@s®ddlmZmZmZeZdZddlZddlm Z ddl m Z m Z ddlmZddlmZddlmZdd lmZdd lmZdd lmZdd lmZeƒZGd d„deƒZdS)é)Úabsolute_importÚdivisionÚprint_functiona© 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)Ú AnsibleErrorÚAnsibleParserError)ÚHandler)Ú IncludedFile)Ú action_loader)Ú StrategyBase)ÚTemplar)Úto_text)ÚDisplaycs,eZdZdZ‡fdd„Z‡fdd„Z‡ZS)ÚStrategyModuleFcstt|ƒ |¡d|_dS)NF)ÚsuperrÚ__init__Ú _host_pinned)ÚselfZtqm©Ú __class__©úA/usr/lib/python3.9/site-packages/ansible/plugins/strategy/free.pyr6szStrategyModule.__init__c" sd}|jj}t|jƒ}| |j¡|jjdur8t d¡d}|rú|jj sú|  |¡}t|ƒdkrv|j  d¡d}qúd}|}g} ||} t  d| ¡|   ¡} |j| dd\} } tj d | | d tj d | | d | sê|j | d¡r|jj | d¡stj d | d d}|jj | d¡sB| rB|j | d¡s4tj d | d |jj|j| | |j|jd}|j||jdt|j|d}tj d| d zt| | j¡ƒ}Wn6tyÖ}ztd| j|d‚WYd}~n d}~00|dkr@d}|jD].}|rì| ¡rì|j j!| j!krì|d7}qìt  d|   ¡|f¡||kr@qŽd|j| <| "| j#| ¡zt$j| j%d| j&d}Wnt'yˆd}Yn0z,t(|j| j#dddd| _#tj d| d Wn"tyØtj d| d Yn0| | j)¡pø|oøt*|ddƒ}|r4|r*t*|ddƒr*td| j%| jd‚n t d¡t+| t,ƒs–| j-r–| j- .| ¡r–| j-j/dusz| j-j/r–| j-j/j0s–tj d | | d |j| =q‚| j%t1j2vrÂ|j3| ||| d!d|j| <np|j4rØ| 5| | ¡rB| j6rêt d"¡t+| t,ƒr|j  d#| ¡n|jj d$| dd%| 7| | ||¡|d8}~nt  d&| ¡|j8rb|dkrb|rb|}qŽ|d7}|t|ƒdkr€d}||kr‚qŽq‚| 9|¡}|  :|¡|t|ƒ7}| ;|¡td(d)„|Dƒƒ}t?ƒ}|D]”}t  d*|¡d}zb|j@r@| A|¡}|jB|j|j|jd+\}}nt+|j t,ƒ}|jC|||d,}d-d.„|jjDDƒ|_DWn†tEyˆ‚Ynrtyø}zX|j@r²tjFt(|ƒdd/|jGD]}d|jHd0<| I|jJ¡q¸WYd}~qøWYd}~n d}~00|D]~} |r,| jKD]} |jLdd…| _Mq| }!n(|jj|j|  N¡|j|jd1}|  O|¡}!|D] } | |jLvrX||  P|!¡qXqþt  d2|¡qø|D]} d|jjQ| j#<| R| ¡q”t  d3t|ƒ¡|D]} | S| || ¡qÊt  d4¡tT Ut1jV¡q<| W|¡}tXtY|ƒ Z|||¡S)5am 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 hostTZ!v2_playbook_on_no_hosts_remainingFznext free host: %s)Úpeekzfree host state: %s)Úhostzfree host task: %szthis host has work to dozgetting variables)ÚplayrÚtaskÚ_hostsÚ _hosts_all)r)ÚloaderZ variableszdone getting variablesz3Failed to convert the throttle value to an integer.)ÚobjZorig_excéztask: %s, same_tasks: %d)Z class_onlyZcollection_list)Zfail_on_undefinedÚempty)Z nonstringzdone templatingz!templating failed for some reasonZBYPASS_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.)rzˆUsing 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)Z target_hostzpUsing any_errors_fatal with the free strategy is not supported, as tasks are executed independently on each hostZ!v2_playbook_on_handler_task_startZv2_playbook_on_task_start)Zis_conditionalz%s is blocked, skipping for now)ÚiteratorrÚvariable_managercss|]}|gfVqdS)Nr)Ú.0rrrrÚ ìóz%StrategyModule.run..zcollecting new blocks for %s)rr#r)r"Ú is_handlercSsg|]}|jD]}|‘qqSr)Úblock)r$ÚbÚhrrrÚ r&z&StrategyModule.run..)Z wrap_textZfailed)rrrrz!done collecting new blocks for %sz@adding all collected blocks from %d included file(s) to iteratorz(done adding collected blocks to iterator)[Z_tqmZRUN_OKÚlenZ_workersZ_set_hosts_cacheZ_playZmax_fail_percentageÚdisplayZwarningZ _terminatedZget_hosts_leftZ send_callbackÚdebugZget_nameZget_next_task_for_hostZ_blocked_hostsÚgetZ_unreachable_hostsZ_variable_managerZget_varsZ _hosts_cacheZ_hosts_cache_allZadd_tqm_variablesr Z_loaderÚintÚtemplateÚthrottleÚ ExceptionrZ_dsÚis_aliveZ_taskZ_uuidZset_state_for_hostÚnamer ÚactionÚ collectionsÚKeyErrorr Úrun_onceÚgetattrÚ isinstancerZ_roleZhas_runZ _metadataZallow_duplicatesÚCZ _ACTION_METAZ _execute_metaZ_stepZ _take_stepZany_errors_fatalZ _queue_taskrZ_process_pending_resultsÚextendZupdate_active_connectionsr Zprocess_include_resultsÚdictÚsetZ_is_roleZ_copy_included_fileZget_block_listZ_load_included_fileÚhandlersrÚerrorZ_resultsZ_resultÚaddZ_hostr(rZnotified_hostsZget_first_parent_includeZfilter_tagged_tasksÚappendZ _failed_hostsZmark_host_failedZ add_tasksÚtimeÚsleepZDEFAULT_INTERNAL_POLL_INTERVALZ_wait_on_pending_resultsrrÚrun)"rr"Z play_contextZ last_hostÚresultZ workers_freeZ work_to_doZ hosts_leftZ starting_hostZ host_resultsrZ host_nameÚstaterZ task_varsZtemplarr2ÚeZ same_tasksZworkerr6r9ÚresultsZincluded_filesZ all_blocksZfailed_includes_hostsZ included_filer'Znew_irZ new_blocksZhandler_blocksÚrZ new_blockZ final_blockrrrrF:s6       &þ&        ÿÿ "$       ü  ý    $ ü    zStrategyModule.run)Ú__name__Ú __module__Ú __qualname__ZALLOW_BASE_THROTTLINGrrFÚ __classcell__rrrrr1s r)Z __future__rrrÚtypeZ __metaclass__Z DOCUMENTATIONrDZansiblerr<Zansible.errorsrrZansible.playbook.handlerrZansible.playbook.included_filer Zansible.plugins.loaderr Zansible.plugins.strategyr Zansible.templater Zansible.module_utils._textr Zansible.utils.displayrr-rrrrrÚs