관리-도구
편집 파일: linear.cpython-39.opt-1.pyc
a �����)g�O����������������������@���s����d�dl�mZmZmZ�eZdZd�dlmZ �d�dl mZmZm Z �d�dlmZmZ�d�dlmZ�d�dlmZ�d�dlmZ�d�d lmZ�d�d lmZ�d�dlmZ�d�dlmZ�d�d lm Z �e ��Z!G�dd��de�Z"dS�)�����)�absolute_import�division�print_functiona�� 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)�IteratingStates�FailedStates)�to_text)�Handler)�IncludedFile)�Task)� action_loader)�StrategyBase)�Templar)�Displayc�����������������������s0���e�Zd�Z��fdd�Zdd��Z��fdd�Z���ZS�)�StrategyModulec��������������������s���t���j|i�|���d|�_d�S�)NF)�super�__init__�_in_handlers)�self�args�kwargs�� __class__���C/usr/lib/python3.9/site-packages/ansible/plugins/strategy/linear.pyr���3���s����zStrategyModule.__init__c����������� ������C���s���t���}d|_d|jd<�d|_|�|jj��i�}|D�]*}|j|dd�\}}|dur2||f||<�q2|spdd��|D��S�|�jr�t t d d ��dd��|���D����s�d |�_|�jr�tdd��|���D���}nzdd��|���D��} d} | dk�r,z|j |j�}W�n"�t�y���d|_| d7�} Y�q�0�|�jd7��_|j| v�rАq4q�td��g�}|���D�]d\}\}}|�j�r`||jk�sv|�j�s�|j|jk�r�|�|j|��|�||f��n|�||f���q@|�j�s�|jtjv��r�|j�d�dk�r�d|�_|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. �meta�noop�_raw_paramsT��peekNc�����������������S���s���g�|�]}|d�f�qS��Nr���)�.0�hr���r���r���� <listcomp>L��������z:StrategyModule._get_next_task_lockstep.<locals>.<listcomp>c�����������������S���s ���|�t�jkS�r#���)r ����HANDLERS)Zrsr���r���r����<lambda>O���r'���z8StrategyModule._get_next_task_lockstep.<locals>.<lambda>c�����������������s���s���|�]\}}|j�V��qd�S�r#���)� run_state)r$����s�_r���r���r���� <genexpr>P���r'���z9StrategyModule._get_next_task_lockstep.<locals>.<genexpr>Fc�����������������s���s$���|�]\}}|j�tjkr|jV��qd�S�r#���)r*���r ���r(����cur_handlers_task�r$���r+����tr���r���r���r-���U���s����c�����������������S���s���g�|�]\}}|j��qS�r���)�_uuidr/���r���r���r���r&���Z���r'���r�������zOBUG: There seems to be a mismatch between tasks in PlayIterator and HostStates.�flush_handlers)r����actionr���Zimplicit� set_loader�_play�_loader�get_next_task_for_hostr����any�filter�values�min� all_tasks�cur_task� IndexErrorr1���r����itemsr.���Zset_state_for_host�name�append�C�_ACTION_META�get) r����hosts�iteratorZ noop_taskZstate_task_per_host�host�state�taskZlowest_cur_handlerZ task_uuidsZ _loop_cntr>���� host_tasksr���r���r����_get_next_task_lockstep9���sd���� �� �� ��z&StrategyModule._get_next_task_lockstepc�����������(���������s���|�j�j}d}|��|j��|�rz|�j�j�sz�zt�d��|��|�}t�d��d}d}|��||�}d}d} d} g�}|D��]�\}} | s�qr|�j�jr���q4d}d}t | t �s�| jr�| j�|�r�| jj du�s�| jj r�| jj js�t�d| ���qrt�d��|�jj|j|| |�j|�jd�}|�j||jd ��t|�j|d �}t�d��|�| j�}ztj|d| jd�}W�n�t�yj���d}Y�n0�|tjv��r�|�|��| |||���| j �d d�dv�r�d}| j!�s�|�r�| j"�s�d} �n8|�j#�r�| �r�|��$| ��r�d} n d}��q4|�| j%��p|�ot&|dd�}| j!�s|�r(| j"�s(d} |�s�t�d��| j'}t�d��z(t(|j| j'dd�dd�| _'t�d��W�n�t)�y����t�d��Y�n0�t�d��t | t ��r�|�j��*d| ��n|�j�j*d| dd��|| _'d}t�d��d|�j+|�,��<�|��-|| ||��~|�r��q4|�|�j.|t/dt0t1|�j�j2�d���d���qr|�r>W�qt�d��|�j3d k�rd|�|��4|���|��5|��t6j7|||�j|�jd!�}t1|�d k�rt�d"��t�d#��t8d$d%��|D���}t�d&��g�}t9��}|D��]�}t�d'|j:���d}�z|j;�r|��<|�}|j=|j|�j|�jd(�\}}nt |j>t �}|�j?|||d)�}d*d+��|jj@D��|_@t�d,��|D�]�}|�r�|jAD�]} |jBdd��| _C�qj|}nJ|�jj|j|�D��|�j|�jd-�}t�d.��|�E|�}t�d/��|�|�F����|D�] }||jBv��r�||��G|���qqZt�d0��W�n��tH�y�����Y�nr�tI�y��}�zX|j;�rHtjJt(|�dd1��|jKD�]} d| jLd2<�|�M| jN���qNW�Y�d}~�q�W�Y�d}~n d}~0�0��q�|D�]}d|�j�jO|j'<�|�P|���q�t�d3��|D�]}|�Q|||����q�||jR|jS|jS�<�t�d4��t�d5��t�d6��t�d7��g�}!g�}"|D�]V}#|#�T���sB|#j>jtjv��r`|�T|#jN��r`|!�G|#jNj'��n|#�U���r$|"�G|#jNj'���q$| �rt1|!�d k�s�t1|"�d k�rtVtWjXtWjYg�}$|D�]h}|jZ|dd8�\}%}&|�[|%�}%|%j\|$v�s�|%j\tWjXk�r�|%j]t^jX@�d k�r�d|�j�jO|j'<�||�j�j_O�}�q�t�d9��t�d:��|jj`du�r�t1|�d k�r�|jj`d;�}'t1|�j�jO�|ja�|'k�r�|D�]*}|j'|!v�rtd|�j�jO|j'<�|�P|���qt|�j��*d<��||�j�j_O�}t�d=t1|�j�jO�|ja|'f���t�d>��t�d?��||�j�jk�r*t1|�j�jO�t1|�k�r*t�d@��|�j��*d<��|W�S�t�dA��W�q�tbtcf�yv�}�z"t�dB|���|�j�jdW��Y�d}~S�d}~0�0�qtetf|���g|||�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 loopFNz)'%s' skipped because role has already runzgetting variables)�playrH���rJ����_hosts� _hosts_all)rM���)�loaderZ variableszdone getting variables)Z class_onlyZcollection_listr ���)r���Zreset_connectionZend_hostZ role_completer3���ZBYPASS_HOST_LOOPzOsending task start callback, copying the task so we can template it temporarilyz#done copying, going to template now)Zfail_on_undefined�empty)Z nonstringzdone templatingz!templating failed for some reasonzhere goes the callback...Z!v2_playbook_on_handler_task_startZv2_playbook_on_task_start)Zis_conditionalzsending task start callbackr2���g�������?)Z max_passesz>done queuing things up, now waiting for results queue to drainr���)rG���rP����variable_managerz!we have included files to processzgenerating all_blocks datac�����������������s���s���|�]}|g�fV��qd�S�r#���r���)r$���rH���r���r���r���r-�����r'���z%StrategyModule.run.<locals>.<genexpr>zdone generating all_blocks datazprocessing included file: %s)rM���rR���rP���)rG���� is_handlerc�����������������S���s���g�|�]}|j�D�]}|�qqS�r���)�block)r$����br%���r���r���r���r&���'��r'���z&StrategyModule.run.<locals>.<listcomp>z2iterating over new_blocks loaded from include file)rM���rJ���rN���rO���zfiltering new block on tagsz done filtering new block on tagsz7done iterating over new_blocks loaded from include file)Z wrap_textZfailedz7extending task lists for all hosts with included blockszdone extending task listszdone processing included fileszresults queue emptyzchecking for any_errors_fatalr!���z"done checking for any_errors_fatalz checking for max_fail_percentageg������Y@Z!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)hZ_tqmZRUN_OKZ_set_hosts_cacher6���Z_terminated�display�debugZget_hosts_leftrL���� isinstancer���Z_roleZhas_runZ _metadataZallow_duplicatesZ_variable_managerZget_varsZ_hosts_cacheZ_hosts_cache_allZadd_tqm_variablesr���r7����templater4���r���rE����collections�KeyErrorrC���rD����extendZ _execute_metar����any_errors_fatal� ignore_errorsZ_stepZ _take_step�run_once�getattrrA���r���� ExceptionZ send_callbackZ_blocked_hostsZget_nameZ_queue_taskZ_process_pending_results�max�int�lenZ_workersZ_pending_resultsZ_wait_on_pending_resultsZupdate_active_connectionsr ���Zprocess_include_results�dict�setZ _filenameZ_is_roleZ_copy_included_fileZget_block_listZ_taskZ_load_included_file�handlersrT���rN���Znotified_hostsZget_first_parent_includeZfilter_tagged_tasksZ get_tasksrB���r���r����errorZ_resultsZ_result�addZ_hostZ _failed_hostsZmark_host_failedZ add_tasksr=���r>���Z is_failedZis_unreachable� frozensetr ���ZRESCUEZALWAYSr8���Zget_active_stater*���Z fail_stater ���ZRUN_FAILED_BREAK_PLAYZmax_fail_percentageZ batch_size�IOError�EOFErrorZRUN_UNKNOWN_ERRORr���r����run)(r���rG���Zplay_context�resultZ work_to_doZ hosts_leftZ callback_sentrK���Z skip_restZchoose_stepr]����resultsrH���rJ���r_���Z task_varsZtemplarZtask_actionr4���Z saved_nameZincluded_filesZ all_blocksZincluded_tasksZfailed_includes_hostsZ included_filerS���Znew_irZ new_blocksZhandler_blocksZ new_blockZfinal_block�e�rZfailed_hostsZunreachable_hosts�resZdont_fail_statesr+���r,���Z percentager���r���r���rm������sz��� � , � � � ( ( " �� $ zStrategyModule.run)�__name__� __module__�__qualname__r���rL���rm���� __classcell__r���r���r���r���r���1���s���Fr���N)#Z __future__r���r���r����typeZ __metaclass__Z DOCUMENTATIONZansibler���rC���Zansible.errorsr���r���r���Zansible.executor.play_iteratorr ���r ���Zansible.module_utils._textr���Zansible.playbook.handlerr���Zansible.playbook.included_filer ���Zansible.playbook.taskr���Zansible.plugins.loaderr���Zansible.plugins.strategyr���Zansible.templater���Zansible.utils.displayr���rV���r���r���r���r���r����<module>���s���