Docs / Server Management / How to Set Up a Server Inventory with Ansible

How to Set Up a Server Inventory with Ansible

By Admin · Mar 1, 2026 · Updated Apr 23, 2026 · 26 views · 2 min read

What Is Ansible Inventory?

Ansible inventory is a file or directory that defines all the Breezes you manage. It organizes servers into groups, assigns variables, and provides the foundation for automation. Ansible connects over SSH with no agent required on target servers.

Step 1: Install Ansible

sudo apt update
sudo apt install -y ansible
ansible --version

Step 2: Create the Inventory File

Create /etc/ansible/hosts or a project-specific inventory:

# inventory.ini
[webservers]
web-01 ansible_host=198.51.100.10
web-02 ansible_host=198.51.100.11

[databases]
db-01 ansible_host=198.51.100.20

[monitoring]
monitor-01 ansible_host=198.51.100.30

[production:children]
webservers
databases
monitoring

[all:vars]
ansible_user=deploy
ansible_ssh_private_key_file=~/.ssh/deploy_key

Step 3: Test Connectivity

# Ping all hosts
ansible all -i inventory.ini -m ping

# Ping only webservers
ansible webservers -i inventory.ini -m ping

Step 4: Run Ad-Hoc Commands

# Check uptime across all Breezes
ansible all -i inventory.ini -m command -a "uptime"

# Check disk space on databases
ansible databases -i inventory.ini -m shell -a "df -h /"

# Update packages on webservers
ansible webservers -i inventory.ini -m apt -a "update_cache=yes upgrade=yes" --become

Dynamic Inventory

For cloud environments, use dynamic inventory scripts that query your infrastructure API to automatically discover servers. This eliminates manual inventory updates as Breezes are added or removed.

Organizing with Group Variables

Create group_vars/ directories to assign variables per group:

mkdir -p group_vars
echo "http_port: 80" > group_vars/webservers.yml
echo "db_port: 3306" > group_vars/databases.yml

Tips

  • Use YAML format for complex inventories with nested variables
  • Keep inventory in version control alongside your playbooks
  • Validate inventory with ansible-inventory --list

Was this article helpful?