
    VhYF                        d dl mZ dZd dlmZ d dlmZmZm	Z	 d dl
mZ d dlmZ d dlmZ d dlmZ d d	lmZ d d
lmZ d dlmZ  e       Z G d de      Zy)    )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)AnsibleErrorAnsibleAssertionErrorAnsibleParserError)to_text)Handler)IncludedFile)action_loader)StrategyBase)Templar)Displayc                  $     e Zd Zd Z fdZ xZS )StrategyModulec                   i }|D ]"  }|j                  |d      \  }}|||f||<   $ |sg S |j                         D ch c]  \  }}|j                   }	}}d}
|
dk  rD	 |j                  |j                     }|xj                  dz  c_        |j                  |	v rn|
dk  rDt        d      g }|j                         D ]Q  \  }\  }}|j                  |j                  k(  s#|j                  |j                  |       |j                  ||f       S |j                  t        j                  v rv|j                  j                  d      dk(  rX|j                   j"                  D cg c]  }|j$                  D ]  }|  c}}|j                  |j                  |j                   |S c c}}w # t
        $ r d|_        |
dz  }
Y )w xY wc c}}w )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)peekr      zOBUG: There seems to be a mismatch between tasks in PlayIterator and HostStates._raw_paramsflush_handlers)get_next_task_for_hostvalues_uuid	all_taskscur_task
IndexErrorr   itemsset_state_for_hostnameappendactionC_ACTION_METAargsget_playhandlersblock)selfhostsiteratorstate_task_per_hosthoststatetaskst
task_uuids	_loop_cntr   
host_tasksbhs                  O/home/dcms/DCMS/lib/python3.12/site-packages/ansible/plugins/strategy/linear.py_get_next_task_lockstepz&StrategyModule._get_next_task_lockstep/   s    ! 	8D"99$T9JKE4,14K#D)	8
 #I*=*D*D*FG$!QaggG
G	1n	#--h.?.?@ !!Q&!>>Z/ 1n (a  
#6#<#<#> 	0D-5$~~+++DIIu=!!4,/	0
 ??ann,1B1B=1QUe1eRZR`R`RiRiF{QstszszF{noqF{qF{Hx001B1BC9 H
  $%!Q	* G|s   F*"F0 )G0G	G	c                R   | j                   j                  }d}| j                  |j                         |rT| j                   j                  s=	 t
        j                  d       | j                  |      }t
        j                  d       d}d}| j                  ||      }d}d}	d}
g }|D ]  \  }}| j                   j                  r nd}d}t        |t              st|j                  rh| j                  ||j                        }|j                  |      r;|j                  j                  j                  du rt
        j                  d|z         t
        j                  d       | j                   j#                  |j                  ||| j$                  | j&                        }| j)                  ||j                         t+        | j,                  |	      }t
        j                  d
       |j/                  |j0                        }	 t3        j4                  |d|j6                        }|t:        j<                  v rc|j?                  | jA                  ||||             |jB                  j5                  dd      dvrd}|jD                  s|r1|jF                  s$d}
n | jH                  r|	r| jK                  |      rd}	nd} n|xr tM        |dd      xs |j/                  |jN                        }	 tQ        |j/                  |jR                  d      d      |_)        |jD                  s|r|jF                  sd}
|sMt        |t              r| j                   jW                  d|       n| j                   jW                  d|d       d}d| jX                  |j[                         <   | j]                  ||||       ~t        |t              r$|r|j_                          n|ja                  |       |r nX|j?                  | jc                  |te        dtg        ti        | j                   jj                        dz                            |r!t
        j                  d       | jl                  dkD  r |j?                  | jo                  |             | jq                  |       ts        jt                  ||| j,                  | j                         }ti        |      dkD  rt
        j                  d       t
        j                  d       tw        d  |D              }t
        j                  d!       g }ty               }|D ]m  }t
        j                  d"|jz                  z         d}	 |j|                  rG| j                  |      }|j                  |j                  | j                   | j,                  #      \  }}n/t        |j                  t              }| j                  |||d$      }|j                  j                  D cg c]  }|j                  D ]  }|  c}}|_C        t
        j                  d%       |D ]  } |r(| j                  D ]  }|j                  dd |_F         | }!n| j                   j#                  |j                  | j                         | j$                  | j&                  &      }t
        j                  d'       | j                  |      }!t
        j                  d(       |j?                  |!j                                |D ]%  }||j                  v s||   j                  |!       '  t
        j                  d)       |j                  D ]2  }| j                   j                  j                  d*|jR                         4 | j                   jW                  d+|       p |D ]6  }d| j                   j                  |jR                  <   |j                  |       8 t
        j                  d1       |D ]  }|j                  |||           ||j                  |j                  |j                   t
        j                  d2       t
        j                  d3       t
        j                  d4       t
        j                  d5       g }#g }$|D ]n  }%|%j                         r&|#j                  |%j                  jR                         9|%j                         sJ|$j                  |%j                  jR                         p |
