Skip to content

How to create a host Inventory using Ansible?

Updated 2 min read

Updated: 11 October 2026 · Applies to: Ansible (ansible-core 2.16+) on Ubuntu 24.04, Debian 12, AlmaLinux 9 and Rocky Linux 9

An inventory lists the servers Ansible manages. Ansible can also collect facts from each server (OS, memory, disks, IPs) to build an overview of your whole estate. These steps use current Ansible (ansible-core 2.16 or newer).

A static inventory

# inventory.yml
all:
  children:
    web:
      hosts:
        web1.example.com:
        web2.example.com:
    db:
      hosts:
        db1.example.com:
  vars:
    ansible_user: admin
ansible-inventory -i inventory.yml --graph      # show groups and hosts
ansible-inventory -i inventory.yml --list       # everything as JSON

Collect facts from all hosts

ansible all -i inventory.yml -m ansible.builtin.setup --tree facts/

This writes one JSON file per host into facts/ with the OS version, CPU, memory, disks and network. Filter with -a "filter=ansible_distribution*".

Turn facts into an overview

  • The ansible-cmdb tool (installed with pipx) generates an HTML overview from that folder: ansible-cmdb facts/ > overview.html. It is no longer actively developed; check it works with your data.
  • Or write a small playbook that uses ansible.builtin.template to create a CSV or Markdown table from the facts you need.

Tip: For cloud servers, dynamic inventory plugins read the server list directly from the provider's API, so the inventory is always current.

Related services

KVM VPS hosting

NVMe SSD and full root access, with Free Basic Managed Support.

Unmanaged dedicated servers

full root access and free IPMI KVM, with Free Basic Managed Support.

Linux server management

hardening, patching, monitoring and automation for Ubuntu, Debian, RHEL and AlmaLinux.

Was this answer helpful?

Still stuck? Open a ticket