I have a situation.
When I try to use json_query filter in ansible-playbook return this error:
{"msg": "Error in jmespath.search in json_query filter plugin:\ninvalid literal for int() with base 10: '-'"}
I solve this with replace ('-','_') filter.
Have I other way to solve this?
complete code here:
---
# tasks file for mpls-lsp
- name: Colete informações do protocolo osfp
junipernetworks.junos.junos_rpc:
rpc: get-ospf-neighbor-information
output: json
register:
_data
- name: Aplica as configurações padrão em RT-BRAS.*
ansible.builtin.debug:
var: item
loop: "{{ _data2 | json_query('ospf_neighbor_information[0].ospf_neighbor[*].neighbor_address[0].data') }}"
vars:
_data2: "{{ _data.output | replace ('-','_') }}"
when: "'device_roles_bras' in {{ group_names }}"
TL;DR
"ospf-neighbor-information"[0]."ospf-neighbor"[*]."neighbor-address"[0].dataFull Story
This is actually quite dangerous as this replaces dashes for underscores absolutely everywhere in the input, identifiers and values. But if we now look at your resulting jmespath expression
we can infer that all your identifiers where previously using
-as a separatorIn the above expression, you are using unquoted identifiers. If you look at jmespath specification for identifiers, you will see that unquoted ones cannot contain dashes.
So if your identifiers contain dashes, you must quote them (and note that quoting identifiers is made with double-quotes)
You can transform your
json_querytask as below to make it work on your original data (you might have to adapt as I didn't have your original structure and had to guess a bit...)