config¶
Collection Note
This module is part of the ansible.builtin collection. To install the collection, use:
Added in version2.5.
Synopsis¶
- Retrieves the value of an Ansible configuration setting, resolving all sources, from defaults, ansible.cfg, environment, 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.
Parameters¶
| Parameter | Defaults / Choices | Comments |
|---|---|---|
| _terms required |
The option(s) to look up. | |
| on_missing string |
Default: error Choices: error, skip, warn |
Action to take if term is missing from config |
| plugin_name string |
The name of the plugin for which you want to retrieve configuration settings. Version Added: 2.12 |
|
| plugin_type string |
Choices: become, cache, callback, cliconf, connection, httpapi, inventory, lookup, netconf, shell, vars | The type of the plugin referenced by 'plugin_name' option. Version Added: 2.12 |
| show_origin bool |
Set this to return what configuration subsystem the value came from (defaults, config file, environment, CLI, or variables). Version Added: 2.16 |
Notes¶
Note
- 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.
Examples¶
- 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")}}
Return Values¶
| Key | Data Type | Description | Returned |
|---|---|---|---|
| _raw | raw | 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 |
Authors¶
- Ansible Core Team