I am trying to use the Ansible uri module to communicate with DeployHQ's API.
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 [email protected]: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/
This is how I am sending it via Ansible:
- uri:
url: https://cepr.deployhq.com/projects/cepr-live/servers
user: [email protected]: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
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).
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
I have also tried passing the --user in the url. No luck at all.
Has anyone else done this?!
SOLVED...
- uri:
url: https://cepr.deployhq.com/projects/cepr-live/servers
user: [email protected]
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.
user
andpassword
options, instead of appending the secret key inuser
? The documentation for ansible uri plugin listsuser
as only the username, so I assume you need both. – user