Translate curl --data-urlencode to Ansible uri module

Viewed 8539

How would you translate this curl request to the ansible uri module?

curl -G http://localhost:8086/query?u=admin&p=password \
  --data-urlencode "q=SHOW databases"

I don't know how or were to put the --data-urlencode part

This is what I have so far (not working):

- name: Create influx users with POST
   uri:
     url: "http://localhost:8086/query/?u=admin&p=password"
     method: GET
     body: "q=SHOW databases"

And the error I get is:

"error": "missing required parameter \"q\""

The following however, works:

- name: Create influx users with POST
  uri:
    url: "http://localhost:8086/ping"
    method: GET
    status_code: 204

EDIT: final working solution

This working example will show you the current users of your influxdb

- name: Create influx users with POST
   uri:
     url: "http://localhost:8086/query?q={{'SHOW USERS '|urlencode}}"
     method: GET
     user: admin
     password: password
2 Answers

You can set uri's body_format to form-urlencoded, with method POST.

- name: Show Databases
  uri:
    url: "http://localhost:8086/query"
    user: admin
    password: password
    method: POST
    body: 
      q: SHOW DATABASES
    body_format: form-urlencoded
Related