首页 > 解决方案 > 对 ansible playbook 的 curl 请求

问题描述

示例 curl 请求。

curl -X POST \
  --data '"test connection"' \
  -H 'Content-type: application/json' \
  -H 'Authorization: Basic asdfasdf' \
  dns.com/end

现在,我想使用 curl ansible playbook 发送完全相同的消息。

---
- name: "Send test"
  hosts: localhost
  tasks:
    - name: Send test
      uri:
        url: dns.com/end
        method: POST
        src: '"test connection"'
        body_format: json
        headers:
          Content-type: "application/json"
          Authorization: "Basic asdfasdf"

我收到一个错误。

标签: jsoncurlansible

解决方案


您应该使用body参数而不是src. 此外,标题应该是Content-Type而不是Content-type.


推荐阅读