rN|#s|$rJ|D ]E  }|jR                  |#vsd| j                   j                  |jR                  <   |j                  |       G t
        j                  d6       t
        j                  d7       |j                  j                  ti        |      dkD  r|j                  j                  d8z  }&ti        | j                   j                        |j                  z  |&kD  r~|D ]E  }|jR                  |#vsd| j                   j                  |jR                  <   |j                  |       G | j                   jW                  d9       || j                   j                  z  }t
        j                  d:ti        | j                   j                        d;|j                  d<|&d=       t
        j                  d>       t
        j                  d?       || j                   j                  k7  r]ti        | j                   j                        ti        |      k\  r2t
        j                  d@       | j                   jW                  d9       |S t
        j                  dA       |r| j                   j                  s=t        t        |   |||      S # t8        $ r d}Y 	w xY w# tT        $ r0}t
        j                  d|jR                   d|        Y d}~d}~ww xY wc c}}w # t        $ r  t        $ r}t
        j                  tQ        |      d,       |j                  D ]  }"d|"j                  d-<   t        |      |"j                  d.<   | j                   j                  j                  d/|"j                  jR                         | j                   jW                  d0|"       |j                  |"j                          Y d}~d}~ww xY w# t        t        f$ r8}t
        j                  dB|z         | j                   j                  cY d}~S d}~ww xY w)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 runzgetting variables)playr,   r.   _hosts
_hosts_all)r9   )loader	variableszdone getting variables)
class_onlycollection_listNr   )noopreset_connectionend_hostrole_completer   end_roleBYPASS_HOST_LOOP)fail_on_undefinedempty)	nonstringzFailed to templalte task name (z"), ignoring error and continuing: !v2_playbook_on_handler_task_startv2_playbook_on_task_start)is_conditionalr   g?)
max_passesz>done queuing things up, now waiting for results queue to drainr   )r*   r<   variable_managerz!we have included files to processzgenerating all_blocks datac              3  $   K   | ]  }|g f 
 y w)N ).0r,   s     r6   	<genexpr>z%StrategyModule.run.<locals>.<genexpr>   s     %HTtRj%Hs   zdone generating all_blocks datazprocessing included file: %s)r9   rM   r<   )r*   
is_handlerhandle_stats_and_callbacksz2iterating over new_blocks loaded from include file)r9   r.   r:   r;   zfiltering new block on tagsz done filtering new block on tagsz7done iterating over new_blocks loaded from include fileokv2_playbook_on_include)	wrap_textfailedreasonfailuresv2_runner_on_failedz7extending task lists for all hosts with included blockszdone extending task listszdone processing included fileszresults queue emptyzchecking for any_errors_fatalz"done checking for any_errors_fatalz checking for max_fail_percentageg      Y@!v2_playbook_on_no_hosts_remaining(z
 failed / z
 total )> z	 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_tqmRUN_OK_set_hosts_cacher%   _terminateddisplaydebugget_hosts_leftr7   
isinstancer	   _role_get_cached_rolehas_run	_metadataallow_duplicates_variable_managerget_vars_hosts_cache_hosts_cache_alladd_tqm_variablesr   _loadertemplater    r   r$   collectionsKeyErrorr!   r"   extend_execute_metar#   any_errors_fatalignore_errors_step
_take_stepgetattrrun_oncer   r   	Exceptionsend_callback_blocked_hostsget_name_queue_taskclear_hostsremove_host_process_pending_resultsmaxintlen_workers_pending_results_wait_on_pending_resultsupdate_active_connectionsr
   process_include_resultsdictset	_filename_is_role_copy_included_fileget_block_list_task_load_included_filer&   r'   r:   notified_hostsget_first_parent_includefilter_tagged_tasks	get_tasksr   _stats	incrementr   r   error_results_resultstr_hostadd_failed_hostsmark_host_failed	add_tasksr   r   	is_failedis_unreachablemax_fail_percentage
