Curl Ansible convert CULL请求与--data urlencode

Curl Ansible convert CULL请求与--data urlencode,curl,ansible,gitlab,uri,urlencode,Curl,Ansible,Gitlab,Uri,Urlencode,我想用Ansible通过RESTAPI将一个HTML文件上传到GitLab 我的卷发请求运行良好: curl -H "Content-Type: application/x-www-form-urlencoded" --request POST --header 'PRIVATE-TOKEN: my_tocken' --data-urlencode content@/tmp/report.html 'https://my_server/api/v4/projects/3/repository

我想用Ansible通过RESTAPI将一个HTML文件上传到GitLab

我的卷发请求运行良好:

 curl -H "Content-Type: application/x-www-form-urlencoded" --request POST  --header 'PRIVATE-TOKEN: my_tocken' --data-urlencode content@/tmp/report.html 'https://my_server/api/v4/projects/3/repository/files/my_customer%2Freportname%2Ehtml?branch=master&commit_message=create%20a%20new%20report' -k
如何使用uri模块翻译它

uri:
  url: "https://my_server/api/v4/projects/3/repository/files/my_customer%2Freportname%2Ehtml?branch=master&commit_message=create%20a%20new%20report"
  validate_certs: no
  method: POST
  headers:
     Content-Type: application/x-www-form-urlencoded
     PRIVATE-TOKEN: "my_tocken"
  status_code: 200
  body: "data-urlencode=content@/tmp/report.html"
我得到:

 "json": {
    "error": "content is missing"
    },
如果/tmp/report.html位于Ansible controller计算机上,则:

uri:
  url: "https://my_server/api/v4/projects/3/repository/files/my_customer%2Freportname%2Ehtml?branch=master&commit_message=create%20a%20new%20report"
  validate_certs: no
  method: POST
  headers:
     Content-Type: application/x-www-form-urlencoded
     PRIVATE-TOKEN: "my_tocken"
  status_code: 200
  body: content={{ lookup('file', '/tmp/report.html') | urlencode }}

如果它位于不同的目标上,您需要先查看数据。

谢谢Techraf,您是对的

正确的要求是:

 - name:  Gitlab | upload file
       uri:
         url: "https://my_server/api/v4/projects/3/repository/files/my_customer%2Freportname%2Ehtml?branch=master&commit_message=create%20a%20new%20report%20for%20server"
        validate_certs: no
         method: POST
         headers:
            Content-Type: application/x-www-form-urlencoded
            PRIVATE-TOKEN: "my_tocken"
      status_code: 201
      body: "content={{ lookup('file', '/tmp/report.html')|urlencode }}"
    delegate_to: localhost

没有必要发布单独的答案,我可以编辑我的答案。更好的是,请修复您的问题,因为您编写的-data urlencode content@/tmp/report.html工作正常。