Translate curl --data-urlencode to Ansible uri module Translate curl --data-urlencode to Ansible uri module curl curl

Translate curl --data-urlencode to Ansible uri module


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


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