a ì)gˆVã@s\ddlmZmZmZeZddlmZddlZddl Z ddl Z ddl Z ddl m Z ddlmZddlmmZddlmZddlmZddlmZmZdd lmZmZdd lm Z m!Z!m"Z"dd l#m$Z$dd l%m&Z&dd l'm(Z(ddl)m*Z*ddl+m,Z,ddl-m.Z.ddl/m0Z0e.ƒZ1ddd„Z2dd„Z3dd„Z4Gdd„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)Ú unfrackpathFcCstj|t||d�S)N)ZDumperÚdefault_flow_styleÚ default_style)ÚyamlÚdumpr)Údatarr©rú6/usr/lib/python3.9/site-packages/ansible/cli/config.pyÚ yaml_dump&srcCst|ddd�S)NTz'')rr)r)rrrrÚ yaml_short*sr cCs$ttdƒsdd„ttƒDƒt_tjS)zE helper method to ensure we can template based on existing constants ÚcvarscSs"i|]}| d¡s|tt|ƒ“qS)Ú__)Ú startswithÚgetattrÚC)Ú.0ÚkrrrÚ 1óz!get_constants..)ÚhasattrÚ get_constantsÚdirr%r!rrrrr+.s r+cs´eZdZdZdZd&‡fdd„ Z‡fdd„Z‡fdd „Z‡fd d „Zd d „Z dd„Z dd„Z d'dd„Z dd„Z dd„Zdd„Zdd„Zdd„Zdd„Zd d!„Zd"d#„Zd$d%„Z‡ZS)(Ú ConfigCLIz Config command line class zansible-configNcs"d|_d|_tt|ƒ ||¡dS©N)Ú config_fileÚconfigÚsuperr-Ú__init__)ÚselfÚargsÚcallback©Ú __class__rrr2:szConfigCLI.__init__c s†tt|ƒjdd�tjjdd�}t |¡|jddddd �|jd d d d ddd gtt j ƒdd�|jdddd�|j j dd�}d|_ |jdd|gd�}|j|jd�|jdddd d d!gd!d"d#�|jd$d%|gd�}|j|jd�|jd&d'd(d)d*d+�|jdddd gd,¢d-d.d#�|jd/d0|gd�}|j|jd�|jd1d2|gd�}|j|jd�|jdddd gd3¢d4d5d#�|jd6d7d)dd8d9�dS):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<r4z build a dict with the list requested configs r?)r>r@T©Zignore_privater>ÚPLUGINSr@r4)rrkr0ržr%rZr¨Úupper)r3Úconfig_entriesrŸrrrÚ_list_entries_from_argsâs &z!ConfigCLI._list_entries_from_argscCsL| ¡}tjddkr t|ƒ}ntjddkr6t|ƒ}| t|dd�¡dS)z3 list and output available configs rIrrJr…r†N)r­rrkrrr‰r)r3r¬Úoutputrrrr`÷s  zConfigCLI.execute_listc Csúg}tjdrd}nd}|D�]Ö}|| d¡s2q|| dd¡}|dkrò|| dd¡}|dkrr|rld }qòd }n€|ræ|d krÈt|tƒsÈzd  |¡}Wn0tyÆ}zd t|ƒ}WYd}~n d}~00t|tƒròt|ƒsòt   |¡}n |duròd}|||vr|||r|||dd} t||dtƒ�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–Ú descriptionrBrRr?ZbooleanÚ1Ú0rFú, z%séÿÿÿÿr§z #z # %s(%s): %sÚstringZ _ANSIBLE_z%s%s=%srSZ _ansible_z%s: %sr…r†)rrkr�Ú isinstancerÚjoinrsrrrŽÚquoter�r#rr ) r3ÚsettingsZsubkeyrÚprefixrvrBÚstyperŒrr8r§rrrÚ_get_settings_varssT   "      " zConfigCLI._get_settings_varsc Cs|i}t| ¡ƒD�]d}||}t|tƒs*q| d¡sr| |¡}|D],}||vrb|| ||¡qB||||<qBqt|dtƒršd| dd¡|df}n"d| dd¡}|d |d¡7}d|vr|dr|dd}|d |vrðg||d <| d d ¡} | dd ¡d k�r&t| tƒ�s&d  | ¡} n| du�r4d } t j d�rPd|d|d<|d|d| f} ||d   | ¡q|S)Nr°z # (%s) %sr?rµz# (%s) z # rQr´r�rBr–rFr³rTz;%sÚkeyz %s=%s) ÚsortedÚkeysr¶rr�Ú_get_settings_iniÚextendrr·rrkr�) r3r¹ÚsectionsÚoÚoptZ new_sectionsÚsr8rrBr½rrrrÀ=s<          zConfigCLI._get_settings_inic CsNg}| ¡}| dd¡}tjddkrÌ| |¡}|r~|D]D}| ||¡}|D],}||vrn|| ||¡qN||||<qNq8|rÊ| ¡D]>}| d|¡||D]} | | ¡| d¡q¤| d¡qŠnftjddv�r2| |tjd¡}|�r2|D]8}|| ¡D]&} | | ||| tjd¡¡�qqø|  t d  |¡d d �¡dS) rPrªNrIrQz[%s]r–)rRrSÚ r…r†) r­ÚpoprrkrÀrÁr¿r�r¼r‰rr·) r3rr¬Z plugin_typesrÂrŸZplugin_sectionsrÅr�r½r¤rrrrcls4      &zConfigCLI.execute_initc Csîg}t|ƒD]Ü}||jdv}tjddkrª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ÚREQUIREDrIrMrBZgreenrÈZredZyellowz %s(%s) = %srK) r¾Úoriginrrkr¶r r€r�rÚ_fieldsr$r�) r3r0r¡rvZchangedZcolorÚmsgrr½rrrÚ_render_settings�s(   zConfigCLI._render_settingscCsV|jjdd� ¡}| ¡D]0}tjj||jtƒd�\}}t|||dƒ||<q|  |¡S)NTr©)ÚcfileÚ variables) r0ržÚcopyr¿r%Úget_config_value_and_originr/r+r rÌ)r3r0rvÚvrÃrrrÚ_get_global_configs°s  zConfigCLI._get_global_configsc Cs&ttd|ƒ}g}i}|rdg}|D]>}|j|dd�}|durLt d|¡q"| |j|dd�¡q"n |jdd�}|D�]ª}|j} } |  d¡r°t j   |j ¡ržqt|   ddd¡d} |j || ¡|| <z|j| dd�} WnJt�y} z0t d | |t| ƒf¡WYd} ~ qtWYd} ~ n d} ~ 00||  ¡D]œ} z"tjj| |j|| tƒd �\}}WnDt�y–} z*t| ƒ d ¡�r~d}d }n| ‚WYd} ~ n d} ~ 00|du�r°|du�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ÍZ plugin_typeZ plugin_namerÎz2No setting was provided for required configurationrÈrIrMú %s: %s)r$r™r�rMrtr�r@ršr#rlrmr›rœr�r0ržrsrr¿r%rÐr/r+r rr rÌrrkÚlenrÁ)r3rŸr r¢r®r¬r£r¤r¥r¦r§rrŒrvrÑrÃÚresultsrrrÚ_get_plugin_configs¸sR    "" zConfigCLI._get_plugin_configscCs8tjddkr| ¡}nÀtjddkrÀ| ¡}tjD]ˆ}| |tjd¡}tjddkr�tjdrf|r¼| d| ¡d t|ƒf¡|  |¡q4|d vr¢| ¡}n d | ¡}| ||i¡q4n| tjdtjd¡}tjddkrðd   |¡}tjdd k�r t |ƒ}ntjddk�r"t |ƒ}|  t|dd�¡dS)zM Shows the current settings, merges ansible.cfg if specified r?r>r@r4rIrMrKrÓrw)ÚmodulesZ doc_fragmentsz %s_PLUGINSrÆrrJr…r†N)rrkrÒr%rZrÖr�r«rÔrÁr·rrr‰r)r3r®rŸZ plugin_listZpnameÚtextrrrraþs,       zConfigCLI.execute_dump)N)N)Ú__name__Ú __module__Ú __qualname__Ú__doc__r§r2rUrerjrƒrbr‘r¨r­r`r¼rÀrcrÌrÒrÖraÚ __classcell__rrr6rr-5s& +  #   9/$ Fr-cCst |¡dSr.)r-Z cli_executor)r4rrrÚmain#srÞÚ__main__)FN)N)8Z __future__rrrr?Z __metaclass__Z ansible.clirrlrrŽr}Úcollections.abcrrzrZansible.plugins.loaderr r¢r™rr%Zansible.cli.argumentsr rVZansible.config.managerr r Zansible.errorsr r Zansible.module_utils._textrrrZ ansible.module_utils.common.jsonrZansible.module_utils.sixrZansible.parsing.quotingrZansible.parsing.yaml.dumperrZansible.utils.colorrZansible.utils.displayrZansible.utils.pathrrMrr r+r-rÞrÙrrrrÚs@             q