Skip to content

Instantly share code, notes, and snippets.

@wate
Last active March 12, 2019 09:24
Show Gist options
  • Save wate/f471944865a090c8ded061623a952450 to your computer and use it in GitHub Desktop.
Save wate/f471944865a090c8ded061623a952450 to your computer and use it in GitHub Desktop.
インベントリファイルを YAML 形式で書く https://tekunabe.hatenablog.jp/entry/2019/03/10/ansible_inventory_yaml
---
# 元ネタ: https://tekunabe.hatenablog.jp/entry/2019/03/10/ansible_inventory_yaml
all:
hosts:
web01:
ansible_host: 127.16.0.1
router:
children:
junos:
ios:
junos:
hosts:
junos01:
ansible_host: 172.16.1.1
junos02:
ansible_host: 172.16.1.2
vars:
ansible_network_os: junos
ansible_connection: netconf
ios:
hosts:
ios01:
ansible_host: 172.16.2.1
ios02:
ansible_host: 172.16.2.22
vars:
ansible_network_os: ios
ansible_connection: network_cli

実行コマンド

ansible-inventory -i inventory.yml --list

出力結果

{
    "_meta": {
        "hostvars": {
            "ios01": {
                "ansible_connection": "network_cli",
                "ansible_host": "172.16.2.1",
                "ansible_network_os": "ios"
            },
            "ios02": {
                "ansible_connection": "network_cli",
                "ansible_host": "172.16.2.22",
                "ansible_network_os": "ios"
            },
            "junos01": {
                "ansible_connection": "netconf",
                "ansible_host": "172.16.1.1",
                "ansible_network_os": "junos"
            },
            "junos02": {
                "ansible_connection": "netconf",
                "ansible_host": "172.16.1.2",
                "ansible_network_os": "junos"
            },
            "web01": {
                "ansible_host": "127.16.0.1"
            }
        }
    },
    "all": {
        "children": [
            "router",
            "ungrouped"
        ]
    },
    "ios": {
        "hosts": [
            "ios01",
            "ios02"
        ]
    },
    "junos": {
        "hosts": [
            "junos01",
            "junos02"
        ]
    },
    "router": {
        "children": [
            "ios",
            "junos"
        ]
    },
    "ungrouped": {
        "hosts": [
            "web01"
        ]
    }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment