Ansible uri 模块授权不能按预期工作

Ansible uri module authorization don't work as expected

我正在尝试通过 ansible uri 模块创建 kibana space 这是我的任务

- name: Create altynorda kibana space
  uri:
    url: '{{ kibana_altynorda_url }}/api/spaces/space'
    method: POST
    body:
      {"id":"altynorda","name":"altynorda","description":"plati za parkovku","color":"#aabbcc","initials":"MK","disabledFeatures":["timelion","canvas"]}
    body_format: json
    headers:
      kbn-xsrf: 'true'
      Content-Type: 'application/json'
    url_username: elastic
    url_password: poshelnaxyi
  when:
    - first_host|default(false)|bool
    - '"altynorda" not in altynorda_spaces_result'
  delegate_to: localhost

所以当我通过 ansible uri 模块启动这个任务时,Kibana 报错

FAILED! => {"cache_control": "private, no-cache, no-store, must-revalidate", "changed": false, "connection": "close", "content": "{\"statusCode\":401,\"error\":\"Unauthorized\",\"message\":\"Unauthorized\"}", "content_length": "66", "content_type": "application/json; charset=utf-8", "date": "Wed, 07 Apr 2021 09:12:24 GMT", "elapsed": 0, "json": {"error": "Unauthorized", "message": "Unauthorized", "statusCode": 401}

但是当我通过纯 cURL 执行此操作时,它接受了

curl -u elastic:poshelnaxyi -X POST "https://kibana.kz/api/spaces/space" -H 'kbn-xsrf: true' -H 'Content-Type: application/json' -d'

{

  "id": "altynorda",

  "name": "altynorda",

  "description" : "plati za parkovku",

  "color": "#aabbcc",

  "initials": "MK",

  "disabledFeatures": ["timelion", "canvas"]

}

'

{"id":"altynorda","name":"altynorda","description":"plati za parkovku","color":"#aabbcc","initials":"MK","disabledFeatures":["timelion","canvas"]}

你可以尝试添加选项

force_basic_auth: yes

由于文档中的原因,我通常必须添加此选项 https://docs.ansible.com/ansible/latest/collections/ansible/builtin/uri_module.html#parameter-force_basic_auth