Hello
I’ve trying to get it working for hours now and no luck.
I’m querying Proxmox LXC network info from the API and the structure is:
json
data
ip-addresses
lo: ip-address
eth0: ip-address
The task looks like this:
- name: Get LXC IP address
ansible.builtin.debug:
var: item
loop: '{{ lxclist.json | community.general.json_query("data[?name==`eth0`].ip-addresses") }}'
tags: apitest
NOTE: If I remove the .ip-addresses
part, it works, I get the whole eth0 network info, but I want to get the IP address.
This generates this kind of error: JMESPathError in json_query filter plugin:\nBad jmespath expression: Unknown token '-'
.
There’s an issue here where someone has the same issue and they’re saying that’s how it should work and you should use quotes to make it work, but it won’t.
Here are the combinations I have tried:
'{{ lxclist.json | community.general.json_query("data[?name==`eth0`].\"ip-addresses\"") }}'
Error: template error while templating string: expected token ',', got 'ip'. String: {{ lxclist.json | community.general.json_query(\"data[?name==`eth0`].\\\\\"ip-addresses\\\\\"\"
'{{ lxclist.json | community.general.json_query("data[?name==`eth0`].""ip-addresses""") }}'
Error: JMESPathError in json_query filter plugin:\nBad jmespath expression: Unknown token '-'
"{{ lxclist.json | community.general.json_query('data[?name==`eth0`].ip-addresses') }}"
Error: JMESPathError in json_query filter plugin:\nBad jmespath expression: Unknown token '-'
"{{ lxclist.json | community.general.json_query('data[?name==`eth0`].`ip-addresses`') }}"
Error: JMESPathError in json_query filter plugin:\nExpecting: ['quoted_identifier', 'unquoted_identifier', 'lbracket', 'lbrace'], got: literal: Parse error at column 20, token \"ip-addresses\" (LITERAL)