The json... returning a list of 2+ objects.
When the API returns only one object, the brackets are gone.

{
    "nagios_xi_hosts.json.host": [
        {
            "@attributes": {
                "id": "26128"
            }, 
            "action_url": {}, 
            "active_checks_enabled": "1", 
            "address": "1.1.1.1", 
            "alias": "sldops0725", 
            "check_interval": "5", 
            "config_type": "1", 
            "display_name": "sldops0725", 
            "first_notification_delay": "0", 
            "host_name": "sldops0725", 
            "icon_image": "redhat.png", 
            "icon_image_alt": {}, 
            "instance_id": "1", 
            "is_active": "1", 
            "max_check_attempts": "5", 
            "notes": {}, 
            "notes_url": {}, 
            "notification_interval": "60", 
            "notifications_enabled": "1", 
            "passive_checks_enabled": "1", 
            "retry_interval": "1", 
            "statusmap_image": "redhat.png"
        }, 
        {
            "@attributes": {
                "id": "14039"
            }, 
            "action_url": {}, 
            "active_checks_enabled": "1", 
            "address": "2.2.2.2", 
            "alias": "sldops0196", 
            "check_interval": "5", 
            "config_type": "1", 
            "display_name": "sldops0196", 
            "first_notification_delay": "0", 
            "host_name": "sldops0196", 
            "icon_image": "redhat.png", 
            "icon_image_alt": {}, 
            "instance_id": "1", 
            "is_active": "1", 
            "max_check_attempts": "5", 
            "notes": {}, 
            "notes_url": {}, 
            "notification_interval": "60", 
            "notifications_enabled": "1", 
            "passive_checks_enabled": "1", 
            "retry_interval": "1", 
            "statusmap_image": "redhat.png"
        }
    ]
}

Le jeudi 16 août 2018 14:57:40 UTC-4, J-F Gaudreault a écrit :
>
> Hi! I getting a json from an API request. I've registered the json in a 
> var.
>
> I'm trying to find a way to get the hostname in the json.
> I need to find it even if it has brackets or not.
>
> I only got this far ....
>
>
> with brackets:
>
> - name: test1
>   debug:
>     msg: "{{ nagios_xi_hosts | json_query('json.host[0].host_name') }}"
>
> no brackets:
>
> - name: test2
>   debug:
>     var: nagios_xi_hosts.json.host.host_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-project+unsubscr...@googlegroups.com.
To post to this group, send email to ansible-project@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/b5c3ae27-ce9f-4938-a443-686fdd3ef481%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to