Convert JSON to Ansible YAML — Inventories, Playbooks, and Vars
- Paste your JSON inventory, playbook, or vars file and get Ansible-ready YAML in one click.
- Ansible accepts both, but YAML is the standard for anything checked into Git or shared with a team.
- Handles dynamic inventory exports from AWS, Azure, GCP, and any custom inventory script.
Table of Contents
Ansible accepts JSON and YAML for inventories, playbooks, and vars — but almost every playbook, role, and inventory you'll find on the internet is YAML. If you have JSON from a dynamic inventory script, a cloud API, or a Terraform export, converting to YAML makes it Git-friendly and reviewable. This guide covers the three common Ansible JSON sources and the conversion workflow.
Dynamic Inventory JSON to Static YAML
Ansible's dynamic inventory scripts (aws_ec2, azure_rm, gcp_compute) emit JSON on stdout. For a snapshot you can version in Git — say, to preserve the inventory state at the time of a deploy — convert the JSON to YAML:
- Run the inventory script:
./inventory.py --list > inventory.json. - Paste the contents into the converter.
- Click Convert. Copy the output.
- Save as
inventory.yaml. Use withansible -i inventory.yaml ....
Now your inventory is a static, readable snapshot. Future runs can use the dynamic script for freshness; the static YAML is for audit and rollback.
Playbooks — When You Have JSON from a Generator
Some tools emit Ansible playbooks as JSON (CI generators, internal platforms, automated conversion from other tools). Convert to YAML:
// Input JSON
[{"hosts":"webservers","tasks":[{"name":"install nginx","apt":{"name":"nginx","state":"present"}}]}]
Output YAML:
- hosts: webservers
tasks:
- name: install nginx
apt:
name: nginx
state: present
Identical playbook, different format. Ansible runs both. Git prefers the YAML.
Sell Custom Apparel — We Handle Printing & Free ShippingVars Files and group_vars / host_vars
Vars files are the most common conversion. A JSON dump of variables becomes a clean group_vars/all.yaml:
// Input
{"db_host":"db.internal","db_port":5432,"features":{"beta":true,"legacy":false}}
Output:
db_host: db.internal db_port: 5432 features: beta: true legacy: false
Drop under group_vars/all.yaml or a specific group, and Ansible picks it up automatically.
Ansible-Specific YAML Quirks to Know
- Boolean styles. Ansible accepts
yes/no,true/false,True/False. Our converter outputstrue/false— safest for YAML 1.2 parsers. - Jinja2 templates. If your JSON has strings with
{{ var }}, they pass through unchanged. Ansible evaluates them at runtime. - Lists of dicts. Ansible task lists are arrays of objects in JSON. YAML output uses
- key: valuenotation, which is idiomatic Ansible. - Preserving order. YAML output respects JSON key order. Helpful for playbooks where task order matters visually.
When json_query Filter Is Better Than Conversion
Ansible's json_query filter lets you consume JSON inside a playbook without converting the whole file. If your workflow is "fetch a JSON API, then act on specific fields," keep the JSON as-is and use json_query.
Convert to YAML when:
- You want the output in Git.
- You want humans to read or review the data.
- You're using it as an inventory, playbook, or vars file.
Keep it as JSON when it's ephemeral data consumed in a single task.
Convert Your Ansible JSON to Clean YAML
Paste inventory, playbook, or vars JSON. Click Convert. Git-ready YAML in seconds.
Open Free JSON to YAML ConverterFrequently Asked Questions
Can Ansible run playbooks in JSON format?
Yes — Ansible parses both JSON and YAML for playbooks, inventories, and vars. The convention is YAML because it's easier to read and review. Converting legacy JSON to YAML is common for that reason.
Does conversion preserve Jinja2 template strings?
Yes. Jinja2 strings like {{ ansible_hostname }} pass through as plain strings. YAML doesn't interpret them — Ansible does at runtime. Output works identically to the JSON input.
How do I convert a multi-document Ansible vars file?
Each document (separated by --- in YAML) must be converted individually. Our tool takes one JSON object per conversion. For a multi-doc vars file, convert each object, then concatenate with --- between them.
What about Ansible Vault encrypted vars?
Encrypted values in Vault are stored as strings. The converter preserves them as-is, and Ansible decrypts them at runtime. Conversion doesn't affect Vault integration.

