d562c09e0c5b5d165659a886ca56d561050685a9
Build and Publish Release / Build Packages and Publish (push) Successful in 9s
Inventory Collector (inventory-collector)
Universal homelab and fleet inventory collector and deduplicator for Ansible and linux-connector.
Features
- Multi-Source Discovery: Gathers physical hosts, virtual machines, and LXC containers dynamically from Proxmox VE REST API, alongside static Ansible INI and YAML files.
- In-Memory Deduplication: Automatically merges host records across sources, calculates group and tag unions, and flags IP/user conflicts on
stderr. - 4-Tier IP Resolution: QEMU Guest Agent
\rightarrowPVE hardware config (ipconfig0)\rightarrowStatic definitions\rightarrowLocal DNS resolution with wildcard NXDOMAIN collision protection. - Filtering & Selective Querying: Filter inventory dynamically by tag (
-t), group/category (-g), or source provider (--source-type {proxmox,static,k3s}). - Mathematical IP & Name Sorting: Sort hosts by name or IP (
--sort {name,ip},-r/--reverse). IP sorting accurately evaluates IPv4 octets (32-bit integer) and IPv6 addresses, handling CIDR prefixes (/24) and ports (:22). - Clean YAML (No Anchors): Generates clean, human-readable YAML without YAML anchors or aliases (
&id/*id). - Multi-Format Exporters:
ansible-yaml: Native Ansible YAML inventory (all.children).ansible-json: Executable Ansible Dynamic Inventory script format (--listwith_meta.hostvars).linux-connector: Nativehosts.yamlfor instant pairing withlinux-connector.yaml: Clean, generic YAML dictionary.xml: Well-formed, pretty-printed XML for CMDB and enterprise monitoring tools.ini: Standard Ansible INI inventory sections.
- Simultaneous Target Sync (
--sync): Synchronizes both Ansible andlinux-connectorinventories with one command, with customizable destination paths (--ansible-dest,--lc-dest) and~home directory expansion. - Zero-Secrets Policy: Credentials read from environment variables (
PROXMOX_*,ANSIBLE_PROXMOX_*) or configuration files with variable interpolation and automatic.envloading. - Lean Runtime: Pure Python 3 standard library with optional
PyYAMLacceleration.
Installation
From Gitea Package Registry (RPM / Fedora / Alma / Rocky)
# Add Wired LAB Gitea repository (/etc/yum.repos.d/gitea-wired.repo)
sudo dnf install -y inventory-collector
From Debian / Ubuntu (.deb)
sudo dpkg -i inventory-collector_1.1.3_all.deb
Standalone Tarball Installer
tar -xzf inventory-collector-1.1.3.tar.gz
cd inventory-collector-1.1.3
sudo ./install.sh
From Source Checkout
git clone https://gitea.wired.synology.me/soda64/inventory-collector.git
cd inventory-collector
pip install -r requirements.txt
Usage
Quick Start
# Print Ansible YAML inventory to stdout
inventory-collector
# Inspect discovered inventory in terminal table (dry run)
inventory-collector --check
# Generate Ansible dynamic inventory JSON for CI/CD
inventory-collector --list
# Synchronize both Ansible and linux-connector files simultaneously
inventory-collector --sync
Sorting & Filtering
# Sort hosts mathematically by IP address (numerical 32-bit order)
inventory-collector --check --sort ip
# Filter only Proxmox VMs tagged with 'k3s'
inventory-collector --check --source-type proxmox -t k3s
# Filter by group and sort by IP in reverse order
inventory-collector -g storage --sort ip -r
# Export filtered inventory to Ansible YAML
inventory-collector -t production --sort ip -o inventory/production.yaml
Synchronization & Custom Destinations
# Sync with explicit destination paths
inventory-collector --sync --ansible-dest ~/.config/inventory-collector/hosts.yaml --lc-dest ~/.config/linux-connector/hosts.yaml
# Sync with custom Ansible path using short flag -o
inventory-collector --sync -o /etc/ansible/hosts.yaml --sort ip
Format Selection
# Export to XML
inventory-collector --format xml --sort ip -o fleet.xml
# Export to INI
inventory-collector --format ini --sort ip -o hosts.ini
# Export to linux-connector
inventory-collector --format linux-connector -o ~/.config/linux-connector/hosts.yaml
Configuration (config.yaml)
Store configuration in ~/.config/inventory-collector/config.yaml, /etc/inventory-collector/config.yaml, or ./inventory-collector.yaml:
sources:
proxmox:
enabled: true
url: "${PROXMOX_URL}"
token_id: "${PROXMOX_TOKEN_ID}"
token_secret: "${PROXMOX_TOKEN_SECRET}"
verify_ssl: false
timeout: 10
static_files:
- path: "~/.config/inventory-collector/static_hosts.ini"
required: false
defaults:
ssh_user: "lain"
ssh_port: 22
conflict_policy: "runtime_over_static"
sort_by: "ip" # Default sorting: "name" or "ip"
sort_reverse: false # Set true to reverse sort order by default
destinations:
# In --sync mode, destinations define where unified inventories are written.
# Supports '~' home expansion or absolute paths:
ansible: "~/.config/inventory-collector/hosts.yaml"
linux_connector: "~/.config/linux-connector/hosts.yaml"
Documentation
- User Guide — Complete operational manual and examples.
- UNIX Manual Page — Section 1 manual page.
- Software Factory Plans — Architecture, specifications, and design documents.
License
MIT
Description
Universal homelab and fleet inventory collector and deduplicator for Ansible and linux-connector
213 KiB
0 Stars
1 Watchers
0 Forks