0

When I run any GET queries, it runs fine. for instance

- name: run curl query on ES host
  uri:
    url: "http://localhost:9200"
    method: GET
    return_content: yes
    url_username: some_elastic_user
    url_password: elastic_pass
  register: response

- debug:
    var: response.content

RESPONSE:

# ansible-playbook -i inv.txt getquery.yml

PLAY [es] ********************************************************************************************************************************************

TASK [esquery : run curl query on ES host] *****************************************************************************************************
ok: [es1]

TASK [esquery : debug] *************************************************************************************************************************
ok: [es1] => {
    "response.content": {
        "cluster_name": "elastic",
        "cluster_uuid": "evEg5b8aQiW-ewNdbYG5-A",
        "name": "es1",
        "tagline": "You Know, for Search",
        "version": {
            "build_date": "2020-06-14T19:35:50.234439Z",
            "build_flavor": "default",
            "build_hash": "757314695644ea9a1dc2fecd26d1a43856725e65",
            "build_snapshot": false,
            "build_type": "tar",
            "lucene_version": "8.5.1",
            "minimum_index_compatibility_version": "6.0.0-beta1",
            "minimum_wire_compatibility_version": "6.8.0",
            "number": "7.8.0"
        }
    }
}

However, when I run PUT query like below, it gives ERROR: "response.content": "VARIABLE IS NOT DEFINED!"

here's playbook

- name: set elasticsearch index settings
  uri:
    url: "http://localhost:9200/*/_settings"
    method: PUT
    headers:
      Content-Type: "application/json"
    body_format: json
    body:
      index:
        auto_expand_replicas: "0-all"
    url_username: some_elastic_user
    url_password: elastic_pass
  register: response

- debug:
    var: response.content

Here's error

# ansible-playbook -i inv.txt putquery.yml

PLAY [es] ********************************************************************************************************************************************

TASK [esquery : set elasticsearch index settings] **********************************************************************************************
ok: [es1]

TASK [esquery : debug] *************************************************************************************************************************
ok: [es1] => {
    "response.content": "VARIABLE IS NOT DEFINED!"
}

not sure what variable it is refering to, and not sure whether query ran or not from output.

2
  • it looks like queries run successful but output is not registered properly due to with_items loop. Commented Aug 4, 2023 at 7:49
  • Debug the response variable and see what it contains Commented Aug 4, 2023 at 8:07

0

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.