String templating issue in lookup plugin command

I’ve got a Playbook that uses a lookup plugin to retrieve a value but I seem to have a string templating issue.

This is my playbook:

`

I've got a Playbook that uses a lookup plugin to retrieve a value but I seem to have a string templating issue.

This is my playbook:

>
---
-name:retrieve password
hosts:localhost
gather_facts:no

vars:
vmware_user:"SOMEUSER"

\# This Doesn't work:
vmware\_password:"\{\{ lookup\('cyberarkpassword', AppID='myapp', Query='address=mydomain\.corp;username=\{\{ vmware\_user

}}', Output='Password').password }}"

\# This works:
\# vmware\_password: "\{\{ lookup\('cyberarkpassword', AppID='myapp', Query='address=mydomain\.corp;username=SOMEUSER',

Output='Password').password }}"
>

The curly braces can't be nested, so in this case you try to use vars['vmware_user'] instead.

Regards
         Racke

You are already in template mode so you can't use {{ }} inside {{ }}.
You need to use string concatenation with tilde, so I think this should work.

vmware_password: "{{ lookup('cyberarkpassword', AppID='myapp', Query='address=mydomain.corp;username=' ~ vmware_user, Output='Password').password }}"