8.5 KiB
Gate 1 — Spec & Product: inventory-collector
1. Problem Statement
Homelab operators and sysadmins run infrastructure across heterogeneous environments:
- Hypervisors (Proxmox VE with dozens of virtual machines and LXC containers),
- Bare-metal appliances and unmanaged hardware (NAS, managed switches, routers, jump hosts),
- Container orchestration nodes (K3s / Kubernetes clusters).
Today, maintaining inventory of these machines is heavily fragmented and manual:
- Static files (such as
static_hosts.ini) become outdated as soon as new VMs are created, destroyed, or receive new IP addresses. - Separate tools maintain duplicate, divergent lists: Ansible requires its own inventory, connection managers (like
linux-connector) require their own host list, and CI/CD pipelines require separate inventory files. - When the same server is defined in multiple places (e.g. in a static file for legacy reasons and discovered dynamically via Proxmox API), tools either duplicate the host, fail with ambiguous errors, or silently use stale parameters.
inventory-collector solves this by acting as a single, lightweight command-line utility that collects hosts from all configured homelab sources, merges them in memory, warns operators of any duplicates or IP conflicts, and generates a unified, standard inventory ready for immediate use by Ansible, linux-connector, and CI/CD automation.
2. Measurable Success Criteria
- Single Command Generation: Running a single command generates a complete, validated inventory for a homelab environment (50+ hosts) in under 500 milliseconds (from local/cached sources) or under 2 seconds (including live Proxmox API network queries).
- 100% Ansible Interoperability: Generated inventory passes
ansible-inventory -i <generated_file> --graphandansible-inventory -i <generated_file> --listwith zero syntax errors or warnings. - 100% linux-connector Interoperability: The exact same output (or simultaneously generated
hosts.yaml) can be loaded bylinux-connectorwithout transformation, enabling immediate fuzzy search and fleet execution across all discovered nodes and groups. - Deterministic Deduplication & Conflict Detection:
- 0 duplicate host records in the output even if the same machine is present in both static files and Proxmox.
- Any conflicting definition (such as mismatched IP addresses or conflicting SSH users for the same host identifier) emits a clear, human-readable warning on standard error without crashing the process.
- Zero Complex Dependencies: Operates out-of-the-box on standard Linux workstations, macOS, and lightweight CI/CD runner environments without requiring external databases or heavy service daemons.
3. Announcement & User Stories
Announcement
"Introducing
inventory-collector— the single source of truth for homelab and fleet inventory. Stop manually maintaining separate host lists across Ansible, SSH managers, and CI/CD.inventory-collectordynamically queries your hypervisors and static definitions, deduplicates host records with smart conflict warnings, and generates unified inventory files for Ansible andlinux-connectorin a single command."
User Stories
- As a homelab administrator, I want to add or clone a new VM in Proxmox and run
inventory-collector, so that the new machine is instantly accessible inlinux-connectorand available for Ansible playbooks without touching any static config files. - As a DevOps engineer, I want
inventory-collectorto run in my Gitea Actions CI/CD pipeline before executing Ansible playbooks, ensuring my deployment runs against the real-time state of the cluster. - As a sysadmin, I want to define non-Proxmox devices (like Synology NAS and home routers) in a simple static YAML or INI file and have them automatically merged into the fleet inventory with their proper groups and tags.
- As an operator, I want to be warned if a static file still lists an old IP for a host that Proxmox reports with a different IP, so that I can easily spot and fix network configuration drift.
4. CLI Experience & User Interfaces
inventory-collector is a command-line application designed for both interactive terminal use and headless automation in scripts and CI/CD pipelines.
Primary Commands & Modes
1. Standard Generation (Default)
Generates the inventory file and writes it to disk or stdout:
$ inventory-collector
[INFO] Querying Proxmox VE (3 nodes, 18 VMs/LXCs found)...
[INFO] Reading static file '/etc/inventory-collector/static_hosts.yaml' (4 hosts found)...
[WARN] Duplicate host 'k3s-master-0' found in static file and Proxmox API (IP: 192.168.5.70). Merged tags and groups.
[SUCCESS] Generated unified inventory with 21 unique hosts across 6 groups -> /etc/ansible/hosts.yaml
2. Writing to Custom Destination or linux-connector Path
$ inventory-collector -o ~/.config/linux-connector/hosts.yaml --format linux-connector
[INFO] Discovered 21 hosts.
[SUCCESS] Written linux-connector inventory to ~/.config/linux-connector/hosts.yaml
3. Dual Export (Ansible + linux-connector simultaneously)
A single run can update both targets at once:
$ inventory-collector --sync
[INFO] Collecting from all configured sources...
[SUCCESS] Updated Ansible inventory: /etc/ansible/hosts.yaml
[SUCCESS] Updated linux-connector inventory: ~/.config/linux-connector/hosts.yaml
4. Dry-Run / Inspection Mode (--check / --dry-run)
Prints a clean tabular summary of discovered hosts, groups, and any warnings to the terminal without modifying any files:
$ inventory-collector --check
======================== Discovered Inventory ========================
NAME IP ADDRESS SOURCE GROUPS TAGS
node0 192.168.0.101 Proxmox proxmox_nodes pve, hypervisor
k3s-master-0 192.168.5.70 Hybrid* k3s_master, k3s control-plane, terraform
tool-server-1 192.168.5.61 Proxmox tool_servers debian, utility
synology-nas 192.168.0.2 Static storage, external nas, btrfs
----------------------------------------------------------------------
Total hosts: 21 | Groups: 6 | Duplicates merged: 1 | Conflicts: 0
======================================================================
* Hybrid indicates host was present in multiple sources and successfully merged.
5. Ansible Executable Dynamic Inventory Mode (--list)
Supports running directly as an Ansible dynamic inventory script:
$ ansible-playbook -i /usr/local/bin/inventory-collector playbooks/site.yml
When invoked by Ansible with --list, it writes valid Ansible Dynamic Inventory JSON with _meta.hostvars directly to stdout and suppresses all informational logs from stdout (sending warnings/diagnostics only to stderr).
5. Conflict Resolution & Warning Discipline
When merging records from multiple sources, inventory-collector follows strict, predictable rules:
- Host Identity Matching: Hosts are matched first by canonical hostname/name, and second by primary IPv4 address.
- Additive Attributes (Union): Groups and tags from all matching sources are merged together without duplicates.
- Attribute Discrepancies (Warnings):
- If Source A and Source B specify different IP addresses for the same hostname:
[WARN] IP conflict for host 'alma-crash': Proxmox reports '192.168.5.51', static file specifies '192.168.5.99'. Using Proxmox runtime IP. - If Source A and Source B specify different SSH usernames:
[WARN] User conflict for host 'node0': Proxmox default is 'lain', static file specifies 'root'. Using static file.
- If Source A and Source B specify different IP addresses for the same hostname:
- Clean Stdio Separation:
- Standard output (
stdout) is reserved strictly for inventory payloads when piping or in--listmode. - All human-facing progress messages, warnings, and error logs are written to standard error (
stderr).
- Standard output (
6. Non-Goals & Boundaries (Keeping it Lean)
- No SSH connection execution:
inventory-collectordoes NOT open SSH connections, manage TTYs, or execute remote commands. That is the explicit role oflinux-connectorandansible. - No state management or orchestration: It does NOT create, destroy, or modify VMs. That is the role of
terraformandproxmox. - No daemon or background service: It is a fast, stateless CLI utility executed on demand, on a cron schedule, or as part of CI/CD pipelines.
- No heavy database backend: All collection, deduplication, and file generation happens in-memory with sub-second execution.