Transform a json list

14 views
Skip to first unread message

Yoel

unread,
Feb 1, 2016, 10:20:02 AM2/1/16
to Ansible Project
Hi,

my variable contains this Json


"grafana_datasources.json": [
            {
                "access": "proxy", 
                "basicAuth": false, 
                "basicAuthPassword": "", 
                "basicAuthUser": "", 
                "database": "databaseName", 
                "id": 2, 
                "isDefault": false, 
                "jsonData": null, 
                "name": "InfluxDB1", 
                "orgId": 1, 
                "password": "user", 
                "type": "influxdb", 
                "url": "http://localhost:8086", 
                "user": "myUser"
            },
            {
                "access": "proxy", 
                "basicAuth": false, 
                "basicAuthPassword": "", 
                "basicAuthUser": "", 
                "database": "databaseName2", 
                "id": 3, 
                "isDefault": false, 
                "jsonData": null, 
                "name": "InfluxDB2", 
                "orgId": 1, 
                "password": "user", 
                "type": "influxdb", 
                "url": "http://localhost:8086", 
                "user": "myUser2"
            }
        ]


How can i extract a list of "name attribute" ?

Expected =  ["InfluxDB1", "InfluxDB2"]
I'm using ansible 1.9.2


Thanks,

Yoel


Matt Martz

unread,
Feb 1, 2016, 12:37:12 PM2/1/16
to ansible...@googlegroups.com
You should be able to do:

{{ grafana_datasources.json|map(attribute='name') }}

--
You received this message because you are subscribed to the Google Groups "Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ansible-proje...@googlegroups.com.
To post to this group, send email to ansible...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/c0afa79e-5bdf-4bda-b5ce-de564a2e78c5%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.



--
Matt Martz
@sivel
sivel.net
Reply all
Reply to author
Forward
0 new messages