User Tools

Site Tools


ansible:ansible_inventory

This is an old revision of the document!


Ansible inventory

It is written in an INI or YAML format, lists host and groups. Can be static of dynamic.

Convert a ini file to

  • JSON :
    ansible-inventory -i /etc/ansible/hosts --list
  • YAML :
    ansible-inventory -i /etc/ansible/hosts --list --yaml

Example of Collection of groups Dev:children

# cat /etc/ansible/hosts
[managedClients]
[RHEL_Dev]
lab-rhel-1
lab-rhel-2

[AIX_Dev]
lab-aix-1
lab-aix-2

[Dev:children]
RHEL_Dev
AIX_Dev
# ansible-inventory --graph
@all:
  |--@Dev:
  |  |--@AIX_Dev:
  |  |  |--lab-aix-1
  |  |  |--lab-aix-2
  |  |--@RHEL_Dev:
  |  |  |--lab-rhel-1
  |  |  |--lab-rhel-2
  |--@local:
  |  |--localhost
# cat /etc/ansible/hosts
[managedClients]
[RHEL_Dev]
lab-rhel-1 ansible_user=ansible
lab-rhel-2 ansible_port=22

[AIX_Dev]
lab-aix-1  ansible_host=10.1.1.1
lab-aix-2

[Dev:children]
RHEL_Dev
AIX_Dev
# ansible-inventory –list
….
 "hostvars": {
            "lab-aix-1": {
                "ansible_host": "10.1.1.1"
            }, 
            "lab-rhel-1": {
                "ansible_user": "ansible"
            }, 
            "lab-rhel-2": {
                "ansible_port": 22
            }
….
ansible/ansible_inventory.1763471216.txt.gz · Last modified: 2025/11/18 14:06 by manu