0

Sample curl request.

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

Now, I'd like to send exactly the same message using 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"

I'm getting an error.

d4nyll
  • 11,811
  • 6
  • 54
  • 68
user2856064
  • 541
  • 1
  • 8
  • 25

3 Answers3

3

You should be using the body parameter instead of src. Also, the header should be Content-Type instead of Content-type.

d4nyll
  • 11,811
  • 6
  • 54
  • 68
0

Just to add src is used when you want to submit the data from a file. Solution will look something like

tasks:
    - name: Send test
      uri:
        url: dns.com/end
        method: POST
        body: "test connection"
        headers:
          Content-Type: "application/json"
          Authorization: "Basic asdfasdf"
Mr Kashyap
  • 562
  • 1
  • 5
  • 16
0

You have mentioned body format as json and you are not passing any body to it. You body.json file should contain something like this:

{
"name": "test connection"
}

and also you can mention status_code=201 for POST method.

Sakar Mehra
  • 89
  • 1
  • 11