Hi,
I’m trying to build an ansible playbook that would be able to execute a SQL query and then parse the command output to play with the data and update some stuff from it.
My SQL request looks like:
SELECT row_to_json(tmp) FROM ( SELECT distinct … ) tmp;
SO far so good. I’m getting a whole lot of output… My only problem is that… the output comes as a list of items, each of them looking like:
{"hostname":"172.27.2.176","string":"public","version":"1"}
Full result.stdout_lines output looks like:
[ " {"hostname":"172.27.2.176","string":"public","version":"1"}“,
" {"hostname":"172.27.7.178","string":"private","version":"1"}”,
" {"hostname":"172.27.1.174","string":"public","version":"2"}"
]
My problem… the backslashes. The json parser is unable, as it seem, to understand the json construct when there are backslashes. As least, as it seem. If I try to debug it with debug (and typing, for example, msg=“{{ item.hostname }}”, or msg=“{{ item[‘hostname’] }}”, or even msg=“{{ item.[hostname] }}”, it just keeps telling me that I’m trying to use a variable that is undefined.
In fact, I’m not sure that this is the backslashes which are the issues. Maybe I’m not accessing the output the right way ?
Thanks,
Christian