带有表单的 ansible uri 模块

ansible uri module with form

是否可以在 ansible 中使用 uri 模块 运行 这个命令?

- shell: unset http_proxy && curl -X POST -H "Cache-Control:no-cache" -F "access_key={{ api_user }}" -F "secret_key={{ api_pass }}" "http://mydomain.bla/api/v1/login_check"

我这样试过:

- uri:
    url: http://mydomain.bla/api/v1/login_check
    method: POST
    user: "{{ api_user }}"
    password: "{{ api_pass }}"
  environment:
    http_proxy: ''

像这样:

- uri:
    url: http://mydomain.bla/api/v1/login_check
    method: POST
    body: "access_key={{ api_user }}&secret_key={{ api_pass }}"
  environment:
    http_proxy: ''

而且还是不行。 我正在尝试获取令牌并将其存储在一个可靠的变量中。

"use_proxy: false" 或否都行不通 - 这就是我使用这种丑陋环境解决方法的原因

您忘记使用 return_content: yes

来自模块的 docs:

return_content (default: no) – Whether or not to return the body of the request as a "content" key in the dictionary result.

- uri:
    url: http://mydomain.bla/api/v1/login_check
    method: POST
    body: "access_key={{ api_user }}&secret_key={{ api_pass }}"
    return_content: yes
  register: token_response
  environment:
    http_proxy: ''

- debug: var=token_response.content