Deano Deano - 1 year ago 318
YAML Question

Ansible parse JSON with YAML

I'm trying to assign a variable to match IP address shown in API call I'm making to an online service provider.

Here is the JSON data I'm receiving:

TASK [manager : debug] *********************************************************
ok: [localhost] => {
"msg": [
"address": "",
"family": "inet",
"netmask": "24",
"scope": "global"
"address": "fe80::216:3eff:feb2:7330",
"family": "inet6",
"netmask": "64",
"scope": "link"

How can I go about parsing the first address output and assign its value to a variable in YAML

this is what I have tried

- debug: msg={{ output.stdout|from_json }}

but I'm unable to get the IP address.

Answer Source

Try: msg={{ (output.stdout | from_json | first).address }}

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download