Parse a dynamic json response

24 views
Skip to first unread message

Stephane Cremel

unread,
Jul 16, 2021, 10:00:31 AM7/16/21
to ansible...@googlegroups.com
I work on role for administrate an elastic cluster.

When i execute this :

- name: Get Statistic of index
  uri:
    url: "{{ update_index }}"
    method: GET
    body: ""
    body_format: json
  register: result_stats
  when: index_ is defined and index

- debug:
    msg: "{{ index_ }}"

- debug:
    msg: "{{ result_stats.json }}"

I have this response :

TASK [elastic_search_create_index : Get Statistic of index] *******************************************************************
ok: [vmelastic02.preprod]

TASK [elastic_search_create_index : debug] ************************************************************************************
ok: [vmelastic02.preprod] => {
    "msg": "webshop-de-preprod"
}

TASK [elastic_search_create_index : debug] ************************************************************************************
ok: [vmelastic02.preprod] => {
    "msg": {
        "webshop-de-preprod": {
            "settings": {
                "index": {
                    "creation_date": "1626441304247",
                    "number_of_replicas": "2",
                    "number_of_shards": "1",
                    "provided_name": "webshop-de-preprod",
                    "routing": {
                        "allocation": {
                            "include": {
                                "_tier_preference": "data_content"
                            }
                        }
                    },
                    "uuid": "hVD9st6VSyiFmTI6pMqjIQ",
                    "version": {
                        "created": "7130399"
                    }
                }
            }
        }
    }
}


I would like get the value of number_of_replicas

but when i test :
- debug:
    msg: "{{ result_stats.json.{{ index_ }} }}"

I have an error, how can I do that ?

thanks
--
Stéphane CREMEL
Reply all
Reply to author
Forward
0 new messages