从 ansible 主机在 Elasticsearch 主机上运行 put 查询

从 ansible 主机在 Elasticsearch 主机上运行 put 查询

当我运行任何 GET 查询时,它运行良好。例如

- 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

回复:

# 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"
        }
    }
}

但是,当我运行如下所示的 PUT 查询时,它会给出错误:“response.content”:“VARIABLE IS NOT DEFINED!”

这是剧本

- 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

这是错误

# 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!"
}

不确定它引用的变量是什么,也不确定查询是否从输出中运行。

相关内容