a )g@sddlmZmZmZeZdZdZdZddl m m Z ddl mZddlmZmZmZddlmZdd lmZdd lmZdd lmZGd d d eZddZddZGdddeZdS))absolute_importdivisionprint_functiona name: config author: Ansible Core Team version_added: "2.5" short_description: Lookup current Ansible configuration values description: - Retrieves the value of an Ansible configuration setting. - You can use C(ansible-config list) to see all available settings. options: _terms: description: The key(s) to look up required: True on_missing: description: - action to take if term is missing from config - Error will raise a fatal error - Skip will just ignore the term - Warn will skip over it but issue a warning default: error type: string choices: ['error', 'skip', 'warn'] 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: name of the plugin for which you want to retrieve configuration settings. type: string version_added: '2.12' 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")}} zM _raw: description: - value(s) of the key(s) in the config type: raw N) constants) AnsibleErrorAnsibleLookupErrorAnsibleOptionsError) to_native) string_types) LookupBase)Sentinelc@s eZdZdS)MissingSettingN)__name__ __module__ __qualname__rrA/usr/lib/python3.9/site-packages/ansible/plugins/lookup/config.pyr Tsr c CszNttd|}|j|dd}|dur6td||ftjj|||j|d}WnVtybYnDty}z,t |}d|vrt ||d|WYd}~n d}~00|S)Nz %s_loaderT)Z class_onlyzUnable to load %s plugin "%s") plugin_type plugin_name variableszwas not definedZorig_exc) getattr plugin_loadergetrCconfigZget_config_valueZ _load_namerr r ) pnameptyperrloaderpresultemsgrrr_get_plugin_configXs  r#c Cs\z"tt|}t|r td|Wn4tyV}ztt||dWYd}~n d}~00|S)NzInvalid setting "%s" attemptedr)rrcallablerAttributeErrorr r )rr r!rrr_get_global_configks &r&c@seZdZdddZdS) LookupModuleNc Ks,|j||d|d}|d}|d}|s4|rD|r<|sDtdt|trV|dvrbtd|g}|D]}t|tstd|t|ft} z |rt||||} nt|} Wnbt y} zH|d krt d || d n"|d kr|j d |n|dkrWYd} ~ n d} ~ 00| turj| | qj|S)N)Z var_optionsZdirectZ on_missingrrzOBoth 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 %srr)z!Skipping, did not find setting %sr*)Z set_optionsZ get_optionr isinstancer typer r#r&r rZ_displayZwarningappend) selfZtermsrkwargsmissingrrretZtermr r!rrrrunxs6       zLookupModule.run)N)rrrr2rrrrr'vsr') Z __future__rrrr,Z __metaclass__Z DOCUMENTATIONZEXAMPLESZRETURNZansible.plugins.loaderZpluginsrrZansiblerrZansible.errorsrrrZansible.module_utils._textr Zansible.module_utils.sixr Zansible.plugins.lookupr Zansible.utils.sentinelr r r#r&r'rrrrs