Curl 使用Ansible uri模块的API调用
我正在尝试使用模块与您进行通信 以下是我试图从Ansible使用的DeployHQ文档示例:Curl 使用Ansible uri模块的API调用,curl,ansible,credentials,Curl,Ansible,Credentials,我正在尝试使用模块与您进行通信 以下是我试图从Ansible使用的DeployHQ文档示例: 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", \ "st
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发送的方式:
- 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请求看起来是正确的,但没有经过身份验证(显然,出于安全原因,他们无法查看头)
它一定很简单,但我花了整个下午的时间,尝试了多种用户组合:(包括和用户:和密码:对于api键)-在主体内:和在主体外:(如上所述)。DeployHQ支持人员表示他们使用基本http_auth,因此我尝试了以下参数组合:
force_basic_auth: yes
我还尝试在url中传递--user。一点运气都没有
还有其他人做过吗
解决了
- uri:
url: https://cepr.deployhq.com/projects/cepr-live/servers
user: me@myemail.org
password: secret_api_key
force_basic_auth: yes
....
都在同一水平上。。非常感谢您的评论,让我回到密码字段。根据,还有一个密码字段。看起来user
应该只是用户名。你有没有试过这样的方法:
- 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
设置:
- name: call an api
vars:
cust_id: "123"
uri:
url: "url"
url_username: "username"
url_password: "password"
force_basic_auth: yes
method: PUT
headers:
xyz: true
body_format: json
body: "{{ cust_id }}"
您是否尝试使用user
和password
选项,而不是在user
中添加密钥?文档中列出的user
仅作为用户名,因此我假设您需要这两个元素。完成了-最后它非常简单,它一定是我没有尝试过的组合之一,您确实需要user:和password:元素,但是你也需要“强制基本认证:是的”…是的-我尝试了几乎所有的user:和user with password组合。它必须是关于基本http身份验证和在user@myemail.com和api密钥