batch_sizeRUN_FAILED_BREAK_PLAYIOErrorEOFErrorRUN_UNKNOWN_ERRORsuperr   run)(r(   r*   play_contextresult
work_to_do
hosts_leftcallback_sentr3   	skip_restchoose_stepru   resultsr,   r.   rz   role_obj	task_varstemplartask_actionr    eincluded_files
all_blocksincluded_tasksfailed_includes_hostsincluded_filerR   new_ir
new_blockshandler_blocksr4   r5   	new_blockfinal_blockrfailed_hostsunreachable_hostsres
percentage	__class__s(                                          r6   r   zStrategyModule.run\   sM    !!
hnn-!6!6~3IJ!00:
NO !&"
!99*hO
 "	" $) $. RCLT4yy,,$H!%J &dG4#'#8#8x~~#N#++D1djj6J6J6[6[_d6d#MM*UX\*\]$MM"56 $ 6 6 ? ?X^^Z^eiGKGXGXeiezez !@ !|I**98>>*J%T\\YOGMM":; #*"2"24;;"?K&!.!2!2;4aeaqaq!r #ann4  t'9'9$hX\']^99===  F]  ]'+H 11XtGYGY/3,  ::+#t4.3,0	 %#)#Xgf>PRW.X#{\c\l\lmqmzmz\{~(/0@0@^c0@0dpw(xDI !11XtGYGY/3,,)$8 $		 7 78[]a b $		 7 78SUYjo 7 p,0M?C++DMMO<((tYM%!$0# ,,. ,,T2  NN4#@#@VYZ[]`adeienenewewax{~a~]  WA#@  $B  CeRCj ^_((1,NN4#@#@#JK..w7!-!E!E%<<%)%;%;	" ~&*MM"EFMM">?!%%HZ%H!HJMM"CD%'N,/E))7 @]&D}G^G^&^_%*
=],55)-)A)A-)P=C=R=R)1595K5K+/<< >S >" :
N .88K8KW-U
-1-E-E$1-5/9?D	 .F ."
 =ENN<S<S0eq]^]d]d0eXY0e0eH-#MM*^_-7 M	#-09 %V>K>R>RST>U(;%V2;K040F0F0O0O-5^^-6-O-O-Q/3/@/@373H3H	 1P 1&I %,MM2O$P2;2O2OPY2ZK$+MM2T$U . 5 5k6K6K6M N,6 !MD'+}/C/C'C(24(8(?(?(L!M%M, $MM*cd )6(<(< L $		 0 0 : :4 KL II334Lm\A@]D !6 8=A		//		: 11$78 MM"[\ * C **4D1ABC O]H&&x'8'89J9JKMM"=>MM"BC34=>!$&!" AC}}$++CIINN;++-)00@	A $9J * <99L8AEDII33DII>$55d;< BC@A>>55Ac'lUVFV!)!C!Ce!KJDII334x7J7JJjX$. @D  $yy<EI		 7 7		 B ( 9 9$ ?@ 		//0ST$))"A"AAMMCPTPYPYPgPgLhjrj}j}  @J  #K  LEFijTYY---#dii6M6M2NRUV`Ra2aMM"EFII++,OP!MMNw !6!6J ^T.xvNNe $ & "&&2  ) ~#MM,KDII;Vxyzx{*|}}~Z 1f4  2 "!+ C#MM'!*MF%2%;%; C6:		( 369!f		( 3 $		 0 0 : ::qww|| T $		 7 78Mq Q 5 9 9!'' BCCP X& 3EIJyy2223s   F:s "n"-C
s 8-n4%D/s Ds /Bo6
o0$Do6*-o6Fs *A s +C!s Es s "n1-s 0n11s 4	o-=%o("s (o--s 0o66sC	ss ss t&.-t!t&!t&)__name__
__module____qualname__r7   r   __classcell__)r   s   @r6   r   r   -   s    +ZRO RO    r   N)
__future__r   DOCUMENTATIONansibler   r!   ansible.errorsr   r   r   +ansible.module_utils.common.text.convertersr   ansible.playbook.handlerr	   ansible.playbook.included_filer
   ansible.plugins.loaderr   ansible.plugins.strategyr   ansible.templater   ansible.utils.displayr   ra   r   rO   r   r6   <module>r      sH   " # # R R ? , 7 0 1 $ )
)AO\ AOr   