通过ansible在ElasticSearch中的注册角色

d5vmydt9  于 2021-06-10  发布在  ElasticSearch
关注(0)|答案(1)|浏览(394)

我正在尝试创建一个新的安全角色。
这个方法很有效,因为它很简单 cURL 电话:

curl -X POST -u tajikistan:himalaya "192.168.2.13:9200/_security/role/dolboed_suka?pretty" -H 'Content-Type: application/json' -d'
{
  "indices": [
    {
      "names": [ "*" ],
      "privileges": ["create", "index", "read", "read_cross_cluster", "view_index_metadata", "write", "create_index"]
    }
  ]
}
'

但是,如果我试着通过ansible uri 像这样的模块

name: create role 
  uri:
    url: '192.168.2.13:9200/_security/role/dolboed_suka?pretty'
    method: POST
    body:
      {"indices":[{"names":["*"],"privileges":["create","index","read","read_cross_cluster","view_index_metadata","write","create_index"]}]}
    body_format: json
    headers:
      Content-Type: 'application/json'
    url_username: tajikistan
    url_password: himalaya
  register: result

我得到以下错误:

fatal: [elasticsearch-db-02]: FAILED! => {"changed": false, "content": "", "elapsed": 0, "msg": "Status code was -1 and not [200]: Request failed: <urlopen error unknown url type: 192.168.2.14>","redirected": false, "status": -1, "url": "192.168.2.14:9200/_security/role/doldoeb_suka?pretty"}
rqmkfv5c

rqmkfv5c1#

如果查看错误,可以看到以下消息:

"msg": "Status code was -1 and not [200]: Request failed: <urlopen error unknown url type: 192.168.2.14>"

你应该给你的网址添加一个方案,我是说,使用 http://192.168.2.13:9200... 而不仅仅是 192.168.2.13:9200 :

name: create role 
  uri: 
    url: 'http://192.168.2.13:9200/_security/role/dolboed_suka?pretty'
    method: POST
    body: {"indices":[{"names":["*"],"privileges":["create","index","read","read_cross_cluster","view_index_metadata","write","create_index"]}]}
    body_format: json
    headers:
      - Content-Type: 'application/json'
   url_username: tajikistan
   url_password: himalaya
 register: result

相关问题