o nnhX@sRddlmZddlmZddlZddlZddlZddlZddlm Z ddl m Z ddl m mZddl mZddlmZddlmZmZdd lmZmZdd lmZmZmZdd lm Z dd l!m"Z"dd l#m$Z$ddl%m&Z&ddl'm(Z(ddl)m*Z*ddl+m,Z,e*Z-dddZ.ddZ/ddZ0GdddeZ1dddZ2e3dkre2dSdS) ) annotations)CLIN)Mapping)context) constants)option_helpers) ConfigManagerSetting) AnsibleErrorAnsibleOptionsError) to_nativeto_textto_bytes) json_dump) string_types) is_quoted) AnsibleDumper)stringc)Display) unfrackpathFcCstj|t||dS)N)Dumperdefault_flow_style default_style)yamldumpr)datarrr=/usr/local/lib/python3.10/dist-packages/ansible/cli/config.py yaml_dump%srcCst|dddS)NTz'')rr)r)rrrr yaml_short)rcCs$ttdsddttDt_tjS)zE helper method to ensure we can template based on existing constants cvarscSs"i|] }|ds|tt|qS)__) startswithgetattrC).0krrr 0s"z!get_constants..)hasattr get_constantsdirr%r!rrrrr*-s r*cseZdZdZdZd&fdd ZfddZfdd Zfd d Zd d Z ddZ ddZ d&ddZ ddZ ddZddZddZddZddZd d!Zd"d#Zd$d%ZZS)' ConfigCLIz Config command line class zansible-configNcs"d|_d|_tt|||dSN) config_fileconfigsuperr,__init__)selfargscallback __class__rrr19szConfigCLI.__init__c stt|jddtjdd}t||jddddd |jd d d d ddd gttj dd|jdddd|j j dd}d|_ |j dd|gd}|j|jd|jdddd d d!gd!d"d#|j d$d%|gd}|j|jd|jd&d'd(d)d*d+|jdddd gd,d-d.d#|j d/d0|gd}|j|jd|j d1d2|gd}|j|jd|jdddd gd3d4d5d#|jd6d7d)dd8d9dS):NzView ansible configuration.)descF)add_helpz-cz--configr.zGpath to configuration file, defaults to first file found in precedence.)desthelpz-tz--typestorebasetypeallz&Filter down to a specific plugin type.)actiondefaultr9choicesr:r3z _load_namer#rprqislink_original_pathreplacer/get_configuration_definitions) r2ptypepluginsentriesloader plugin_cspluginp finalnamenamerrr_list_plugin_settingss&    zConfigCLI._list_plugin_settingscCsi}tjddvr|jjdd}tjddkri|d<tjddkr5tjD] }|||d|<q%|StjddkrO|tjdtjd|dtjd<|S) z> build a dict with the list requested configs r=)r<r>Tignore_privater<PLUGINSr>r3)rror/rr%rXrupper)r2config_entriesrrrr_list_entries_from_argss &z!ConfigCLI._list_entries_from_argscCsL|}tjddkrt|}n tjddkrt|}|t|dddS)z3 list and output available configs rGrrHrrN)rrrorrrr )r2routputrrrr^s  zConfigCLI.execute_listc Csg}tjdr d}nd}|D]}||dsq|j||ddt}|dkr~||dd}|dkr>|r;d }nCd }n@|rx|d krit|tsizd |}Wnt yh}z d t |}WYd}~nd}~wwt|trwt |swt |}n|dur~d}|||vr|||r|||dd} t||dtr||d} n d||d} ||d|} |d| ||dd| f|dkr| drq|d|| |fn|dkr| drq||d| tt|ddf|dq|S)NrR#r descriptionr@rPr=boolean10rD, z%srz #z # %s(%s): %sstring _ANSIBLE_z%s%s=%srQ _ansible_z%s: %srr)rrorr/template_defaultr* isinstancerjoinrxr rrquoterr#r r) r2settingssubkeyrprefixsettingr@styperrr7rrrr_get_settings_varss\      " zConfigCLI._get_settings_varsc Csi}t|D]}||}t|tsq|ds9|||}|D]}||vr1||||q!||||<q!qt|dtrMd|dd|df}nd|dd}|d|d7}d|vr|dr|dd} | d |vrxg|| d <| d |vrg|| d <| d || d vr|| d  | d |j |d d t } |dd d krt| tsd| } n| durd } t jdrd| d | d <|d| d | f} || d  | q|S)Nrz # (%s) %sr=rz# (%s) z # rOrrkeyr@rrDrrRz;%sz %s=%s)sortedkeysrrr_get_settings_iniextendrrrr/rr*rro) r2rseensectionsoopt new_sectionssr7rr@rrrrr<sF          zConfigCLI._get_settings_inic CsPi}g}|}|dd}tjddkrj|||}|rC|D]#}||||}|D]}||vr;||||q+||||<q+q|ri|D]} |d| || D] } || |dqV|dqIn0tjddvr||tjd}|r|D]}||D]} ||||| tjdqq~| t d |d d dS) rNrNrGrOz[%s]r)rPrQ rr) rpoprrorrrrrrr r) r2rrr plugin_typesrrplugin_sectionsrrrrrrrrars<       "zConfigCLI.execute_initc Csg}t|D]x}||jdv}tjddkr_t||trK||j}||jdkr4d}|j|t }n ||jdkr>d}nd}d |||j|f}nd}d |d|| df}t ||}ni}||j D] } t ||| || <qftjd ry|r~||q|S) N)r@REQUIREDrGrKr@greenrredyellowz %s(%s) = %srI)roriginrrorr rr/rr*rr_fieldsr$r) r2r/rrchangedrcolormsgrrrrr_render_settingss.    zConfigCLI._render_settingscCsV|jjdd}|D]}tjj||jtd\}}t|||d||<q | |S)NTr)cfile variables) r/rcopyrr%get_config_value_and_originr.r*r r)r2r/rvrrrr_get_global_configss   zConfigCLI._get_global_configsc Cs ttd|}g}i}|r2g}|D]}|j|dd}|dur&td|q||j|ddqn|jdd}|D]}|j} } | drWt j |j rNq:| dddd} |j|| || <z |j| dd} Wnty} ztd | |t| fWYd} ~ q:d} ~ ww|| D]I} ztjj| |j|| td \}}Wn ty} zt| d rd}d }n| WYd} ~ nd} ~ ww|dur|durd }t| ||d|| | <q||| }|rtjd dkr|d| dt| f||q:|| |iq:|S)NrTrrrrrrzMSkipping "%s" %s plugin, as we cannot load plugin to check config due to : %s)r plugin_type plugin_namerz2No setting was provided for required configurationrrGrK %s: %s)r$rrrKryrr>rr#rprqrrrr/rrxr rr%rr.r*r r r rrrolenr)r2rrrrrrrrrrrrrrrresultsrrr_get_plugin_configss`    "  zConfigCLI._get_plugin_configscCs4tjddkr |}n`tjddkr`|}tjD]D}||tjd}tjddkrHtjdr3|rG|d|d t|f| |q|d vrQ|}nd |}|||iqn |tjdtjd}tjddkrxd |}tjdd krt |}n tjddkrt |}| t|dddS)zM Shows the current settings, merges ansible.cfg if specified r=r<r>r3rGrKrIr=)modules doc_fragmentsz %s_PLUGINSrrrHrrN)rrorr%rXrrrrrrrrrr )r2rr plugin_listpnametextrrrr_s0       zConfigCLI.execute_dumpr-)__name__ __module__ __qualname____doc__rr1rSrgrnrr`rrrr^rrrarrrr_ __classcell__rrr5rr,4s(  + #  96%"Fr,cCst|dSr-)r, cli_executor)r3rrrmain,r r__main__)FNr-)4 __future__r ansible.clirrprrr~collections.abcransibleransible.plugins.loaderrrrrr%ansible.cli.argumentsrrTansible.config.managerrr ansible.errorsr r +ansible.module_utils.common.text.convertersr r r ansible.module_utils.common.jsonransible.module_utils.sixransible.parsing.quotingransible.parsing.yaml.dumperransible.utils.colorransible.utils.displayransible.utils.pathrrKrrr*r,rrrrrrsB               {