Adding nested variable example (#69518)
* Adding nested variable example to lib/ansible/plugins/lookup/vars.py Co-authored-by: Matt Martz <matt@sivel.net>
This commit is contained in:
parent
323d2adfcc
commit
0894ea1b1d
1 changed files with 10 additions and 2 deletions
|
@ -9,7 +9,7 @@ DOCUMENTATION = """
|
||||||
version_added: "2.5"
|
version_added: "2.5"
|
||||||
short_description: Lookup templated value of variables
|
short_description: Lookup templated value of variables
|
||||||
description:
|
description:
|
||||||
- Retrieves the value of an Ansible variable.
|
- 'Retrieves the value of an Ansible variable. Note: Only returns top level variable names.'
|
||||||
options:
|
options:
|
||||||
_terms:
|
_terms:
|
||||||
description: The variable names to look up.
|
description: The variable names to look up.
|
||||||
|
@ -43,6 +43,14 @@ EXAMPLES = """
|
||||||
- name: find several related variables
|
- name: find several related variables
|
||||||
debug: msg="{{ lookup('vars', 'ansible_play_hosts', 'ansible_play_batch', 'ansible_play_hosts_all') }}"
|
debug: msg="{{ lookup('vars', 'ansible_play_hosts', 'ansible_play_batch', 'ansible_play_hosts_all') }}"
|
||||||
|
|
||||||
|
- name: Access nested variables
|
||||||
|
debug: msg="{{ lookup('vars', 'variabl' + myvar).sub_var }}"
|
||||||
|
ignore_errors: True
|
||||||
|
vars:
|
||||||
|
variablename:
|
||||||
|
sub_var: 12
|
||||||
|
myvar: ename
|
||||||
|
|
||||||
- name: alternate way to find some 'prefixed vars' in loop
|
- name: alternate way to find some 'prefixed vars' in loop
|
||||||
debug: msg="{{ lookup('vars', 'ansible_play_' + item) }}"
|
debug: msg="{{ lookup('vars', 'ansible_play_' + item) }}"
|
||||||
loop:
|
loop:
|
||||||
|
|
Loading…
Reference in a new issue