Ansible: how to construct a variable from another variable and then fetch it’s value

If you have a variable like

vars:
myvar: xxx
xxx_var: anothervalue

the working Ansible syntax:

- debug: msg={{ vars[myvar + '_var'] }}

will give you the analogue of:

- debug: msg={{ xxx_var }}

Leave a Comment