What are other inventory formats?

0135

Ansible supports several inventory file formats, allowing flexibility in how you define your hosts and groups. The main formats are:

1. INI Format

This is the traditional format, using a simple key-value structure.

[webservers]
192.168.1.10
192.168.1.11

[databases]
db1.example.com
db2.example.com

2. YAML Format

YAML is more human-readable and allows for complex structures, including nested groups and variables.

all:
  children:
    webservers:
      hosts:
        192.168.1.10:
        192.168.1.11:
    databases:
      hosts:
        db1.example.com:
        db2.example.com:

3. JSON Format

JSON can also be used, though it's less common due to its verbosity.

{
  "all": {
    "children": {
      "webservers": {
        "hosts": [
          "192.168.1.10",
          "192.168.1.11"
        ]
      },
      "databases": {
        "hosts": [
          "db1.example.com",
          "db2.example.com"
        ]
      }
    }
  }
}

Summary

You can choose the format that best fits your needs and preferences. YAML is often preferred for its readability, especially in larger inventories.

0 Comments

no data
Be the first to share your comment!