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

Lookup matching variable names

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

Authors: Ansible Core Team

Install Ansible via pip

Install with pip install ansible-core==2.16.5

Description

Retrieves a list of matching Ansible variable names.

Usage examples

  • Success
    Steampunk Spotter scan finished with no errors, warnings or hints.
- 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"
  • Success
    Steampunk Spotter scan finished with no errors, warnings or hints.
- name: Show all variables
  ansible.builtin.debug: msg="{{ lookup('ansible.builtin.varnames', '.+')}}"
  • Success
    Steampunk Spotter scan finished with no errors, warnings or hints.
- name: Show variables with 'hosts' in their names
  ansible.builtin.debug: msg="{{ lookup('ansible.builtin.varnames', 'hosts')}}"
  • Success
    Steampunk Spotter scan finished with no errors, warnings or hints.
- name: Find several related variables that end specific way
  ansible.builtin.debug: msg="{{ lookup('ansible.builtin.varnames', '.+_zone$', '.+_location$') }}"

Inputs

    
_terms:
    description: List of Python regex patterns to search for in variable names.
    required: true

Outputs

_value:
  description:
  - List of the variable names requested.
  type: list