Adding nested variable example (#69518)

* Adding nested variable example to lib/ansible/plugins/lookup/vars.py
Co-authored-by: Matt Martz <matt@sivel.net>
pull/69751/head
Nick Busey 5 years ago committed by GitHub
parent 323d2adfcc
commit 0894ea1b1d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -9,7 +9,7 @@ DOCUMENTATION = """
version_added: "2.5"
short_description: Lookup templated value of variables
description:
- Retrieves the value of an Ansible variable.
- 'Retrieves the value of an Ansible variable. Note: Only returns top level variable names.'
options:
_terms:
description: The variable names to look up.
@ -22,7 +22,7 @@ DOCUMENTATION = """
EXAMPLES = """
- name: Show value of 'variablename'
debug: msg="{{ lookup('vars', 'variabl' + myvar)}}"
debug: msg="{{ lookup('vars', 'variabl' + myvar) }}"
vars:
variablename: hello
myvar: ename
@ -43,6 +43,14 @@ EXAMPLES = """
- name: find several related variables
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
debug: msg="{{ lookup('vars', 'ansible_play_' + item) }}"
loop:

Loading…
Cancel
Save