I want to interact with a seafile server with its REST api.
So far I had no problems translating POST or GET queries into the ansible uri module. However, I have a problem with getting a PUT query to work.
The following works with curl:
curl -X PUT -d "share_type=group&group_id=<groupid>&permission=rw" -H 'Authorization: Token <mysecrettoken>' -H 'Accept: application/json; charset=utf-8; indent=4' https://<myserverurl>/api2/repos/<mylibraryid>/dir/shared_items/?p=/
When I translate this to the following ansible task, it fails:
- name: mytask
uri:
url: "https://<myserverurl>/api2/repos/<mylibraryid>/dir/shared_items/?p=/"
method: PUT
headers: '{ "Authorization": "Token <mysecrettoken>" }'
body: '{ "share_type": "group", "group_id": "<groupid>", "permission": "rw"}'
body_format: json
return_content: yes
I get the error:
HTTP Error 500: INTERNAL SERVER ERROR", "redirected": false, "server": "nginx", "set_cookie": "SERVERID=<serverid>; path=/", "status": 500, "transfer_encoding": "chunked", "url": "https://<myserverurl>/api2/repos/<mylibraryid>/dir/shared_items/?p=/", "vary": "Accept-Language, Cookie"}
In a python script using the requests library, I had to supply the final ?p=/
as params={'p': '/'}
. Is this the reason for the failure? How do I correctly submit the parameter then?
You should pass the headers
as a YAML hash, not as a JSON string:
- name: mytask
uri:
url: "https://<myserverurl>/api2/repos/<mylibraryid>/dir/shared_items/?p=/"
method: PUT
headers:
Authorization: "Token <mysecrettoken>"
body: '{ "share_type": "group", "group_id": "<groupid>", "permission": "rw"}'
body_format: json
return_content: yes
For reference, see the docs, especially the second-to-last example:
- uri:
url: https://your.form.based.auth.example.com/dashboard.php
method: GET
return_content: yes
headers:
Cookie: "{{ login.set_cookie }}"