varnames – Lookup matching variable names — Ansible Documentation

- AnsibleFest
- Products
- Community
- Webinars & Training
- Blog

Documentation

# varnames – Lookup matching variable names

New in version 2.8.

- Synopsis
- Parameters
- Examples
- Return Values
- Status

## Synopsis

- Retrieves a list of matching Ansible variable names.

## Parameters

Parameter | Choices/Defaults | Configuration | Comments
--- | --- | --- | ---
_terms - / required |  |  | List of Python regex patterns to search for in variable names.

## Examples

    - name: List variables that start with qz_
      debug: msg="{{ lookup('varnames', '^qz_.+')}}"
      vars:
        qz_1: hello
        qz_2: world
        qa_1: "I won't show"
        qz_: "I won't show either"

    - name: Show all variables
      debug: msg="{{ lookup('varnames', '.+')}}"

    - name: Show variables with 'hosts' in their names
      debug: msg="{{ lookup('varnames', 'hosts')}}"

    - name: Find several related variables that end specific way
      debug: msg="{{ lookup('varnames', '.+_zone$', '.+_location$') }}"

## Return Values

Common return values are documented here, the following are the fields unique to this lookup:

Key | Returned | Description
--- | --- | ---
_value list |  | List of the variable names requested.

## Status

- This lookup is not guaranteed to have a backwards compatible interface. [preview]
- This lookup is maintained by the Ansible Community. [community]

### Authors

- Ansible Core

Hint

If you notice any issues in this documentation, you can edit this document to improve it.

Hint

Configuration entries for each entry type have a low to high priority order. For example, a variable that is lower in the list will override a variable that is higher up.