관리-도구
편집 파일: config.cpython-39.opt-1.pyc
a �����)g�V����������������������@���s\��d�dl�mZmZmZ�eZd�dlmZ�d�dlZd�dl Z d�dl Z d�dlZd�dlm Z �d�dlmZ�d�dlm��mZ�d�dlmZ�d�dlmZ�d�dlmZmZ�d�d lmZmZ�d�d lm Z m!Z!m"Z"�d�dl#m$Z$�d�dl%m&Z&�d�d l'm(Z(�d�dl)m*Z*�d�dl+m,Z,�d�dl-m.Z.�d�dl/m0Z0�e.��Z1ddd�Z2dd��Z3dd��Z4G�dd��de�Z5ddd�Z6e7dk�rXe6���dS�) �����)�absolute_import�division�print_function)�CLIN)�Mapping)�context)� constants)�option_helpers)� ConfigManager�Setting)�AnsibleError�AnsibleOptionsError)� to_native�to_text�to_bytes)� json_dump)�string_types)� is_quoted)� AnsibleDumper)�stringc)�Display)�unfrackpathFc�����������������C���s���t�j|�t||d�S�)N)ZDumper�default_flow_style� default_style)�yaml�dumpr���)�datar���r�����r����6/usr/lib/python3.9/site-packages/ansible/cli/config.py� yaml_dump&���s����r���c�����������������C���s���t�|�ddd�S�)NTz'')r���r���)r���)r���r���r���r���� yaml_short*���s����r ���c�������������������C���s$���t�td�sdd��tt�D��t_tjS�)zE helper method to ensure we can template based on existing constants �cvarsc�����������������S���s"���i�|�]}|��d��s|tt|��qS�)�__)� startswith�getattr�C)�.0�kr���r���r���� <dictcomp>1��������z!get_constants.<locals>.<dictcomp>)�hasattr� get_constants�dirr%���r!���r���r���r���r���r+���.���s���� r+���c�����������������������s����e�Zd�ZdZdZd&��fdd� Z��fdd�Z��fdd �Z��fd d�Zdd ��Z dd��Z dd��Zd'dd�Zdd��Z dd��Zdd��Zdd��Zdd��Zdd��Zd d!��Zd"d#��Zd$d%��Z���ZS�)(� ConfigCLIz Config command line class zansible-configNc��������������������s"���d�|�_�d�|�_tt|���||��d�S��N)�config_file�config�superr-����__init__)�self�args�callback�� __class__r���r���r2���:���s����zConfigCLI.__init__c�������������� ������s���t�t|��jdd��tjjdd�}t�|��|jddddd ��|jd ddd ddd gtt j ��dd��|jdddd��|�jjdd�}d|_ |jdd|gd�}|j|�jd��|jddddd d!gd!d"d#��|jd$d%|gd�}|j|�jd��|jd&d'd(d)d*d+��|jddddg�d,�d-d.d#��|jd/d0|gd�}|j|�jd��|jd1d2|gd�}|j|�jd��|jddddg�d3�d4d5d#��|jd6d7d)dd8d9��d�S�):NzView ansible configuration.)�descF)�add_help�-cz--configr/���zGpath to configuration file, defaults to first file found in precedence.)�dest�helpz-tz--type�store�base�type�allz&Filter down to a specific plugin type.)�action�defaultr;����choicesr<���r4���z<Specific plugin to target, requires type of plugin to be set�*)r<����nargsrA���)r;���T�listzPrint all config options)r<����parents)�funcz--formatz-f�format�jsonr���zOutput format for list)r;���rA���rC���rB���r<���r���zDump configurationz--only-changedz--changed-only�only_changed� store_truez;Only show configurations that have changed from the default)r;���rA���r<���)rJ���r����displayrM���zOutput format for dump�viewzView configuration file�init�Create initial configuration)�ini�env�varsrQ���zOutput format for initz --disabled� commentedz=Prefixes all entries with a comment character to disable them)r;���rA���rB���r<���)r1���r-����init_parser�opt_help�argparse�ArgumentParserZadd_verbosity_options�add_argumentrF���r%����CONFIGURABLE_PLUGINS�parser�add_subparsers�required� add_parser�set_defaults�execute_list�execute_dump�execute_view�execute_init)r3����commonZ subparsersZlist_parserZdump_parserZview_parserrU���r6���r���r���rU���@���sJ���� � �������zConfigCLI.init_parserc��������������������s���t�t|���|�}|jt_|S�r.���)r1���r-����post_process_args� verbosityrM���)r3����optionsr6���r���r���re���k���s����zConfigCLI.post_process_argsc��������������������sL��t�t|������tjd�rrttjd�dd�|�_t|�j�}tj � |�r^t�|tj�r^t |�j�|�_q�tdt|�j����ntj|�_|�jj|�_|�j�r$zNtj � |�j�s�td|�j���ntj �|�j�s�td|�j���t|�j�tjd<�W�nF�t�y ���tjd�d v�r���n tjd�d v��rt�d|�j���Y�n0�ntjd�dk�r<td ��tjd����d�S�)Nr/���F)�followz@The provided configuration file is missing or not accessible: %sz&%s does not exist or is not accessiblez%s is not a valid fileZANSIBLE_CONFIGrA���)rN���)Zedit�updatez(File does not exist, used empty file: %srN���z&Invalid or no config file was suppliedrH���)r1���r-����runr����CLIARGSr���r/���r����os�path�exists�access�R_OKr ���r0���r ���r���r%���Z_config_file�isfile�environ� ExceptionrM����warningr���)r3���Zb_configr6���r���r���rj���q���s0���� z ConfigCLI.runc�����������������C���s~���t�d��tjd�du�rtd��tjd��d�\}}d|v�rJ|�d�\}}nd}|}t�dd d ddd dd|�j|||f�g��dS�)zG Updates a single setting in the specified ansible.cfg �Option not implemented yet�settingNz*update option requires a setting to update�=�.�defaults�ansiblez-mZini_fileZ localhostr:����localz-az2"dest=%s section=%s option=%s value=%s backup=yes")r���r���rk���r ����split� subprocess�callr/���)r3����entry�value�section�optionr���r���r����execute_update����s�����zConfigCLI.execute_updatec�������������� ���C���s����zFt�|�jd��&}|��t|���dd���W�d����n1�s:0����Y��W�n4�tyz�}�ztdt|����W�Y�d}~n d}~0�0�dS�)z2 Displays the current config file �rb�surrogate_or_strict��errorsNzFailed to open config file: %s)�openr/����pagerr����readrs���r���r���)r3����f�er���r���r���rb�������s ����8zConfigCLI.execute_viewc�����������������C���sp���t�d��z.t�tj�dd��}|�|�j��t� |��W�n4�t yj�}�zt�dt|����W�Y�d}~n d}~0�0�dS�)z9 Opens ansible.cfg in the default EDITOR ru���ZEDITOR�vizFailed to open editor: %sN)r����shlexr|���rl���rr����get�appendr/���r}���r~���rs���r���)r3���Zeditorr����r���r���r����execute_edit����s����zConfigCLI.execute_editc����������� ������C���s����i�}t�td|��}|rVg�}|D�]4}|j|dd�}|d�u�rHt�d|���q|�|��qn|jdd�}|D�]N}|j�}} | �d�r�t j �|j�r�qfn| � ddd�d�}|�j�|| �||<�qf|S�) N� %s_loaderT�Z class_only�0Skipping %s as we could not find matching plugin�_������� (DEPRECATED))r$���� plugin_loaderr����rM���rt���r����r@���� _load_namer#���rl���rm����islink�_original_path�replacer0����get_configuration_definitions) r3����ptype�plugins�entries�loader� plugin_cs�plugin�p� finalname�namer���r���r����_list_plugin_settings����s$���� zConfigCLI._list_plugin_settingsc�����������������C���s����i�}t�jd�dv�r |�jjdd�}t�jd�dkr6i�|d<�t�jd�dkrhtjD�]}|��|�|d�|���<�qJn4t�jd�dkr�|��t�jd�t�jd��|d�t�jd�<�|S�) z> build a dict with the list requested configs r?���)r>���r@���T�Zignore_privater>����PLUGINSr@���r4���)r���rk���r0���r����r%���rZ���r�����upper)r3����config_entriesr����r���r���r����_list_entries_from_args����s���� &z!ConfigCLI._list_entries_from_argsc�����������������C���sL���|�����}tjd�dkr t|�}ntjd�dkr6t|�}|��t|dd���dS�)z3 list and output available configs rI���r���rJ���r����r����N)r����r���rk���r���r���r����r���)r3���r�����outputr���r���r���r`�������s���� zConfigCLI.execute_listc�����������������C���s���g�}t�jd�rd}nd}|D��]�}||��d�s2q||��dd�}|dkr�||��dd�}|dkrr|rld }q�d }n�|r�|dkr�t|t�s�zd�|�}W�n0�ty��}�zd t|��}W�Y�d�}~n d�}~0�0�t|t�r�t|�s�t � |�}n|d�u�r�d}|||�v�r||�|�r||�|�d�d�} t||�d�t��r@||�d�} nd�||�d��} ||��d|�}|�d|||��dd�| f���|dk�r�| �d��r�q|�d|| |f���n:|dk�r�| �d��r�q|�|d| t t|�dd�f����|�d��q|S�)NrT����#r�����descriptionrB���rR���r?���Zboolean�1�0rF����, z%s���r����z #z# %s(%s): %s�stringZ _ANSIBLE_z%s%s=%srS���Z _ansible_z%s: %sr����r����)r���rk���r����� isinstancer����joinrs���r���r���r�����quoter����r#���r���r ���)r3����settingsZsubkeyr����prefixrv���rB����styper����r���r8���r����r���r���r����_get_settings_vars��sT���� " "zConfigCLI._get_settings_varsc�����������������C���s|��i�}t�|����D��]d}||�}t|t�s*q|�d�sr|��|�}|D�],}||v�rb||��||���qB||�||<�qBqt|d�t�r�d|�dd�|d�f�}n"d|�dd��}|d�|d��7�}d|v�r|d�r|d�d�}|d �|vr�g�||d �<�|�d d�} |�dd�dk�r&t| t��s&d �| �} n| d�u��r4d} t j d��rPd|d��|d<�|d|d�| f��} ||d ���| ��q|S�)Nr����z # (%s) %sr?���r����z# (%s) z # rQ���r����r����rB���r����rF���r����rT���z;%s�keyz %s=%s)�sorted�keysr����r���r�����_get_settings_ini�extendr���r����r���rk���r����)r3���r�����sections�o�optZnew_sections�sr8���r���rB���r����r���r���r���r����=��s<���� zConfigCLI._get_settings_inic�������������� ���C���sN��g�}|�����}|�dd�}tjd�dkr�|��|�}|r~|D�]D}|��||��}|D�],}||v�rn||��||���qN||�||<�qNq8|r�|���D�]>}|�d|���||�D�]} |�| ��|�d��q�|�d��q�nftjd�dv��r2|��|tjd��}|�r2|D�]8}||����D�]&} |�|��||�| �tjd�����qq�|�� t d�|�d d ���dS�)rP���r����NrI���rQ���z[%s]r����)rR���rS���� r����r����)r�����popr���rk���r����r����r����r����r����r����r���r����)r3���r���r����Zplugin_typesr����r����Zplugin_sectionsr����r����r����r����r���r���r���rc���l��s4���� &zConfigCLI.execute_initc����������� ������C���s����g�}t�|�D�]�}||�jdv}tjd�dkr�t||�t�r�||�jdkrNd}n||�jdkrbd}nd}d |||�j||�jf�}nd}d |d||��d�f�}t||�}n&i�}||�j D�]}t ||�|�||<�q�tjd �r�|r|�|��q|S�)N)rB����REQUIREDrI���rM���rB���Zgreenr����ZredZyellowz%s(%s) = %srK���)r�����originr���rk���r����r���r����r����r����_fieldsr$���r����) r3���r0���r����rv���ZchangedZcolor�msgr���r����r���r���r����_render_settings���s(����zConfigCLI._render_settingsc�����������������C���sV���|�j�jdd����}|���D�]0}tj�j||�jt��d�\}}t|||d��||<�q|�� |�S�)NTr����)�cfile� variables) r0���r�����copyr����r%����get_config_value_and_originr/���r+���r���r����)r3���r0���rv����vr����r���r���r����_get_global_configs���s ����zConfigCLI._get_global_configsc�����������������C���s&��t�td|��}g�}i�}|rdg�}|D�]>}|j|dd�}|d�u�rLt�d|���q"|�|j|dd���q"n|jdd�}|D��]�}|j�} } | �d�r�t j �|j�r�qt| � ddd�d�} |�j�|| �|| <�z|j| dd�}W�nJ�t�y�}�z0t�d | |t|�f���W�Y�d�}~qtW�Y�d�}~n d�}~0�0�|| ����D�]�} z"tjj| |�j|| t��d �\}}W�nD�t�y��}�z*t|��d��r~d�}d}n|�W�Y�d�}~n d�}~0�0�|d�u��r�|d�u��r�d}t| ||d��|| �| <��q,|��|| ��}|rttjd �dk�r|�d| dt| ��f���|�|��qt|�| |i��qt|S�)Nr����Tr����r����r����r����r����r����zMSkipping "%s" %s plugin, as we cannot load plugin to check config due to : %s)r����Zplugin_typeZplugin_namer����z2No setting was provided for required configurationr����rI���rM���� %s: %s)r$���r����r����rM���rt���r����r@���r����r#���rl���rm���r����r����r����r0���r����rs���r���r����r%���r����r/���r+���r���r���r���r����r���rk����lenr����)r3���r����r����r����r����r����r����r����r����r����r����r���r����rv���r����r�����resultsr���r���r����_get_plugin_configs���sR���� ""zConfigCLI._get_plugin_configsc�����������������C���s8��t�jd�dkr|����}n�t�jd�dkr�|����}tjD�]�}|��|t�jd��}t�jd�dkr�t�jd�rf|r�|�d|���d t|��f���|� |��q4|d v�r�|���}nd|����}|�||i��q4n|��t�jd�t�jd��}t�jd�dkr�d� |�}t�jd�d k�r t|�}nt�jd�dk�r"t|�}|�� t|dd���dS�)zM Shows the current settings, merges ansible.cfg if specified r?���r>���r@���r4���rI���rM���rK���r����rw���)�modulesZ doc_fragmentsz %s_PLUGINSr����r���rJ���r����r����N)r���rk���r����r%���rZ���r����r����r����r����r����r����r���r���r����r���)r3���r����r����Zplugin_listZpname�textr���r���r���ra������s,���� zConfigCLI.execute_dump)N)N)�__name__� __module__�__qualname__�__doc__r����r2���rU���re���rj���r����rb���r����r����r����r`���r����r����rc���r����r����r����ra���� __classcell__r���r���r6���r���r-���5���s&���+# 9/$ Fr-���c�����������������C���s���t��|���d�S�r.���)r-���Zcli_executor)r4���r���r���r����main#��s����r�����__main__)FN)N)8Z __future__r���r���r���r?���Z __metaclass__Zansible.clir���rl���r���r����r}����collections.abcr���rz���r���Zansible.plugins.loaderr����r����r����r���r%���Zansible.cli.argumentsr ���rV���Zansible.config.managerr ���r���Zansible.errorsr���r ���Zansible.module_utils._textr���r���r���Z ansible.module_utils.common.jsonr���Zansible.module_utils.sixr���Zansible.parsing.quotingr���Zansible.parsing.yaml.dumperr���Zansible.utils.colorr���Zansible.utils.displayr���Zansible.utils.pathr���rM���r���r ���r+���r-���r����r����r���r���r���r����<module>���s@��� ���q