관리-도구
편집 파일: playbook_executor.cpython-39.pyc
a �����)g�:����������������������@���s����d�dl�mZmZmZ�eZd�dlZd�dlmZ �d�dlm Z �d�dlmZm Z �d�dlmZ�d�dlmZ�d�dlmZmZmZ�d�d lmZ�d�d lmZ�d�dlmZ�d�dlmZ�d�d lmZm Z �d�dl!m"Z"�d�dl#m$Z$�d�dl%m&Z&�e&��Z'G�dd��d�Z(dS�)�����)�absolute_import�division�print_functionN)� constants)�context)�TaskQueueManager�AnsibleEndPlay)�to_text)�boolean)� become_loader�connection_loader�shell_loader)�Playbook)�Templar)� pct_to_int)�AnsibleCollectionConfig)�_get_collection_name_from_path�_get_collection_playbook_path)� makedirs_safe)�set_default_transport)�Displayc�������������������@���s0���e�Zd�ZdZdd��Zdd��Zdd��Zdd ��Zd S�)�PlaybookExecutorzw This is the primary class for executing playbooks, and thus the basis for bin/ansible-playbook operation. c�����������������C���s����||�_�||�_||�_||�_||�_t��|�_tj� d�sVtj� d�sVtj� d�sVtj� d�r^d�|�_ nt||||�jtj� d�d�|�_ t���d�S�)NZ listhostsZ listtasksZlisttags�syntax�forks)� inventory�variable_manager�loader� passwordsr���) � _playbooks� _inventory�_variable_manager�_loaderr����dict�_unreachable_hostsr����CLIARGS�get�_tqmr���r���)�selfZ playbooksr���r���r���r�����r(����F/usr/lib/python3.9/site-packages/ansible/executor/playbook_executor.py�__init__2���s(���� � � �zPlaybookExecutor.__init__c�����������$������C���s���d}g�}i�}�zbt�tjdd���t�tjdd���t�tjdd���|�jD��]�}t|�}|durn|d�}|d�}n|}t|�}|r�t� d� |���|t_ndt_t j||�j|�jd�}|�jdu�r�d |i}g�|d <�n|�j����|�j�d|��d} |���} t�dt| �t|�f���| D��]}|jdu�r0|�j�|j��n|�j�|j��|�j����|�jj|d �}t|�j|d�} t|d| � |j!���|j!�r^|j!D�]�}|d�}|�"d|�}|�"dd�}t#|�"dd��}t#|�"dd��}|�"dd�}|�"dd�}|�"dd�}|�"dd�}||�jj$v�r�|�j�rP|�j�d|||||||||� �t�%|||||||||� |j&|<�n ||j&|<��q�|�jj|d �}t|�j|d�} |�'| ��t(j)d��r��q|�jdu��r�|d ��*|���n`|�jj+�,|�j+��t|�jj-�}t|�jj+�}d}|��.|�}t|�dk�r|�j�d|��|�j�d��|D�]�}|�j�/|��z|�jj0|d �}W�n<�t1�yr�}�z"|j2}W�Y�d}~��qW�Y�d}~n d}~0�0�||�jj3@�dk�r�|�jj4}d}t|�jj-�t|�jj+��||��}t|�|k�r�d}��q|t|�jj-�|�7�}|t|�jj+�|�7�}|�j+�,|�jj+���q|�r��q| d�} �q|�r.|�*|��|�jdu�rt5j6�r�t7|�jj-�8���}|�,|�jj+�8����t9|�}t|�dk�r�t5j:�r�t5j:} n |�r�t;j<�=t;j<�>|��} nd} t;j<�?t;j<�@|��\}!}"t;j<�A| d|!��}#|��B|#|��r�t�d |#���|�j�d!|�jjC��|dkrF��qqF|�rF|W�|�jdu�r2|�j�D���|�j�rD|�j�E���S�W�|�jdu�r^|�j�D���|�j�r�|�j�E���n*|�jdu�r�|�j�D���|�j�r�|�j�E���0�t(j)d��r�t�d"��|S�t(j)d#��r�|�jjF�s�t�Gd$t(j)d#����|S�)%z� Run the given playbook, based on the settings in the play which may limit the runs to serialized groups, etc. r���T)Z class_onlyN��������z&running playbook inside collection {0})r���r����playbook�playsZv2_playbook_on_startz%d plays in %s)�play)r���Z variables�vars_prompt�name�prompt�default�private�confirmF�encrypt� salt_size�salt�unsafeZv2_playbook_on_vars_promptr���Zv2_playbook_on_play_startZv2_playbook_on_no_hosts_matchedz~/z%s.retryz to retry, use: --limit @%s Zv2_playbook_on_statszNo issues encounteredZ start_at_taskzSNo matching task "%s" found. Note: --start-at-task can only follow static includes.)H�listr����allr ���r���r���r���r����display�warning�formatr���Zdefault_collectionr����loadr ���r!���r&���Zload_callbacksZ send_callbackZ get_playsZvv�lenr ���Z_included_pathZset_basedirZ_basedirr���Zremove_restrictionZget_varsr����setattr�templater0���r%���r ���Z extra_varsZ do_var_prompt�varsZ post_validater���r$����appendr#����updateZ _failed_hosts�_get_serialized_batchesZrestrict_to_hosts�runr����resultZRUN_FAILED_BREAK_PLAYZRUN_FAILED_HOSTS�CZRETRY_FILES_ENABLED�set�keys�sortedZRETRY_FILES_SAVE_PATH�os�path�dirname�abspath�splitext�basename�join�_generate_retry_inventoryZ_statsZcleanupZcleanup_all_tmp_filesZ_start_at_done�error)$r'���rH���Z entrylist�entryr-����resourceZ playbook_pathZplaybook_collectionZpb�ir.���r/���Zall_varsZtemplar�varZvnamer2���r3���r4���r5���r6���r7���r8���r9���Zpreviously_failedZpreviously_unreachableZ break_playZbatchesZbatch�eZfailed_hosts_countZretriesZbasedirZ retry_name�_�filenamer(���r(���r)���rG���N���s��� �" &� � � ��zPlaybookExecutor.runc����������� ������C���s����|�j�j|j|jd�}t|�}|j}t|�dkr4dg}d}g�}t|�dkr�t||�|�}|dkrl|�|��q�n8g�}t|�D�] } t|�dkrx|�|� d���qx|�|��|d7�}|t|�d�kr<t|�d�}q<|S�)zz Returns a list of hosts, subdivided into batches based on the serial size specified in the play. )�orderr������r+���) r���Z get_hosts�hostsr]���r@����serialr���rD����range�pop) r'���r/���Z all_hostsZ all_hosts_lenZserial_batch_listZcur_itemZserialized_batchesr`���Z play_hosts�xr(���r(���r)���rF�����s*���� z(PlaybookExecutor._get_serialized_batchesc�������������� ���C���s����zVt�tj�|���t|d��(}|D�]}|�d|���q"W�d����n1�sJ0����Y��W�n<�ty��}�z$t�d|t |�f���W�Y�d}~dS�d}~0�0�dS�)z� Called when a playbook run fails. It generates an inventory which allows re-running on ONLY the failed hosts. This may duplicate some variable information in group_vars/host_vars but that is ok, and expected. �wz%s Nz%Could not create retry file '%s'. %sFT) r���rM���rN���rO����open�write� Exceptionr<���r=���r ���)r'���Z retry_pathZreplay_hosts�fdrc���rZ���r(���r(���r)���rT���@��s����2z*PlaybookExecutor._generate_retry_inventoryN)�__name__� __module__�__qualname__�__doc__r*���rG���rF���rT���r(���r(���r(���r)���r���+���s����E.r���))Z __future__r���r���r����typeZ __metaclass__rM���Zansibler���rI���r���Z#ansible.executor.task_queue_managerr���r���Zansible.module_utils._textr ���Z)ansible.module_utils.parsing.convert_boolr ���Zansible.plugins.loaderr���r���r ���Zansible.playbookr���Zansible.templater���Zansible.utils.helpersr���Zansible.utils.collection_loaderr���Z2ansible.utils.collection_loader._collection_finderr���r���Zansible.utils.pathr���Zansible.utils.ssh_functionsr���Zansible.utils.displayr���r<���r���r(���r(���r(���r)����<module>���s$���