Skip to content
koducathome

cURL to Ansible Converter

Convert curl commands to Ansible code using uri module. Paste a command and the Ansible snippet appears instantly — everything runs in your browser.

How to use this tool

Steps for using the cURL to Code.

  1. Copy a curl command — from API documentation, or from your browser's DevTools (Network tab → right-click a request → Copy as cURL (bash)).
  2. Paste it into Enter cURL command. The Ansible uri module code appears instantly.
  3. Set up: Ansible includes the uri module — no extra collection is needed.
  4. Run it: Put the tasks in a play and run it with ansible-playbook playbook.yml. Replace placeholders such as YOUR_TOKEN first, and check any notes under the editors for curl options that have no uri module equivalent.

Example

GET with headers → Ansible uri module

curl command
curl 'https://api.example.com/v1/users?page=2' \
  -H 'Accept: application/json' \
  -H 'Authorization: Bearer YOUR_TOKEN'
Ansible uri module
- name: "GET https://api.example.com/v1/users?page=2"
  ansible.builtin.uri:
    url: "https://api.example.com/v1/users?page=2"
    method: "GET"
    headers:
      "Accept": "application/json"
      "Authorization": "Bearer YOUR_TOKEN"
    return_content: true
  register: response

- name: Show the response
  ansible.builtin.debug:
    msg:
      - "{{ response.status }}"
      - "{{ response.content }}"

Common use cases

  • Calling APIs during deployments
  • Health checks and smoke tests in playbooks
  • Registering servers with an external service

Converting curl to Ansible uri module

The ansible.builtin.uri module sends HTTP requests from a playbook. JSON bodies use body_format: json, and the response is registered so later tasks can use it.

The converter reads the curl command the way curl does — the method (-X), headers (-H), request bodies (-d, --data-raw, --json, -F), query strings, basic auth (-u) and cookies — and writes the equivalent uri module code. Options that have no uri module equivalent are listed under the editors rather than silently dropped.

Limitations

  • The code is a starting point: add timeouts, retries and error handling for production use.
  • Secrets in the curl command are copied into the code — move them to environment variables before committing.

Frequently asked questions

How do I check the status code in Ansible?

The response is registered as response; use response.status. Add status_code: [200, 201] to the task to fail on anything else.

Why does the task fail on a 404?

The uri module expects 200 by default. Set status_code to the codes you accept.

Is my curl command sent to a server?

No. The conversion runs entirely in your browser, so tokens and passwords in the command never leave your device. Still, replace real secrets before sharing the generated code.