python - Ansible: printing out JSON first level keys names -
example :
{ "fw1": { "ipv4": { "rtr": { "ip": "1.2.3.4", "net": "1.2.3.4", } } }, "fw2": { "ipv4": { "rtr": { "ip": "4.3.2.1", "net": "4.3.2.1", } } } }
i need list first level keys of json file.
using 'from_json).keys()' strange syntax --> [u'fw1', u'fw2'].
where 'u' characters come , how rid of them ? there way list keys instead of getting them in array ?
you don't need use from_json
here:
--- - hosts: localhost gather_facts: true vars: my_json: "{{ lookup('file','test.json') }}" tasks: - debug: msg: "keys list: {{ my_json.keys() }}"
Comments
Post a Comment