I generate a list of users members of a group:
"ansible_facts": {
"adminsys_members": [
"user1",
"user2",
"user3",
], ...
And I want to use it as a string in a json_query
filtering expression, but if I just write:
query: "[?contains( {{ adminsys_members }}, username)].authorized_keys"
I obtain (debug in execution):
"query": "[?contains( [u'ulvida', u'apias', u'cchoque', u'vtorterola', u'santiagomr4', u'victor'], username)].authorized_keys"
And then when I try to execute the json_query:
debug:
msg: "{{ users | json_query( query ) }}"
It fails with:
fatal: [ta.interior.edu.uy]: FAILED! => {
"msg": "Error in jmespath.search in json_query filter plugin:\n'literal'"
}
When I manually define my query, with the appropriate syntax and quotes in list:
query: "[?contains( ['user1', 'user2', 'user3'], username)].authorized_keys"
It works ok.
I'm puzzled in building a filter that gives me the string:
['user1', 'user2', 'user3']
when I apply it to the list:
"adminsys_members": [
"user1",
"user2",
"user3",
]
I think I'm not too far from this bug where the only solution I din't try is to define a new filter n python, and this bug, which only answer doesn't work.
Am I in a hell of impossible escaping of characters? Thanks in advance.