user2856064
user2856064

Reputation: 553

Curl request to ansible playbook

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.

Upvotes: 0

Views: 1221

Answers (3)

Sakar Mehra
Sakar Mehra

Reputation: 89

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.

Upvotes: 0

Mr Kashyap
Mr Kashyap

Reputation: 584

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"

Upvotes: 0

d4nyll
d4nyll

Reputation: 12637

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

Upvotes: 3

Related Questions