使用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.
推荐答案
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屋!