From 0894ea1b1d50ef0f51f0ac7312fb9ec3d7d75872 Mon Sep 17 00:00:00 2001 From: Nick Busey Date: Thu, 28 May 2020 14:48:52 -0600 Subject: [PATCH] Adding nested variable example (#69518) * Adding nested variable example to lib/ansible/plugins/lookup/vars.py Co-authored-by: Matt Martz --- lib/ansible/plugins/lookup/vars.py | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/lib/ansible/plugins/lookup/vars.py b/lib/ansible/plugins/lookup/vars.py index 73e55219d3e..5895b93f9fc 100644 --- a/lib/ansible/plugins/lookup/vars.py +++ b/lib/ansible/plugins/lookup/vars.py @@ -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: