SSH Config to Ansible Inventory Converter

Convert OpenSSH client configurations (~/.ssh/config) into ready-to-use Ansible INI (hosts.ini) or Ansible YAML inventory files.

How to Convert SSH Config to Ansible Inventory

1

Select Output Format

Choose between Ansible INI (hosts.ini) or Ansible YAML inventory formatting.

2

Paste SSH Config

Paste your ~/.ssh/config declarations including Host, HostName, User, Port, and IdentityFile.

3

Run Ansible Playbooks

Save output as inventory.ini or hosts.yaml and run ansible -i inventory.ini all -m ping.

Tool Options

Host & User Mapping

Maps HostNameansible_host and Useransible_user parameters.

Key & Port Parameters

Maps IdentityFileansible_ssh_private_key_file and non-standard Portansible_port.

Custom Host Groups

Assign all imported hosts directly into custom Ansible groups (e.g. [webservers] or [database]).

Your Data Privacy

Web Tool
Privacy-First Architecture
Most of our web tools process your data entirely in-browser. Where server processing is technically required, payloads are evaluated statelessly in-memory and are never stored, saved, or logged.
REST API
Stateless In-Memory Processing
When you use our API endpoints, your requests are processed strictly in-memory without persistent database storage, disk logging, or data retention.
Want to learn more about how we safeguard your information and infrastructure?
Read our full Privacy Policy for detailed security standards, data retention principles, and compliance guarantees.

What does the SSH Config to Ansible Inventory Converter do?

The SSH Config to Ansible Inventory Converter parses OpenSSH client configuration files (~/.ssh/config) and compiles them into ready-to-run Ansible INI (hosts.ini) or Ansible YAML inventory files. It automatically maps SSH host connection variables (HostName, User, Port, IdentityFile) to their standard Ansible inventory counterparts (ansible_host, ansible_user, ansible_port, ansible_ssh_private_key_file).

Core Concepts

Understanding SSH config to Ansible inventory mapping:

  • Host & Variable Extraction: Extracts SSH aliases into Ansible inventory inventory identifiers and assigns ansible_host from HostName.
  • Credential & Port Mapping: Maps IdentityFile paths to ansible_ssh_private_key_file and attaches custom ansible_port values for non-standard SSH ports.
  • Dual Inventory Formats: Compiles either classic flat Ansible INI format ([group] host key=value) or modern structured Ansible YAML hierarchy.
  • Custom Host Groups: Places all imported hosts under a customizable group identifier (such as [webservers] or [database]).

How to use the tool?

  1. Paste SSH Config: Paste your ~/.ssh/config file content into the editor or click Load Sample Config.
  2. Configure Format & Group: Select your desired output format (Ansible INI or Ansible YAML) and enter a Group Name (e.g. webservers).
  3. Convert & Copy: Click Convert to Ansible Inventory, then click Copy or Download to export the inventory file.

Related Developer Utilities

If you work with SSH keys, server provisioning, and infrastructure automation, explore these complementary tools:

REST API Integration

Blueutils provides a free REST API endpoint (POST https://blueutils.com/api/ssh/ssh-config-to-ansible) to programmatically convert OpenSSH client configuration (~/.ssh/config) files into Ansible INI (hosts.ini) or Ansible YAML inventory files.

API Request Parameters

Name Type Description Example
rawText String OpenSSH ~/.ssh/config content to parse. "Host web-1\n HostName 10.0.1.10\n User ubuntu"
format String Optional. Output format: "ini" (default) or "yaml". "ini"
groupName String Optional. Ansible host group name (default: "servers"). "webservers"

API Request Payload Examples

cURL

curl -X POST https://blueutils.com/api/ssh/ssh-config-to-ansible \
  -H "Content-Type: application/json" \
  -d '{
    "rawText": "Host web-1\n  HostName 10.0.1.10\n  User ubuntu\n  Port 2222\n  IdentityFile ~/.ssh/id_rsa",
    "format": "ini",
    "groupName": "webservers"
  }'

Python

import requests

url = "https://blueutils.com/api/ssh/ssh-config-to-ansible"
payload = {
    "rawText": "Host web-1\n  HostName 10.0.1.10\n  User ubuntu\n  Port 2222\n  IdentityFile ~/.ssh/id_rsa",
    "format": "ini",
    "groupName": "webservers"
}
headers = {"Content-Type": "application/json"}
response = requests.post(url, json=payload, headers=headers)
print(response.json())

Java

import java.net.URI;
import java.net.http.HttpClient;
import java.net.http.HttpRequest;
import java.net.http.HttpResponse;

