使用 Ansible uri 模块的 API 调用 [英] API call using Ansible uri module
问题描述
我正在尝试使用 Ansible uri 模块与
I am trying to use the Ansible uri module to communicate with DeployHQ's API.
这是我尝试从 Ansible 使用的示例 DeployHQ 文档:
Here is the example DeployHQ's documentation that I am trying to use from Ansible:
curl -H "Content-type: application/json" \
-H "Accept: application/json" \
--user adam@atechmedia.com:my-api-key \
-d '{"deployment":{ "parent_identifier":"7563d091-ca73-588e-cfe2- e4936f190145", \
"start_revision" : "e84b5937f1132932dd56026db26a76f406555c19", \
"end_revision" : "e84b5937f1132932dd56026db26a76f406555c19", \
"mode" : "queue", \
"copy_config_files" : 1, \
"email_notify" : 1 \
}}' http://test.deployhq.com/projects/project/deployments/
这是我通过 Ansible 发送它的方式:
This is how I am sending it via Ansible:
- uri:
url: https://cepr.deployhq.com/projects/cepr-live/servers
user: me@myemail.org:secret_api_key
body_format: json
method: GET
headers:
Content-Type: application/json
Accept: application/json
deployment:
parent_identifier: id
start_revision: my_start_rev
end_revision: my_end_rev
mode: queue
copy_config_files: 1
email_notify: 1
return_content: yes
问题是我收到了 403 响应(访问被拒绝),所以这与向它们传递 --user 参数有关.我从 cli 发送 cURL 请求完全没有问题,因此传入 --user 的用户凭据是正确的.DeployHQ 可以从他们的日志中看到 json 请求看起来是正确的,但它没有经过身份验证(显然出于安全原因他们无法查看标头).
The issue is that I am getting a 403 response back (access denied), so it is something to do with passing them the --user parameters. I have no issue at all sending the cURL request from the cli, so the user creds passed in --user are correct. DeployHQ can see from their logs that the json request looks correct but it not authenticated (obviously they cannot view the headers for security reasons).
它一定很简单,但我已经花了整个下午并尝试了多种用户组合:(包括和用户:和密码:用于api密钥) - 在正文中:和正文外:(如上).DeployHQ 支持说他们使用基本的 http_auth,所以我尝试了这些参数的组合:
It must be simple but I have spent all afternoon and tried many combinations of user: (including and user: and password: for the api key) - in the body: and out of the body: (as above). DeployHQ support say they use basic http_auth and so I have tried these combinations with the parameter:
force_basic_auth: yes
我也试过在 url 中传递 --user .一点运气都没有.
I have also tried passing the --user in the url. No luck at all.
有没有其他人这样做过?!
Has anyone else done this?!
已解决...
- uri:
url: https://cepr.deployhq.com/projects/cepr-live/servers
user: me@myemail.org
password: secret_api_key
force_basic_auth: yes
....
都在同一级别..非常感谢评论让我回到密码字段.
All on the same level.. Many thanks for comments making me go back to to password field.
推荐答案
根据 ansible uri 文档,还有一个 password
字段.看起来 user
应该只是用户名.您是否尝试过类似的操作:
According to the ansible uri documentation, there is also a password
field. It also looks like user
is supposed to be only the username. Did you try something like:
- uri:
url: https://cepr.deployhq.com/projects/cepr-live/servers
user: me@myemail.org
password: secret_api_key
body_format: json
method: GET
headers:
Content-Type: application/json
Accept: application/json
deployment:
parent_identifier: id
start_revision: my_start_rev
end_revision: my_end_rev
mode: queue
copy_config_files: 1
email_notify: 1
return_content: yes
这篇关于使用 Ansible uri 模块的 API 调用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!