I'm trying to extract the result from the value "mac_addr" and then register it (in this case 00:50:56:a2:57:c9)
The output I'm working with
"msg": [
{
"changed": false,
"failed": false,
"network_data": {
"0": {
"allow_guest_ctl": true,
"connected": true,
"device_type": "test0",
"label": "test1",
"mac_addr": "00:50:56:a2:57:c9",
"name": "DVSwitch: ",
"start_connected": true,
"unit_number": 7,
"wake_onlan": true
I've tried different commands but I can get past the "0" value. Here the last commands I've tried.
- name: show test result
debug:
msg:
- "{{ test.network_data | json_query('0[*].mac_addr') }}"
register: mac
AND
- name: show test result
debug:
msg:
- "{{ test.network_data.0 | json_query('mac_addr') }}"
register: mac
The output is in the "test" variable
I'm a beginner in Ansible and JSON. Can you please tell what I'm doing wrong ?
I'm working with ansible 2.9.
Thanks