I have a file attachment I'm trying to upload to Confluence via the REST API. I can do it by replicating their example with curl
, but it's failing when using Ansible and I can't figure out why.
Here's the curl
command:
curl -u <username>:<password> -X POST -H "X-Atlassian-Token: nocheck" -F "file=@<filepath>" -F "comment=File attached via REST API" https://myconfluenceserver.com/rest/api/content/<page ID>/child/attachment
Of course the values in <>
are replaced with real values. This command is successful.
Here's the Ansible
task:
ansible.builtin.uri:
user: "{{ osa_credentials.username }}"
password: "{{ osa_credentials.password }}"
url: "{{ url }}"
method: POST
headers:
X-Atlassian-Token: nocheck
force_basic_auth: yes
src: "{{ filepath }}"
validate_certs: no
When I run the curl
command it works, but with Ansible it throws error 400
. Here is the full error text:
fatal: [localhost]: FAILED! => {
"changed": false,
"connection": "close",
"content_language": "en",
"content_length": "435",
"content_type": "text/html;charset=utf-8",
"date": "Thu, 29 Jun 2023 06:34:10 GMT",
"elapsed": 1,
"invocation": {
"module_args": {
"attributes": null,
"body": null,
"body_format": "raw",
"ca_path": null,
"ciphers": null,
"client_cert": null,
"client_key": null,
"creates": null,
"decompress": true,
"dest": null,
"follow_redirects": "safe",
"force": false,
"force_basic_auth": true,
"group": null,
"headers": {
"Content-Length": 543818,
"X-Atlassian-Token": "nocheck"
},
"http_agent": "ansible-httpget",
"method": "POST",
"mode": null,
"owner": null,
"password": "VALUE_SPECIFIED_IN_NO_LOG_PARAMETER",
"remote_src": false,
"removes": null,
"return_content": false,
"selevel": null,
"serole": null,
"setype": null,
"seuser": null,
"src": "<filepath>",
"status_code": [
200
],
"timeout": 30,
"unix_socket": null,
"unredirected_headers": [],
"unsafe_writes": true,
"url": "https://myconfluenceserver.com/rest/api/content/<page ID>/child/attachment",
"url_password": "VALUE_SPECIFIED_IN_NO_LOG_PARAMETER",
"url_username": "<username>",
"use_gssapi": false,
"use_netrc": true,
"use_proxy": true,
"user": "<username>",
"validate_certs": false
}
},
"msg": "Status code was 400 and not [200]: HTTP Error 400: ",
"redirected": false,
"server": "Apache",
"status": 400,
"url": "https://myconfluenceserver.com/rest/api/content/<page ID>/child/attachment"
}
What am I missing?