Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Ansible parse JSON with YAML

Tags:

yaml

ansible

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": "10.0.3.224",
            "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.

like image 355
Deano Avatar asked Oct 21 '16 14:10

Deano


1 Answers

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

like image 182
Konstantin Suvorov Avatar answered Oct 26 '22 20:10

Konstantin Suvorov