ansible.builtin.config (v2.16.5) — lookup

Lookup current Ansible configuration values

| "added in version" 2.5 of ansible.builtin"

Authors: Ansible Core Team

Install Ansible via pip

Install with pip install ansible-core==2.16.5

Description

Retrieves the value of an Ansible configuration setting.

You can use C(ansible-config list) to see all available settings.

Usage examples

  • Success
    Steampunk Spotter scan finished with no errors, warnings or hints.
    - name: Show configured default become user
      ansible.builtin.debug: msg="{{ lookup('ansible.builtin.config', 'DEFAULT_BECOME_USER')}}"
  • Success
    Steampunk Spotter scan finished with no errors, warnings or hints.
    - name: print out role paths
      ansible.builtin.debug:
        msg: "These are the configured role paths: {{lookup('ansible.builtin.config', 'DEFAULT_ROLES_PATH')}}"
  • Success
    Steampunk Spotter scan finished with no errors, warnings or hints.
    - 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"
  • Success
    Steampunk Spotter scan finished with no errors, warnings or hints.
    - name: see the colors
      ansible.builtin.debug: msg="{{item}}"
      loop: "{{lookup('ansible.builtin.config', 'COLOR_OK', 'COLOR_CHANGED', 'COLOR_SKIP', wantlist=True)}}"
  • Success
    Steampunk Spotter scan finished with no errors, warnings or hints.
    - 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
  • Success
    Steampunk Spotter scan finished with no errors, warnings or hints.
    - 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')}}
  • Success
    Steampunk Spotter scan finished with no errors, warnings or hints.
    - 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")}}

Inputs

    
_terms:
    description: The key(s) to look up
    required: true

on_missing:
    choices:
    - error
    - skip
    - warn
    default: error
    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
    type: string

plugin_name:
    description: name of the plugin for which you want to retrieve configuration settings.
    type: string
    version_added: '2.12'
    version_added_collection: ansible.builtin

plugin_type:
    choices:
    - become
    - cache
    - callback
    - cliconf
    - connection
    - httpapi
    - inventory
    - lookup
    - netconf
    - shell
    - vars
    description: the type of the plugin referenced by 'plugin_name' option.
    type: string
    version_added: '2.12'
    version_added_collection: ansible.builtin

show_origin:
    description: toggle the display of what configuration subsystem the value came from
    type: bool
    version_added: '2.16'
    version_added_collection: ansible.builtin

Outputs

_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