varnames¶
Collection Note
This module is part of the ansible.builtin collection. To install the collection, use:
Added in version2.8.
Synopsis¶
- Retrieves a list of matching Ansible variable names.
Parameters¶
| Parameter | Defaults / Choices | Comments |
|---|---|---|
| _terms 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="{{ q('varnames', 'hosts') }}"
- name: Find several related variables that end specific way
ansible.builtin.debug: msg="{{ query('ansible.builtin.varnames', '.+_zone$', '.+_location$') }}"
- name: display values from variables found via varnames (note "*" is used to dereference the list to a 'list of arguments')
debug: msg="{{ lookup('vars', *lookup('varnames', 'ansible_play_.+')) }}"
Return Values¶
| Key | Data Type | Description | Returned |
|---|---|---|---|
| _value | list | List of the variable names requested. |
Authors¶
- Ansible Core Team