向Ansible Playbook发出卷曲请求

时间:2020-03-01 23:25:26

标签: json curl ansible

示例卷曲请求。

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

现在,我想使用可卷曲的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"

我遇到错误。

3 个答案:

答案 0 :(得分:3)

您应该使用body参数而不是src。另外,标头应为Content-Type,而不是Content-type

答案 1 :(得分:0)

要添加文件中的数据时,只需添加src。 解决方案将类似于

tasks:
    - name: Send test
      uri:
        url: dns.com/end
        method: POST
        body: "test connection"
        headers:
          Content-Type: "application/json"
          Authorization: "Basic asdfasdf"

答案 2 :(得分:0)

您已将正文格式称为json,并且没有将任何正文传递给它。 您的body.json文件应包含以下内容:

{
"name": "test connection"
}

,您还可以为POST方法提及status_code = 201。

相关问题