将 curl PUT 命令转换为 ansible uri
translate a curl PUT command into ansible uri
我想通过 its REST api.
与 seafile 服务器交互
到目前为止,我在将 POST 或 GET 查询转换为 ansible uri 模块时没有遇到任何问题。但是,我在使用 PUT 查询时遇到问题。
以下适用于 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=/
当我将其转换为以下 ansible 任务时,它失败了:
- 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
我收到错误:
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"}
在使用请求库的 python 脚本中,我必须提供最终的 ?p=/
作为 params={'p': '/'}
。这是失败的原因吗?那么如何正确提交参数呢?
您应该将 headers
作为 YAML 哈希传递,而不是作为 JSON 字符串传递:
- 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
参考the docs,尤其是倒数第二个例子:
- uri:
url: https://your.form.based.auth.example.com/dashboard.php
method: GET
return_content: yes
headers:
Cookie: "{{ login.set_cookie }}"
我想通过 its REST api.
与 seafile 服务器交互到目前为止,我在将 POST 或 GET 查询转换为 ansible uri 模块时没有遇到任何问题。但是,我在使用 PUT 查询时遇到问题。
以下适用于 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=/
当我将其转换为以下 ansible 任务时,它失败了:
- 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
我收到错误:
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"}
在使用请求库的 python 脚本中,我必须提供最终的 ?p=/
作为 params={'p': '/'}
。这是失败的原因吗?那么如何正确提交参数呢?
您应该将 headers
作为 YAML 哈希传递,而不是作为 JSON 字符串传递:
- 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
参考the docs,尤其是倒数第二个例子:
- uri:
url: https://your.form.based.auth.example.com/dashboard.php
method: GET
return_content: yes
headers:
Cookie: "{{ login.set_cookie }}"