Extracting list of values from a list of list of dictionaries

10 views
Skip to first unread message

Ahmed Kamel

unread,
Mar 22, 2017, 9:29:33 AM3/22/17
to Ansible Project
Hello,

I have a command running a loop through with items and I get a registered result like the following structure:
{
    "changed": false,
    "msg": "All items completed",
    "results": [
        {
            "machines": [
                {
                    "ip": "127.0.0.1",
                    "name": "machine1"
                },
                {
                    "ip": "127.0.0.1",
                    "name": "machine2"
                }
            ]
        },
        {
            "machines": [
                {
                    "ip": "127.0.0.1",
                    "name": "machine3"
                },
                {
                    "ip": "127.0.0.1",
                    "name": "machine4"
                }
            ]
        }
    ]
}


I wanted to extract a list of machines.name out of it so I used the following filter:

map(attribute="machines.name")

And I got a list of Undefined as an output:
"[Undefined, Undefined]": "[Undefined, Undefined]"


How can I correctly extract a list of machine names out of that data structure?
Reply all
Reply to author
Forward
0 new messages