public class Main {
    public static void main(String[] args) throws Exception {
        String jsonPayload = """
            {
                "rawText": "Host web-1\\n  HostName 10.0.1.10\\n  User ubuntu\\n  Port 2222\\n  IdentityFile ~/.ssh/id_rsa",
                "format": "ini",
                "groupName": "webservers"
            }
            """;

        HttpClient client = HttpClient.newHttpClient();
        HttpRequest request = HttpRequest.newBuilder()
            .uri(URI.create("https://blueutils.com/api/ssh/ssh-config-to-ansible"))
            .header("Content-Type", "application/json")
            .POST(HttpRequest.BodyPublishers.ofString(jsonPayload))
            .build();

        HttpResponse<String> response = client.send(request, HttpResponse.BodyHandlers.ofString());
        System.out.println(response.body());
    }
}

API Response Parameters

Name Type Description Example
isValid Boolean Indicates whether conversion succeeded. true
format String Output format produced ("ini" or "yaml"). "ini"
groupName String Name of the Ansible host group. "webservers"
hostsCount Number Count of converted host definitions. 1
converted String Formatted Ansible inventory content string. "[webservers]\nweb-1 ansible_host=10.0.1.10..."

API Response Payload Examples

Success Response (HTTP 200 OK)

{
  "isValid": true,
  "format": "ini",
  "groupName": "webservers",
  "hostsCount": 1,
  "converted": "[webservers]\nweb-1 ansible_host=10.0.1.10 ansible_user=ubuntu ansible_port=2222 ansible_ssh_private_key_file=~/.ssh/id_rsa"
}

Validation Failure Response (HTTP 400 Bad Request)

{
  "isValid": false,
  "error": "No valid Host blocks were found in the SSH config."
}

Rate Limit Exceeded Response (HTTP 429 Too Many Requests)

{
  "error": "API rate limit exceeded. Please wait or contact support@blueutils.com."
}

Why use an API to convert SSH config to Ansible?

Integrating the SSH Config to Ansible Converter API into DevOps provisioning scripts, cluster orchestrators, or AI agent tool calling provides key benefits:

  • Rapid Script Validation: Generates dynamic Ansible inventories from workstation developer configs or cloud bastion nodes on the fly.
  • Optimized Token Efficiency for AI Agents: LLMs frequently mix up Ansible INI and YAML syntax keys. Calling the API translates connection variables deterministically without token consumption.
  • Deterministic Accuracy Without Hallucinations: Ensures 100% compliant Ansible syntax generation for both INI and YAML specifications.

Native Usage

How to convert SSH configs to Ansible inventories locally in terminal environments or scripts:

Windows (CMD / PowerShell)

# Parse ~/.ssh/config into Ansible INI in PowerShell
$configPath = "$env:USERPROFILE\.ssh\config"
if (Test-Path $configPath) {
    Write-Output "[servers]"
    Get-Content $configPath | ForEach-Object {
        if ($_ -match '^\s*Host\s+([^\*]+)$') { $h = $matches[1].Trim() }
        elseif ($_ -match '^\s*HostName\s+(\S+)') { Write-Output "$h ansible_host=$($matches[1].Trim())" }
    }
}

Linux / Unix (Bash)

# Parse ~/.ssh/config into Ansible INI format in Linux
awk '/^Host / {host=$2} /^  HostName / {print host " ansible_host="$2}' ~/.ssh/config

Python

Using Python:

import re

with open("~/.ssh/config".replace("~", "/home/user")) as f:
    text = f.read()

print("[servers]")
for block in re.findall(r'Host\s+([^\n]+)\n\s+HostName\s+([^\n]+)', text):
    print(f"{block[0].strip()} ansible_host={block[1].strip()}")

Java

Using Java:

import java.nio.file.*;
import java.util.List;

public class SshToAnsibleExample {
    public static void main(String[] args) throws Exception {
        List<String> lines = Files.readAllLines(Paths.get(System.getProperty("user.home"), ".ssh", "config"));
        System.out.println("[servers]");
        String currentHost = "";
        for (String line : lines) {
            if (line.trim().startsWith("Host ")) {
                currentHost = line.trim().substring(5);
            } else if (line.trim().startsWith("HostName ")) {
                System.out.println(currentHost + " ansible_host=" + line.trim().substring(9));
            }
        }
    }
}

Frequently Asked Questions (FAQ)

How do I convert ~/.ssh/config to an Ansible inventory?

Paste your SSH config file, choose between INI or YAML output formats, specify a group name (e.g. servers), and click Convert to Ansible Inventory.

Which SSH config parameters are mapped into Ansible variables?

The tool maps HostName to ansible_host, User to ansible_user, non-standard Port to ansible_port, and IdentityFile to ansible_ssh_private_key_file.

Is data saved remotely?

No. All conversion logic executes strictly in browser memory without network transmission.

Rate Limits

UI Limits
100 uses per 15 minutes
Max payload size: 5 MB
API Limits
5 requests per 60 minutes
Max payload size: 256 KB
Need higher API rate limits, increased payload sizes, or custom developer solutions?
Contact our engineering team at support@blueutils.com for custom rate limit increases, higher quota allocations, or tailored enterprise integrations.