ansible.builtin.varnames lookup – Lookup matching variable names

Note

This lookup plugin is part of ansible-core and included in all Ansible installations. In most cases, you can use the short plugin name varnames. However, we recommend you use the Fully Qualified Collection Name (FQCN) ansible.builtin.varnames for easy linking to the plugin documentation and to avoid conflicting with other collections that may have the same lookup plugin name.

New in Ansible 2.8

Synopsis

  • Retrieves a list of matching Ansible variable names.

Terms

Parameter

Comments

Terms

string / required

List of Python regex patterns to search for in variable names.

Examples

- name: List variables that start with qz_
  ansible.builtin.debug: msg="{{ lookup('ansible.builtin.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
  ansible.builtin.debug: msg="{{ lookup('ansible.builtin.varnames', '.+')}}"

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

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

Return Value

Key

Description

Return value

list / elements=string

List of the variable names requested.

Returned: success

Authors

  • Ansible Core Team

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.