a )gb@snddlmZmZmZeZddlZddlZddlZddl Zddl Z ddl Z ddl Z ddl Z ddlmZddlmZmZddlmZddlmZmZddlmZmZmZddlmZdd lmZdd l m!Z!dd l"m#Z#dd l$m%Z%dd l&m'Z'ddl(m)Z)m*Z*m+Z+eddZ,eddZ-ddiZ.ddZ/d%ddZ0d&ddZ1ddZ2ddZ3d'dd Z4d!d"Z5Gd#d$d$e6Z7dS)()absolute_importdivisionprint_functionN) namedtuple)MappingSequence)NativeEnvironment)AnsibleOptionsError AnsibleError)to_textto_bytes to_native) yaml_load) string_types)boolean)unquote)AnsibleVaultEncryptedUnicode) py3compat)cleanup_tmp_file makedirs_safe unfrackpathPluginz name typeSettingzname value origin typelookup)Z_termscCs4d}|r$|d|7}|r$|d|7}|d|7}|S)z& construct entry for requested config zplugin_type: %s z plugin: %s z setting: %s ) plugin_type plugin_nameconfigentryrr:/usr/lib/python3.9/site-packages/ansible/config/manager.py _get_entry%s   r!csd}d|r,tj|r,tjt|r,||r8|}|dur|dvrZt|dd}n.|dvrnt|}n|dkrt|}n|dkrt |t rd d | d D}nt |t sd}n|d kr|d krd}|durd }n|dkr t |t rt |d}nd}n||dvrzt |t rrt |d}tj|sFt|ddt}tj||d}tjt|ddnd}n|dkrt |t r| tj}t |t rfdd |D}nd}n|dkrt |t rdd | d D}t |t r fdd |D}nd}nv|dvr.t |tsd}nZ|dvrht |t tttttfrbtt|dd }nd!}n t |t tfrtt|dd }|rtd"|t|ft|dd#d$S)%a return a configuration variable with casting :arg value: The value to ensure correct typing of :kwarg value_type: The type of the value. This can be any of the following strings: :boolean: sets the value to a True or False value :bool: Same as 'boolean' :integer: Sets the value to an integer or raises a ValueType error :int: Same as 'integer' :float: Sets the value to a float or raises a ValueType error :list: Treats the value as a comma separated list. Split the value and return it as a python list. :none: Sets the value to None :path: Expands any environment variables and tilde's in the value. :tmppath: Create a unique temporary directory inside of the directory specified by value and return its path. :temppath: Same as 'tmppath' :tmp: Same as 'tmppath' :pathlist: Treat the value as a typical PATH string. (On POSIX, this means colon separated strings.) Split the value and then expand each part for environment variables and tildes. :pathspec: Treat the value as a PATH string. Expands any environment variables tildes's in the value. :str: Sets the value to string types. :string: Same as 'str' rN)rboolF)strict)ZintegerintfloatlistcSsg|]}t|qSr)rstrip.0xrrr _zensure_type..,ZnoneNonepathbasedir)tmptemppathZtmppathizansible-local-%s)prefixdirT)warnr3Zpathspeccsg|]}t|dqSr0 resolve_pathr(r0rr r+r,ZpathlistcSsg|] }|qSr)r'r(rrr r+r,csg|]}t|dqSr7r8r(r0rr r+r,)dict dictionaryr;)strstringsurrogate_or_stricterrorsr=z"Invalid type provided for "%s": %sZpassthru)r@Z nonstring)osr/isabsexistsr lowerrr$r% isinstancersplitrr9rgetpidtempfileZmkdtempatexitregisterrpathseprrr"complexrr ValueErrorr )valueZ value_typeoriginerrmsgr4rr0r ensure_type1sx                       rQcCs&d|vr|dt}t|d|dS)z& resolve relative or 'variable' paths z{{CWD}}F)followr1)replacerAgetcwdr)r/r1rrr r9sr9cCsPd}|durLtj|d}|dvr*d}n"|dvr8d}ntd|t|f|S)N)z.iniz.cfgini)z.yamlz.ymlyamlz3Unsupported configuration file extension for %s: %s)rAr/splitextr r )cfileftypeextrrr get_config_typesr\cCsHd}|durDz$|j|dd|dddd}WntyBYn0|S)z+ returns the value of last ini entry found NsectiondefaultskeyrT)raw)get Exception)prrNrrr get_ini_config_values$ rdc CsB|durt}t}g}td|}||ur^t|dd}tjt|rTtj|d}| |d}zTt }t |}tj|d}|j t j @rtj|rd}n| t|ddWntyYn0| td dd| d |D],}t|} tj| rt| tjrqqd}||kr>|r>|d t||S) zO Load INI Config File order(first found is used): ENV, CWD, HOME, /etc/ansible NZANSIBLE_CONFIGF)rRz ansible.cfgTr>r?z~/.ansible.cfgz/etc/ansible/ansible.cfgzAnsible is being run in a world writable directory (%s), ignoring it as an ansible.cfg source. For more information see https://docs.ansible.com/ansible/devel/reference_appendices/config.html#cfg-in-world-writable-dir)setobjectrAgetenvrr/isdirr joinappendrTstatst_modeS_IWOTHrCr OSErroraccessR_OKadd) warningsZSENTINELZpotential_pathsZ path_from_envZwarn_cmd_publiccwdZpermsZcwd_cfgr/b_pathrrr find_ini_config_filesB        rucCsNdd}|D]8\}}||dD]"}||vr$||D] }||q8q$qdS)zDAdd deprecation source 'ansible.builtin' to deprecations in base.ymlcSsd|vrd|dd<dS)N deprecatedzansible.builtinZcollection_namer)rrrr process sz,_add_base_defs_deprecations..process)rVenvvarsN)items)Z base_defsrwZdummydatar]rrrr _add_base_defs_deprecationss r|c@seZdZgZeZdddZddZd ddZdd Z d!d d Z d d Z ddZ d"ddZ ddZd#ddZddZd$ddZd%ddZddZdS)& ConfigManagerNcCsvi|_i|_i|_||_||p.dtjt|_t |j|jdurTt |j |_|jrb| ddd|jd<dS)Nz %s/base.ymlr/)defaulttype CONFIG_FILE) _base_defs_plugins_parsers _config_file_read_config_yaml_filerAr/dirname__file__r|ruWARNINGS_parse_config_file)selfZ conf_fileZ defs_filerrr __init__s   zConfigManager.__init__cCs^t|}tj|rJt|d}t|p*iWdS1s@0Ytdt|dS)Nrbz4Missing base YAML definition file (bad install?): %s)r rAr/rCopenrr r )rZyml_fileZ config_defrrr r1s  * z$ConfigManager._read_config_yaml_filec Cs |dur|j}t|}|dur|dkr tjdd|j|<tt|d^}zt|dd}Wn8t y}z t d|t |fWYd}~n d}~00Wdn1s0Yz|j| |Wn<tj y}z t d |t |fWYd}~n d}~00nt d t |dS) z1 return flat configuration settings from file(s) NrV);)Zinline_comment_prefixesrr>r?zNError reading config file(%s) because the config file was not utf8 encoded: %sz"Error reading config file (%s): %sz'Unsupported configuration file type: %s)rr\ configparserZ ConfigParserrrr r read UnicodeErrorr r Z read_stringError)rrYrZfZcfg_texterrr r;s   H,z ConfigManager._parse_config_filecCsdS)zL Load YAML Config Files in order, check merge flags, keep origin of settingsNr)rrrr _find_yaml_config_filesVsz%ConfigManager._find_yaml_config_filesc Cs8i}|||}|D]}|j||||||d||<q|S)N)rrkeys variablesdirect)get_configuration_definitionsget_config_value) rrnamerrroptionsdefsoptionrrr get_plugin_optionsZs  z ConfigManager.get_plugin_optionscCsJg}|||D]0}d|vr|dr|dD]}||dq0q|SNryr)rvaluesrj)rrrZpvarspdef var_entryrrr get_plugin_varscs  zConfigManager.get_plugin_varscCsVg}|||D]<\}}d|vr|dr|dD]}||dkr4||q4q|Sr)rrzrj)rrrvariablerZ option_namerrrrr get_plugin_options_from_varls  z)ConfigManager.get_plugin_options_from_varcCs^i}|dur|j|d}n>|dur<|j|i|d}n|j|i|i|d}|SN)rrar)rrrrretrrr get_configuration_definitionvsz*ConfigManager.get_configuration_definitioncCs d}||jvr||j|v}|S)NFr)rrrZhasrrr has_configuration_definitions z*ConfigManager.has_configuration_definitionFcCsli}|dur|j}n.|dur,|j|i}n|j|i|i}|rht|D]}|drR||=qR|S)zP just list the possible settings, either base or for specific plugins or plugin N_)rrrar&r startswith)rrrZignore_privaterZcdefrrr rs z+ConfigManager.get_configuration_definitionsc Csd}d}|D]}|d}z||d}Wn,tyV|jdt|Yq Yn0|dur t|trvt|dd}|}|}d|vr |j |d|dfq ||fS)z( repeat code for value entry assignment NrzCvalue for config entry {0} contains invalid characters, ignoring...r>r?rv) raUnicodeEncodeErrorrrqformatr rEr DEPRECATEDrj)r containerZ entry_listrNrOrr temp_valuerrr _loop_entriess"     zConfigManager._loop_entriesc Cstz |j|||||||d\}} WnNty4Yn<tyn} z$td|t| f| dWYd} ~ n d} ~ 00|S)z wrapper )rYrrrrrz*Unhandled exception when retrieving %s: %s)Zorig_excN)get_config_value_and_originr rbr ) rrrYrrrrrrNZ_droprrrr rs  .zConfigManager.get_config_valuec s|dur|j}dkr|dfSd}d} |||vrdg} rvrf}d} n"fdd| D} | r| d}d} |dur|rˆd r||d \}} d | } |durd r|r||d \}} d | } |durd|rd|vr$|}} n.| rR| D]"} | |vr.|| }| } qRq.|durdd | } |durd vrddlm}||jd \}} d| } |durdr|tjd\}} d| } |j |ddur| ||dur|durt |}|r|r|dkrzhdD]V}t |j ||}|durN|}|} d|vrN|j d|d|df|dfqNWn>ty}z$tjd|t|fWYd}~n d}~00n|dkr|} |durddrF|r,t|ivrtdtt||npd} d}t|tr|dr|dr|durzt|}||}WntyYn0zt|d| d }Wnty\}zp| d!r"|dkr"d} tdd| d }n&t d"tt||!| t|fWYd}~n d}~00|durd#vrd#durd$}dd%krt"fd&d'|D }n|d#v}|rtd#t#rd($d)dd#%D}n`td#tr*d#}n>td#t&r\d($d*dd#D}n d#}t d+|tt|||fdvr| dkr|j dfntd,tt|||| fS)-zY Given a config key figure out the actual value and report on the origin of the settings NrraliasesZDirectcsg|]}|vr|qSrr)r)alias)rrr r+r,z=ConfigManager.get_config_value_and_origin..rryzvar: %skeywordz keyword: %sZcli)contextzcli: %srxzenv: %srVrvz[%s]%sr]r_z%Error while loading ini config %s: %srWrequiredFz5No setting was provided for required configuration %sr~z{{z}}r)rOzenv:z6Invalid type for configuration option %s (from %s): %schoicesTr&c3s|]}|dvVqdS)rNr)r)choice)rrrr ?r,z.z, cSsg|] }t|qSrr )r)krrr r+Gr,cSsg|] }t|qSrr)r)crrr r+Kr,zFInvalid value "%s" for configuration option "%s", valid values are: %sz6Requested entry (%s) was not defined in configuration.)'rrrarZansiblerZCLIARGSrenvironrrr\rdrrjrbsysstderrwriter INTERNAL_DEFSr r!rErrendswithrZ from_stringZrenderrQrMr r'allrrirr)rrrYrrrrrrNrOrZdirect_aliasesrrrrZZ ini_entryrrtZinvalid_choicesZvalidr)rrrr rs           ,0  . $*" z)ConfigManager.get_config_value_and_origincCs&||jvri|j|<||j||<dSrr)rrrrrrr +initialize_plugin_configuration_definitionsZs  z9ConfigManager.initialize_plugin_configuration_definitions)NN)N)NNN)NN)NNF)NNNNNN)NNNNNN)__name__ __module__ __qualname__rrerrrrrrrrrrrrrrrrrrr r}s"       r})N)N)N)8Z __future__rrrrZ __metaclass__rIrrAZos.pathrrkrH traceback collectionsrcollections.abcrrZjinja2.nativetypesrZansible.errorsr r Zansible.module_utils._textr r r Z ansible.module_utils.common.yamlrZansible.module_utils.sixrZ)ansible.module_utils.parsing.convert_boolrZansible.parsing.quotingrZansible.parsing.yaml.objectsrZ ansible.utilsrZansible.utils.pathrrrrrrr!rQr9r\rdrur|rfr}rrrr s@           q  A