Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Translate curl --data-urlencode to Ansible uri module

Tags:

curl

ansible

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
like image 314
viktorsmari Avatar asked Dec 18 '22 04:12

viktorsmari


1 Answers

There is a urlencode filter in Jinja...but there is another problem. A GET request doesn't have a body; when you run:

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

What actually happens is:

GET /query?u=admin&p=password&q=SHOW%20databases

So you would need to rewrite your task like this:

- name: Create influx users with POST
   uri:
     url: "http://localhost:8086/query/?u=admin&p=password?{{ 'q=SHOW databases'|urlencode }}"
     method: GET
like image 185
larsks Avatar answered Jan 04 '23 21:01

larsks