a )gV@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.Z1dddZ2ddZ3ddZ4GdddeZ5dddZ6e7dkrXe6dS) )absolute_importdivisionprint_function)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)ZDumperdefault_flow_style default_style)yamldumpr)datarrr6/usr/lib/python3.9/site-packages/ansible/cli/config.py yaml_dump&srcCst|dddS)NTz'')rr)r)rrrr yaml_short*sr cCs$ttdsddttDt_tjS)zE helper method to ensure we can template based on existing constants cvarscSs"i|]}|ds|tt|qS)__) startswithgetattrC).0krrr 1z!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__rrr2:szConfigCLI.__init__c stt|jddtjjdd}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 gd3d4d5d#|jd6d7d)dd8d9dS):NzView ansible configuration.)descF)add_help-cz--configr/zGpath to configuration file, defaults to first file found in precedence.)desthelpz-tz--typestorebasetypeallz&Filter down to a specific plugin type.)actiondefaultr;choicesr<r4z build a dict with the list requested configs r?)r>r@TZignore_privater>PLUGINSr@r4)rrkr0rr%rZrupper)r3config_entriesrrrr_list_entries_from_argss &z!ConfigCLI._list_entries_from_argscCsL|}tjddkr t|}ntjddkr6t|}|t|dddS)z3 list and output available configs rIrrJrrN)rrrkrrrr)r3routputrrrr`s  zConfigCLI.execute_listc Csg}tjdrd}nd}|D]}||ds2q||dd}|dkr||dd}|dkrr|rld }qd }n|r|d krt|tszd |}Wn0ty}zd t|}WYd}~n d}~00t|trt|st |}n |durd}|||vr|||r|||dd} t||dtr@||d} nd||d} ||d|} | d| ||dd| f|dkr| drq| d|| |fn:|dkr| drq| |d| t t|ddf| dq|S)NrT#r descriptionrBrRr?Zboolean10rF, z%srz #z # %s(%s): %sstringZ _ANSIBLE_z%s%s=%srSZ _ansible_z%s: %srr)rrkr isinstancerjoinrsrrrquoterr#rr ) r3settingsZsubkeyrprefixrvrBstyperrr8rrrr_get_settings_varssT   "      " zConfigCLI._get_settings_varsc Cs|i}t|D]d}||}t|ts*q|dsr||}|D],}||vrb||||qB||||<qBqt|dtrd|dd|df}n"d|dd}|d|d7}d|vr|dr|dd}|d |vrg||d <|d d } |dd d kr&t| ts&d | } n| dur4d } t j drPd|d|d<|d|d| f} ||d  | q|S)Nrz # (%s) %sr?rz# (%s) z # rQrrrBrrFrrTz;%skeyz %s=%s) sortedkeysrrr_get_settings_iniextendrrrrkr) r3rsectionsooptZ new_sectionssr8rrBrrrrr=s<          zConfigCLI._get_settings_inic CsNg}|}|dd}tjddkr||}|r~|D]D}|||}|D],}||vrn||||qN||||<qNq8|r|D]>}|d|||D]} || |dq|dqnftjddvr2||tjd}|r2|D]8}||D]&} ||||| tjdqq| t d |d d dS) rPrNrIrQz[%s]r)rRrS rr) rpoprrkrrrrrrrr) r3rrZ plugin_typesrrZplugin_sectionsrrrrrrrrcls4      &zConfigCLI.execute_initc Csg}t|D]}||jdv}tjddkrt||tr||jdkrNd}n||jdkrbd}nd}d |||j||jf}nd}d |d||df}t||}n&i}||j D]}t |||||<qtjd r|r | |q |S) N)rBREQUIREDrIrMrBZgreenrZredZyellowz %s(%s) = %srK) roriginrrkrr rrr_fieldsr$r) r3r0rrvZchangedZcolormsgrrrrr_render_settingss(   zConfigCLI._render_settingscCsV|jjdd}|D]0}tjj||jtd\}}t|||d||<q| |S)NTr)cfile variables) r0rcopyrr%get_config_value_and_originr/r+r r)r3r0rvvrrrr_get_global_configss  zConfigCLI._get_global_configsc Cs&ttd|}g}i}|rdg}|D]>}|j|dd}|durLtd|q"||j|ddq"n |jdd}|D]}|j} } | drt j |j rqt| dddd} |j|| || <z|j| dd} WnJty} z0td | |t| fWYd} ~ qtWYd} ~ n d} ~ 00|| D]} z"tjj| |j|| td \}}WnDty} z*t| d r~d}d }n| WYd} ~ n d} ~ 00|dur|durd }t| ||d|| | <q,||| }|rttjd dkr|d| dt| f||qt|| |iqt|S)NrTrrrrrrzMSkipping "%s" %s plugin, as we cannot load plugin to check config due to : %s)rZ plugin_typeZ plugin_namerz2No setting was provided for required configurationrrIrM %s: %s)r$rrrMrtrr@rr#rlrmrrrr0rrsrrr%rr/r+r rr rrrklenr)r3rrrrrrrrrrrrrvrrresultsrrr_get_plugin_configssR    "" zConfigCLI._get_plugin_configscCs8tjddkr|}ntjddkr|}tjD]}||tjd}tjddkrtjdrf|r|d|d t|f| |q4|d vr|}n d |}|||iq4n|tjdtjd}tjddkrd |}tjdd kr t |}ntjddkr"t |}| t|dddS)zM Shows the current settings, merges ansible.cfg if specified r?r>r@r4rIrMrKrrw)modulesZ doc_fragmentsz %s_PLUGINSrrrJrrN)rrkrr%rZrrrrrrrrrr)r3rrZ plugin_listZpnametextrrrras,       zConfigCLI.execute_dump)N)N)__name__ __module__ __qualname____doc__rr2rUrerjrrbrrrr`rrrcrrrra __classcell__rrr6rr-5s& +  #   9/$ Fr-cCst|dSr.)r-Z cli_executor)r4rrrmain#sr__main__)FN)N)8Z __future__rrrr?Z __metaclass__Z ansible.clirrlrrr}collections.abcrrzrZansible.plugins.loaderrrrrr%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-rrrrrrs@             q