o nnh@sddlmZdZdZdZddlmmZddl m Z ddl m Z mZmZddlmZdd lmZdd lmZdd lmZGd d d eZddZddZGdddeZdS)) annotationsaK name: config author: Ansible Core Team version_added: "2.5" short_description: Display the 'resolved' Ansible option values. description: - Retrieves the value of an Ansible configuration setting, resolving all sources, from defaults, ansible.cfg, envirionmnet, CLI, and variables, but not keywords. - The values returned assume the context of the current host or C(inventory_hostname). - You can use C(ansible-config list) to see the global available settings, add C(-t all) to also show plugin options. options: _terms: description: The option(s) to look up. required: True on_missing: description: Action to take if term is missing from config default: error type: string choices: error: Issue an error message and raise fatal signal warn: Issue a warning message and continue skip: Silently ignore plugin_type: description: The type of the plugin referenced by 'plugin_name' option. choices: ['become', 'cache', 'callback', 'cliconf', 'connection', 'httpapi', 'inventory', 'lookup', 'netconf', 'shell', 'vars'] type: string version_added: '2.12' plugin_name: description: The name of the plugin for which you want to retrieve configuration settings. type: string version_added: '2.12' show_origin: description: Set this to return what configuration subsystem the value came from (defaults, config file, environment, CLI, or variables). type: bool version_added: '2.16' notes: - Be aware that currently this lookup cannot take keywords nor delegation into account, so for options that support keywords or are affected by delegation, it is at best a good guess or approximation. a  - name: Show configured default become user ansible.builtin.debug: msg="{{ lookup('ansible.builtin.config', 'DEFAULT_BECOME_USER')}}" - name: print out role paths ansible.builtin.debug: msg: "These are the configured role paths: {{lookup('ansible.builtin.config', 'DEFAULT_ROLES_PATH')}}" - name: find retry files, skip if missing that key ansible.builtin.find: paths: "{{lookup('ansible.builtin.config', 'RETRY_FILES_SAVE_PATH')|default(playbook_dir, True)}}" patterns: "*.retry" - name: see the colors ansible.builtin.debug: msg="{{item}}" loop: "{{lookup('ansible.builtin.config', 'COLOR_OK', 'COLOR_CHANGED', 'COLOR_SKIP', wantlist=True)}}" - name: skip if bad value in var ansible.builtin.debug: msg="{{ lookup('ansible.builtin.config', config_in_var, on_missing='skip')}}" var: config_in_var: UNKNOWN - name: show remote user and port for ssh connection ansible.builtin.debug: msg={{q("ansible.builtin.config", "remote_user", "port", plugin_type="connection", plugin_name="ssh", on_missing='skip')}} - name: show remote_tmp setting for shell (sh) plugin ansible.builtin.debug: msg={{q("ansible.builtin.config", "remote_tmp", plugin_type="shell", plugin_name="sh")}} z _raw: description: - A list of value(s) of the key(s) in the config if show_origin is false (default) - Optionally, a list of 2 element lists (value, origin) if show_origin is true type: raw N) constants) AnsibleErrorAnsibleLookupErrorAnsibleOptionsError) to_native) string_types) LookupBase)Sentinelc@s eZdZdS)MissingSettingN)__name__ __module__ __qualname__rrH/usr/local/lib/python3.10/dist-packages/ansible/plugins/lookup/config.pyr ]sr c Csz,ttd|}|j|dd}|durtd||ftjj|||j|d\}}W||fSty4tyO}zt |} d| vrIt | |d|d}~ww)Nz %s_loaderT) class_onlyzUnable to load %s plugin "%s") plugin_type plugin_name variableszwas not definedorig_exc) getattr plugin_loadergetrCconfigget_config_value_and_origin _load_namerrr ) pnameptyperrloaderpresultoriginemsgrrr_get_plugin_configas   r&c CsNztt|}t|rtd|W|Sty&}ztt||dd}~ww)NzInvalid setting "%s" attemptedr)rrcallablerAttributeErrorr r)rr"r$rrr_get_global_configts  r)c@seZdZdddZdS) LookupModuleNc KsP|j||d|d}|d}|d}|d}|s|r'|r#|s'tdt|tr0|dvr6td|g}|D]k} t| tsKtd | t| ft} d} z|r\t||| |\} } nt| } Wn0t y} z$|d krut d | | d |d kr|j d| n|dkr WYd} ~ nd} ~ ww| tur|r| | | fq:| | q:|S)N) var_optionsdirect on_missingrr show_originzOBoth plugin_type and plugin_name are required, cannot use one without the other)errorwarnskipzJ"on_missing" must be a string and one of "error", "warn" or "skip", not %sz:Invalid setting identifier, "%s" is not a string, its a %sr/zUnable to find setting %srr0z!Skipping, did not find setting %sr1) set_options get_optionr isinstancertyper r&r)r r_displaywarningappend) selftermsrkwargsmissingrrr.rettermr"r#r$rrrrunsF       zLookupModule.run)N)r r rr?rrrrr*sr*) __future__r DOCUMENTATIONEXAMPLESRETURNansible.plugins.loaderpluginsr ransiblerransible.errorsrrr+ansible.module_utils.common.text.convertersransible.module_utils.sixransible.plugins.lookupr ansible.utils.sentinelr r r&r)r*rrrrs )