You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

将curl命令转换为Ansible uri模块时遇OPERATION_NOT_SUPPORTED错误求助

问题排查:Ansible uri模块替代curl命令报错OPERATION_NOT_SUPPORTED

原始curl命令

curl -u "username:password" "https://company.abc.apps.company.eu/qps/rest/1.0/download/ca/downloadbinary/" --header "Content-Type: application/xml" --data-raw "<ServiceRequest><data><DownloadBinary><platform>LINUX_UBUNTU</platform><architecture>ARM_64</architecture></DownloadBinary></data></ServiceRequest>" -o file.deb

当前Ansible任务

- name: Download Binaries?
  ansible.builtin.uri:
    url: https://company.abc.apps.company.eu/qps/rest/1.0/download/ca/downloadbinary/
    url_username: username
    url_password: password
    force_basic_auth: true
    headers:
      Content-Type: application/xml
    body_format: raw 
    body: "<ServiceRequest><data><DownloadBinary><platform>LINUX_UBUNTU</platform><architecture>ARM_64</architecture></DownloadBinary></data></ServiceRequest>"
    dest: file.deb

错误响应

<?xml version="1.0" encoding="UTF-8"?>
<ServiceResponse xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="https://companty.abc.apps.company.eu/qps/xsd/1.0/ca/downloadbinary.xsd">
  <responseCode>OPERATION_NOT_SUPPORTED</responseCode>
  <responseErrorDetails>
    <errorMessage>Operation not supported for this object using this method.</errorMessage>
    <errorResolution>Refer to the QPS guide for authorized operation for this domain object.</errorResolution>
  </responseErrorDetails>
</ServiceResponse>

问题原因

核心差异在于HTTP请求方法:

  • curl使用--data-raw参数时,默认发送POST请求
  • Ansible uri模块默认使用GET请求,即使指定body也不会自动切换为POST,导致服务端收到不支持的请求方法,返回OPERATION_NOT_SUPPORTED错误

解决方案

在uri模块中显式添加method: POST参数,对齐curl的请求方法:

- name: Download Binaries
  ansible.builtin.uri:
    url: https://company.abc.apps.company.eu/qps/rest/1.0/download/ca/downloadbinary/
    url_username: username
    url_password: password
    force_basic_auth: true
    method: POST  # 显式指定POST方法
    headers:
      Content-Type: application/xml
    body_format: raw 
    body: "<ServiceRequest><data><DownloadBinary><platform>LINUX_UBUNTU</platform><architecture>ARM_64</architecture></DownloadBinary></data></ServiceRequest>"
    dest: file.deb

额外检查项

  • 确认URL路径(含末尾斜杠)与curl完全一致,部分服务端对路径匹配敏感
  • 验证body中的XML内容无转义错误或格式差异
  • 若问题仍存在,可添加return_content: true和status_code: 200(或服务端预期的成功状态码),获取更详细的响应信息辅助排查

内容的提问来源于stack exchange,提问作者Pugs08

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.02 15:20:22