I am using a lookup method which returns a password (using cyberark.. but that is not relevant for this issue description)
When the password happens to contain a curly brace and there is a variable in second lookup parameter, the result is interpreted by jinja.
Here is a simplified example.
Among the inventory variables I have the following values:
existing_var: just a string
ansible_password: {{ lookup("mylookup", "{{ existing_var }}") }}
Where mylookup is a test lookup method, that returns always a single string "x{g{%Y" such as below. (this has to be stored in the lookup folder specified in the ansible config files, with name "mylookup.py".)
from __future__ import (absolute_import, division, print_function)
__metaclass__ = type
from ansible.errors import AnsibleError
from ansible.plugins.lookup import LookupBase
class LookupModule(LookupBase):
def run(self, terms, variables=None, **kwargs):
#we return always the same string without taking account of any parameter.
return ["x{g{%Y"]
I don t expect the lookup result to be interpreted.
But it is.
This lead to an ansible interpretation error : "encountered unknown tag Y .. string: {%Y".
Of course being a password in my real world case, the result is not meant to be interpreted.
I have noticed that this does not occur when there is no curly brace in the lookup second parameter.
ansible_password: {{ lookup("mylookup", "simple string without curly braces.")}}
How to avoid this interpretation?
To solve this issue, I have tried to increase log verbosity, and activated debug. There was no useful log, ansible fails as soon as the lookup method is called. I have stubbed the complex password lookup method to simplify the issue and present it here. I have tried to use the filters "safe" and "string", to no avail. I have removed the second parameter, and observed that in this case, the returned string is not interpreted.