관리-도구
편집 파일: __init__.cpython-39.pyc
a �����)g5m������������������� ���@���sV��d�dl�mZmZmZ�eZd�dlZd�dlZd�dlZej dk�rRe dd�ej� ������dd��Ze���dd ��Ze���d�d lmZ�d�dlmZ�ed�Zeed �k�r�e de���d�dlZd�dlZd�dlZd�dlZd�dlmZmZ�d�dlmZ�z"d�dlmZ�d�dl m!Z!�e!��Z"W�nB�e#�yF�Z$�z(e%de$�ej&d��e�'d��W�Y�dZ$[$n dZ$[$0�0�d�dlm(Z(�d�dl)m*Z+�d�dl,m-Z-m.Z.m/Z/�d�dl0m1Z1�d�dl2m3Z3�d�dl4m5Z5m6Z6�d�dl7m8Z8�d�dl9m:Z:�d�dl;m<Z<m=Z=�d�dl>m?Z?�d�d l@mAZA�d�d!lBmCZC�d�d"lDmEZE�d�d#lFmGZG�d�d$lHmIZI�d�d%lJmKZK�zd�dlLZLd&ZMW�n�eN�y@���d'ZMY�n0�G�d(d)��d)e�ZOdS�)*�����)�absolute_import�division�print_functionN)����� ���zRERROR: Ansible requires Python 3.9 or newer on the controller. Current version: %s��c��������������� ���C���s����g�}�t�jt�jt�jfD�]L}z|���}W�n�ty:���Y�qY�n0�t�|�s|��t |dd�p\d|���q|�r�t dd�dd��|�D������dS�)zBCheck stdin/stdout/stderr to make sure they are using blocking IO.�nameNz#%szbERROR: Ansible requires blocking IO on stdin/stdout/stderr. Non-blocking file handles detected: %sz, c�����������������s���s���|�] }|V��qd�S�)N��)�.0�_ior ���r ����8/usr/lib/python3.9/site-packages/ansible/cli/__init__.py� <genexpr>'��������z$check_blocking_io.<locals>.<genexpr>)�sys�stdin�stdout�stderr�fileno� Exception�os�get_blocking�append�getattr� SystemExit�join)ZhandlesZhandle�fdr ���r ���r����check_blocking_io���s���� �r���c��������������� ���C���s����zt��t�jd��t����\}�}W�n6�t�jtfyT�}�ztd|���W�Y�d}~n d}~0�0�|rf|���dvrrtd|���t� ��}|���dkr�td|���dS�)zmSet the locale to the users default setting and ensure the locale and filesystem encoding are UTF-8. r���z<ERROR: Ansible could not initialize the preferred locale: %sN)�utf-8�utf8zEERROR: Ansible requires the locale encoding to be UTF-8; Detected %s.r���zIERROR: Ansible requires the filesystem encoding to be UTF-8; Detected %s.) �locale� setlocale�LC_ALL� getlocale�Error� ValueErrorr����lowerr����getfilesystemencoding)Zdummy�encoding�eZfs_encr ���r ���r����initialize_locale-���s�����r)���)�version)�LooseVersionZjinja2z3.0zRERROR: Ansible requires Jinja2 3.0 or newer on the controller. Current version: %s)�ABC�abstractmethod)�Path)� constants)�Displayz ERROR: %s)�file����)�context)�option_helpers)�AnsibleError�AnsibleOptionsError�AnsibleParserError)�InventoryManager)�string_types)�to_bytes�to_text)� is_executable)� DataLoader)�PromptVaultSecret�get_file_vault_secret)�add_all_plugin_dirs)�__version__)�AnsibleCollectionConfig)�_get_collection_name_from_path��unfrackpath)�to_unsafe_text)�VariableManagerTFc�������������������@���s����e�Zd�ZdZdZdZdZd-dd�Zedd ���Z e d d���Ze d.d d��Ze d/dd��Z e dd���Ze dd���Zd0dd�Zed1dd��Zedd���Zdd��Ze d2dd��Ze d d!���Ze d"d#���Ze d$d%���Ze d3d'd(��Ze d)d*���Zed4d+d,��ZdS�)5�CLIz# code behind bin/ansible* programs �lessZFRSXFNc�����������������C���s<���|st�d��||�_d|�_||�_tjr8t�d�r8t� d��dS�)z@ Base init method for all command line programs z%A non-empty list for args is requiredNZdev0z�You are running the development version of Ansible. You should only run Ansible from "devel" if you are modifying the Ansible engine, or trying out features under development. This is a rapidly changing source of code and can become unstable at any point.) r$����args�parser�callback�CZ DEVEL_WARNINGrA����endswith�display�warning)�selfrJ���rL���r ���r ���r����__init__����s�����zCLI.__init__c�����������������C���s����|������t�tt�|�jj����tj r<t� dttj ����n t� d��tjjD�]�}|d�}|d�d�}d|d�v�r�d|d�d��}nd}|d�� d �}|d�� d �}|d�� d�}tjd|||f�|||d ��qNdS�)z�Run the ansible command Subclasses must implement this method. It does the actual work of running an Ansible command. zUsing %s as config filez$No config file found; using defaultsr��������whyZalternativesz, use %s insteadr���r*����date�collection_namez%s option, %s%s)r*���rU���rV���N)�parserO���Zvvr;����opt_helpr*���rK����progrM���ZCONFIG_FILE�vZconfigZ DEPRECATED�get� deprecated)rQ���r\���r���rT���ZaltZverrU���rV���r ���r ���r����run����s"���� �zCLI.runc�����������������C���s(���d|�vrd�|�fS�|���dd�}t|�}|S�)N�@rS���)�split�tuple)�vault_id�parts�retr ���r ���r����split_vault_id����s ����zCLI.split_vault_idTc�����������������C���sZ���|pg�}|�pg�}�|D�]}dt�j|f�}|��|��q|s>|�sV|rVdt�jdf�}|��|��|�S�)Nz%s@%s�prompt_ask_vault_pass)rM����DEFAULT_VAULT_IDENTITYr���)� vault_ids�vault_password_files�ask_vault_pass�create_new_password�auto_promptZ password_fileZid_slugr ���r ���r����build_vault_ids����s���� zCLI.build_vault_idsc�����������������C���s"��g�}i�}|pg�}t�jr"|�t�j��|r@ddg|d<�ddg|d<�ndg|d<�dg|d<�tj|||||d �}d��}} |D��]�} t�| �\}}|d v��r|p�t�j} t||�| d�}z|����W�n8�t y��}�z t �d||f�����W�Y�d�}~n d�}~0�0�d } |�| |f��|��|��qtt � d|���zt|||�d�}W�nL�t �y|�}�z2t �d|t|�f���|}W�Y�d�}~qtW�Y�d�}~n d�}~0�0�z|����W�nL�t �y��}�z2t �d|t|�f���|}W�Y�d�}~qtW�Y�d�}~n d�}~0�0�d } |�r�|�||f��n|�t�j|f��|��|��qt|�r| �s|�|S�)Nz#New vault password (%(vault_id)s): z+Confirm new vault password (%(vault_id)s): �promptzNew Vault password: zConfirm New Vault password: re���zVault password (%(vault_id)s): zVault password: )rk���)rm���re���)�prompt_formatsra���z'Error in vault password prompt (%s): %sTzReading vault password file: %s)�filenamera����loaderz*Error getting vault password file (%s): %sz-Error in vault password file loading (%s): %s)rM���ZDEFAULT_VAULT_PASSWORD_FILEr���rH���rl���rd���rf���r>����loadr5���rO���rP����set_vault_secretsZvvvvvr?���r;���)rp���rg���rh���ri���rj���rk���� vault_secretsrn���Zlast_exceptionZfound_vault_secretZ vault_id_slugZ vault_id_nameZvault_id_valueZbuilt_vault_idZprompted_vault_secret�excZfile_vault_secretr ���r ���r����setup_vault_secrets����sz������ � � � ""zCLI.setup_vault_secretsc�����������������C���s���t�j�|�d�}|rt|�}|S�)N)rm���)�getpassrF���)rm����secretr ���r ���r����_get_secret?��s����zCLI._get_secretc������������������C���s����t�j}�d}d}d}tjrdn |�d����}z|d|�}|�d�rNt�d�}d|�}n|�d �rdt�|�d ��}|�d �r�t�|�}|�d�r�|dkr�|}n|�d�r�t�|�d��}W�n�ty����Y�n0�||fS�)z6 prompt for connection and become passwords if needed Nr���ZBECOMEZ become_methodz %s password: Zask_passzSSH password: z'%s password[defaults to SSH password]: Zconnection_password_fileZbecome_ask_passZbecome_password_file) r3����CLIARGSrM���ZAGNOSTIC_BECOME_PROMPT�upperrH���rx����get_password_from_file�EOFError)�opZsshpassZ becomepassZ become_promptZbecome_prompt_methodr ���r ���r���� ask_passwordsG��s*���� zCLI.ask_passwordsc�����������������C���s���|r|j�dk�r|�j�d��|S�)z check for conflicting options rS���z.The number of processes (--forks) must be >= 1)ZforksrK����error)rQ���r}���Z runas_optsZ fork_optsr ���r ���r����validate_conflictsf��s���� zCLI.validate_conflictsr���c�����������������C���s���t�j|�j|||d�|�_dS�)a_�� Create an options parser for most ansible scripts Subclasses need to implement this method. They will usually call the base class's init_parser to create a basic version and then add their own options on top of that. An implementation will look something like this:: def init_parser(self): super(MyCLI, self).init_parser(usage="My Ansible CLI", inventory_opts=True) ansible.arguments.option_helpers.add_runas_options(self.parser) self.parser.add_option('--my-option', dest='my_option', action='store') )�usage�desc�epilogN)rX���Zcreate_base_parserr���rK���)rQ���r����r����r����r ���r ���r����init_parsero��s����zCLI.init_parserc�����������������C���s����t�|d�r|jsdg|_t�|d�rb|jrbt��}|jD�]"}|�d�D�]}|�|�����qBq4t|�|_t�|d�r�|jr�t��}|jD�]"}|�d�D�]}|�|�����q�q~t|�|_t�|d�r�|�js�|j r�t |j t�r�|j g|_ dd��|j D��|_ ntj |_ |S�)a ��Process the command line args Subclasses need to implement this method. This method validates and transforms the command line arguments. It can be used to check whether conflicting values were given, whether filenames exist, etc. An implementation will look something like this:: def post_process_args(self, options): options = super(MyCLI, self).post_process_args(options) if options.addition and options.subtraction: raise AnsibleOptionsError('Only one of --addition and --subtraction can be specified') if isinstance(options.listofhosts, string_types): options.listofhosts = string_types.split(',') return options �tags�all�,� skip_tags� inventoryc�����������������S���s$���g�|�]}d�|vrt�|dd�n|�qS�)r����F)�followrD���)r ����optr ���r ���r���� <listcomp>���r���z)CLI.post_process_args.<locals>.<listcomp>)�hasattrr�����setr_����add�strip�listr�����SKIP_INVENTORY_DEFAULTSr����� isinstancer9���rM���ZDEFAULT_HOST_LIST)rQ����optionsr����Ztag_set�tagr����r ���r ���r����post_process_args���s*���� zCLI.post_process_argsc�������������� ���C���s����|������trt�|�j��z|�j�|�jdd���}W�nJ�ty|�}�z2|jdkrf|�jj dd|�j� ���d����W�Y�d}~n d}~0�0�|��|�}t� |��dS�)a���Parse the command line args This method parses the command line arguments. It uses the parser stored in the self.parser attribute and saves the args and options in context.CLIARGS. Subclasses need to implement two helper methods, init_parser() and post_process_args() which are called from this function before and after parsing the arguments. rS���Nr�������z %s)�status�message)r�����HAS_ARGCOMPLETE�argcompleteZautocompleterK���� parse_argsrJ���r����code�exit�format_helpr����r3���Z_init_global_context)rQ���r�����exr ���r ���r���rW������s���� z CLI.parsec�������������� ���C���s����|�rt����}nt}|���d�}|�d�}tt|��D�]@}||�dkrLd||<�zt||��||<�W�q4�tyr���Y�q40�q4t|�dk�r�tt|�d�D�]}|�d��q�|� ��||d�|d�|d�d�S�)z" return full ansible version info r����.r���r���rS���r����)�stringZfull�major�minorZrevision) rX���r*���rA���r_����range�len�intr���r���r����)�gitinfoZansible_version_stringZansible_versionZansible_versionsZcounterr ���r ���r����version_info���s*���� �zCLI.version_infoc�����������������C���s����t�j���stj|�dd��n|dtjv�rRt�jdkr>tj|�dd��q�t�|�tjd���nDt j ddt jt jd�}|����|j dkr�t�|�d��ntj|�dd��d S�) z% find reasonable way to display text T)Zscreen_only�PAGER�win32zless --version)�shellr���r���r���rI���N)r���r����isattyrO���r����environ�platformrH���� pager_pipe� subprocess�Popen�PIPE�communicate� returncode)�text�pr ���r ���r����pager���s���� z CLI.pagerc�����������������C���sh���dt�jvrtjt�jd<�z*tj|dtjtjd�}|j t |��d��W�n"�tyR���Y�n�tyb���Y�n0�dS�)z pipe text through a pager �LESST)r����r���r���)�inputN) r���r����rH���� LESS_OPTSr����r����r����r���r���r����r:����IOError�KeyboardInterrupt)r�����cmdr ���r ���r���r�������s���� zCLI.pager_pipec������������ ������C���s����t�j}�t��}|��dd�}|rV|�|��t|��|t_t|�}|rVt � d�|���|t_t |�d��}tj}||�}tj||t |�d��|�d�dd�}|�|��t||�d�|��d ��d �}t||tjdd�d�}|||fS�) N�basedirFz#running with default collection {0}rg���rh���ri���)rg���rh���ri���rk���r����Zflush_cache)rp���Zsources�cache)r����)rp���r����r����)r3���ry���r=���r[���Zset_basedirr@���rB���Zplaybook_pathsrC���rO���rP����format�default_collectionr����rM���ZDEFAULT_VAULT_IDENTITY_LISTrH���ru���rr���r8���rG���r����) r����rp���r����r����rg���Zdefault_vault_idsrs���r����Zvariable_managerr ���r ���r���� _play_prereqs��s0���� � zCLI._play_prereqsr����c�����������������C���s^���d}t�|�����dkr2tjr.|tjvr.t�d��d}|��|��|��|�}|sZ|du�rZtd��|S�)NFr���zpprovided hosts list is empty, only localhost is available. Note that the implicit localhost does not match 'all'TzSSpecified inventory, host pattern and/or --limit leaves us with no hosts to target.) r����Z list_hostsrM���ZLOCALHOST_WARNINGZ LOCALHOSTrO���rP����subsetr5���)r����r�����patternZno_hosts�hostsr ���r ���r���� get_host_list0��s���� zCLI.get_host_listc����������� ��� ���C���s^��t�|��}d�}|dkr$tjj���}�ntj�|�s>td|����n�t |�r�t �dt|�����|g}zt j|t jt jd�}W�n4�ty��}�ztd|�|f���W�Y�d�}~n d�}~0�0�|���\}}|jdkr�td|�|j|f���|}n^z"t|d�}|������}|����W�n:�ttf�y8�}�ztd |�|f���W�Y�d�}~n d�}~0�0�|�d �}|�sVtd|����t|�S�)N����-z"The password file %s was not foundz!The password file %s is a script.)r���r���z�Problem occured when trying to run the password script %s (%s). If this is not a script, remove the executable bit from the file.r���z4The password script %s returned an error (rc=%s): %s�rbz#Could not read password file %s: %ss��� z*Empty password was provided from file (%s))r:���r���r����buffer�readr����path�existsr5���r<���rO���Zvvvvr;���r����r����r�����OSErrorr����r�����openr�����closer����rF���) Zpwd_fileZ b_pwd_filerw���r����r����r(���r���r����fr ���r ���r���r{���B��s:����� & zCLI.get_password_from_filec����������� ������C���s���|d�u�rt�j}z�t�d��ttj����}z|jdd��W�nJ�t y��}�z2|j t jkrnt�d|t |dd�f���W�Y�d�}~nd�}~0�0�t�d|���zdd ��|D��}W�n6�ty����t�d ��t�dt t�������d}Y�n0�|�|�}|���}W��n��t�y8�}�z.|j����tjt |�d d��d}W�Y�d�}~�n�d�}~0��t�yt�}�z$tjt |�d d��d}W�Y�d�}~�nLd�}~0��t�y��}�z$tjt |�d d��d}W�Y�d�}~�nd�}~0��t�y����t�d��d}Y�n��t�y��}�z�tj�r��ttj�}tjdt |��d d��|�r&|�rvtjd�dk�rvd }t|d��r�t�dt t |j!�����t |j!�} t |�| k�r�t�d| ���nt�d��d}tjdt t�����|d��d}W�Y�d�}~n d�}~0�0�t��"|��d�S�)Nzstarting runi���)�modez'Failed to create the directory '%s': %sZsurrogate_or_replace��errorszCreated the '%s' directoryc�����������������S���s���g�|�]}t�|d�d��qS�)Zsurrogate_or_strictr����)r;���)r ����ar ���r ���r���r�������r���z$CLI.cli_executor.<locals>.<listcomp>zaCommand line args are not in utf-8, unable to continue. Ansible currently only understands utf-8zThe full traceback was: %s����F)Z wrap_textr2�������rS���zUser interrupted execution�c���z0Unexpected Exception, this is probably a bug: %s� verbosityr�����orig_excz exception type: %sz original msg: %sz#to see the full traceback, use -vvvTzthe full traceback was: %s)�log_only����)#r����argvrO����debugr.���rM���ZANSIBLE_HOME� expanduser�mkdirr�����errnoZEEXISTrP���r;����UnicodeErrorr���� traceback� format_excr]���r6���rK���� print_helpr7���r5���r����r���Z DEFAULT_DEBUG�boolr3���ry���r����Zvvv�typer����r����) �clsrJ���Zansible_dirrt���Z exit_codeZclir(���Zhave_cli_optionsr����rT���r ���r ���r����cli_executorl��sf���� � zCLI.cli_executor)N)NNNT)NNFT)FF)r���NN)F)r����)N)�__name__� __module__�__qualname__�__doc__r����r����r����rR���r-���r]����staticmethodrd���rl���ru���rx���r~���r����r����r����rW���r����r����r����r����r����r{����classmethodr����r ���r ���r ���r���rH���w���sV��� ��������f 8 $ )rH���)PZ __future__r���r���r���r����Z __metaclass__r���r���r���r����r���r���r*���� splitlinesr���r)����importlib.metadataZ#ansible.module_utils.compat.versionr+���Zjinja2_versionr����rv���r����r�����abcr,���r-����pathlibr.���Zansibler/���rM���Zansible.utils.displayr0���rO���r���r(����printr���r����r3���Zansible.cli.argumentsr4���rX���Zansible.errorsr5���r6���r7���Zansible.inventory.managerr8���Zansible.module_utils.sixr9���Zansible.module_utils._textr:���r;���Z ansible.module_utils.common.filer<���Zansible.parsing.dataloaderr=���Zansible.parsing.vaultr>���r?���Zansible.plugins.loaderr@���Zansible.releaserA���Zansible.utils.collection_loaderrB���Z2ansible.utils.collection_loader._collection_finderrC���Zansible.utils.pathrE���Zansible.utils.unsafe_proxyrF���Zansible.vars.managerrG���r����r�����ImportErrorrH���r ���r ���r ���r����<module>���st��� ����