首页 > 解决方案 > 使用 uri 模块 ansible 执行 curl -X

问题描述

我想执行这个 curl 命令:

shell: 'curl -X POST -F app.yaml=@/full/path/to/app.yaml -H "Content-Type: multipart/form-data" http://endpoint:8080/v2/apps' 

基于:Execute curl -X with ansible playbook,我做到了

- name: 
  uri:
    url: "https://endpoint:8080/v2/apps"
    method: "POST"
    body: "{{ 'app.yaml=@' + lookup('file','/full/path/to/app.yaml') }}"
    headers:
        content-Type: "multipart/form-data"
    status_code: 200
    validate_certs: no
    return_content: yes

但是我通过使用查找模块或完整路径得到:“缺少 app.yaml”。我在我的控制器机器上进行了测试。

Using module file /usr/lib/python2.7/site-packages/ansible/modules/net_tools/basics/uri.py
<127.0.0.1> ESTABLISH LOCAL CONNECTION FOR USER: paas
<127.0.0.1> EXEC /bin/sh -c '/usr/bin/python2 && sleep 0'
The full traceback is:
  File "/tmp/ansible_HDPF5B/ansible_module_uri.py", line 535, in main
    js = json.loads(u_content)
  File "/usr/lib64/python2.7/json/__init__.py", line 338, in loads
    return _default_decoder.decode(s)
  File "/usr/lib64/python2.7/json/decoder.py", line 366, in decode
    obj, end = self.raw_decode(s, idx=_w(s, 0).end())
  File "/usr/lib64/python2.7/json/decoder.py", line 384, in raw_decode
    raise ValueError("No JSON object could be decoded")

fatal: [localhost]: FAILED! => {
    "cache_control": "no-cache, no-store, no-transform, must-revalidate, proxy-revalidate, max-age=0, s-maxage=0", 
    "changed": false, 
    "connection": "close", 
    "content": "missing app.yaml", 
    "content_type": "text/plain",  
    "invocation": {
        "module_args": {
            "body": "app.yaml=@/tmp/app.yaml", 
            "body_format": "raw", 
            "headers": {
                "Authorization": "Token XXX", 
                "content-Type": "multipart/form-data"
            }, 
            "http_agent": "ansible-httpget", 
            "method": "POST",  
            "return_content": true,  
            "status_code": [
                "200"
            ], 
            "url": "https://endpoint:8080/v2/apps",  
            "use_proxy": true, 
            "validate_certs": false
        }
    }, 
    "pragma": "no-cache", 
    "redirected": false, 
    "server": "nginx", 
    "status": 404, 
    "url": "https://endpoint:8080/v2/apps", 
    "x_api_version": "1.1.4"
}

MSG:

Status code was 404 and not [200]: HTTP Error 404: Not Found

有人能帮我吗 ?
提前致谢。

标签: curlansibleuri

解决方案


推荐阅读