Blog
Wild & Free Tools

Convert JSON to Ansible YAML — Inventories, Playbooks, and Vars

Last updated: April 2026 7 min read
Quick Answer

Table of Contents

  1. Dynamic inventory JSON to static YAML
  2. Playbooks — when you have JSON from a generator
  3. Vars files and group_vars / host_vars
  4. Ansible-specific YAML quirks to know
  5. When json_query filter is better than conversion
  6. Frequently Asked Questions

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:

  1. Run the inventory script: ./inventory.py --list > inventory.json.
  2. Paste the contents into the converter.
  3. Click Convert. Copy the output.
  4. Save as inventory.yaml. Use with ansible -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 Shipping

Vars 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

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:

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 Converter

Frequently 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.

Tyler Mason
Tyler Mason File Format & Converter Specialist

Tyler spent six years in IT support where file format conversion was a daily challenge.

More articles by Tyler →
Launch Your Own Clothing Brand — No Inventory, No Risk