docs: synchronize README and user guide with v1.1.2 features, sorting, and filtering

This commit is contained in:
soda64 committed 2026-10-03 22:24:38 +02:00
1 parent 1dbbb1ce56
commit c116834be9
2 files changed
+115 -28

No files matched your search

+67 -10
View File
@@ -39,19 +39,66 @@ synology-nas 192.168.0.2 static:hosts.ini external, storage
| `-o`, `--output` | `PATH` | Write inventory to destination file. Format is inferred from extension (`.xml`, `.ini`, `.json`, `.yaml`). |
| `-f`, `--format` | `FORMAT` | Explicit output format: `ansible-yaml` (default), `ansible-json`, `linux-connector`, `yaml`, `xml`, `ini`. |
| `-s`, `--source` | `PATH` | Path to static file (`.ini` or `.yaml`). Can be repeated multiple times. |
| `--list` | *none* | Ansible Dynamic Inventory script mode (outputs JSON with `_meta.hostvars` to stdout). |
| `--check`, `--dry-run` | *none* | Print summary table to stdout and exit. |
| `--sync` | *none* | Update both Ansible (`inventory/hosts.yaml`) and `linux-connector` (`~/.config/linux-connector/hosts.yaml`) simultaneously. |
| `--list` | *none* | Ansible Dynamic Inventory script mode (outputs JSON with `_meta.hostvars` to stdout). Stderr is quieted. |
| `--check`, `--dry-run` | *none* | Print summary table to stdout and exit without modifying any files. |
| `--sync` | *none* | Update both Ansible (`destinations.ansible`) and `linux-connector` (`destinations.linux_connector`) simultaneously. |
| `-t`, `--tag`, `--filter-tag` | `TAG` | Filter inventory hosts by tag (case-insensitive, e.g. `hypervisor`, `k3s`). |
| `-g`, `--group`, `--filter-group` | `GROUP` | Filter inventory hosts by group or category name (e.g. `proxmox_vms`, `storage`). |
| `--source-type`, `--origin` | `SOURCE` | Filter hosts by source provider (`proxmox`, `static`, `file`, `k3s`). |
| `--sort`, `--sort-by` | `FIELD` | Sort hosts by `name` or `ip` (default: `name`, or config setting). Evaluates 32-bit/128-bit numerical IP order. |
| `-r`, `--reverse` | *none* | Reverse the sort order. |
| `--ansible-dest` | `PATH` | Target output path for Ansible inventory in `--sync` mode (overrides config). |
| `--lc-dest` | `PATH` | Target output path for linux-connector inventory in `--sync mode` (overrides config). |
| `-q`, `--quiet` | *none* | Silence all informational and warning log messages on stderr. |
| `-v`, `--verbose` | *none* | Enable verbose logging on stderr (forces output even in `--list` mode). |
| `-c`, `--config` | `PATH` | Path to configuration file. Default: `~/.config/inventory-collector/config.yaml`. |
| `-V`, `--version` | *none* | Show version and exit. |
| `-h`, `--help` | *none* | Show help message. |
---
## 3. Configuration File (`config.yaml`)
## 3. Filtering & Sorting
### Filtering Hosts
You can filter hosts in check mode (`--check`), sync mode (`--sync`), or when exporting to any format:
```bash
# Filter by tag:
inventory-collector --check -t hypervisor
# Filter by group / category:
inventory-collector --check -g proxmox_vms
# Filter by source provider (e.g. only hosts discovered via Proxmox):
inventory-collector --check --source-type proxmox
# Combine filters:
inventory-collector --check --source-type proxmox -t k3s -g k3s_cluster
```
### Sorting Hosts
Hosts can be sorted either by hostname or by IP address:
```bash
# Sort alphabetically by hostname (default):
inventory-collector --check --sort name
# Sort numerically by IP address (IPv4 32-bit octets / IPv6):
inventory-collector --check --sort ip
# Reverse sort order:
inventory-collector --check --sort ip -r
```
> [!NOTE]
> IP sorting accurately evaluates full IPv4 octets (`(192, 168, 0, 101) < (192, 168, 5, 51)` because $0 < 5$). CIDR prefixes (`/24`) and ports (`:22`) are automatically stripped before numerical comparison.
---
## 4. Configuration File (`config.yaml`)
Configuration can be stored in:
- `./inventory-collector.yaml` (current directory)
- `./inventory-collector.yaml` (current working directory)
- `~/.config/inventory-collector/config.yaml` (user-level)
- `/etc/inventory-collector/config.yaml` (system-level)
@@ -74,15 +121,19 @@ 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:
ansible: "inventory/hosts.yaml"
# 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"
```
---
## 4. Integration Examples
## 5. Integration Examples
### Ansible CLI
Use generated static file:
@@ -100,9 +151,15 @@ Sync directly to `linux-connector`:
```bash
inventory-collector --format linux-connector -o ~/.config/linux-connector/hosts.yaml
```
Or run simultaneous sync:
### Simultaneous Sync (`--sync`)
Update both Ansible and `linux-connector` simultaneously:
```bash
# Uses destinations configured in config.yaml:
inventory-collector --sync
# Or override destinations ad-hoc from CLI:
inventory-collector --sync --ansible-dest /etc/ansible/hosts.yaml --lc-dest ~/.config/linux-connector/hosts.yaml --sort ip
```
### Gitea Actions CI/CD Pipeline
@@ -114,12 +171,12 @@ In `.gitea/workflows/run-ansible.yml`:
ANSIBLE_PROXMOX_TOKEN_ID: ${{ secrets.ANSIBLE_PROXMOX_TOKEN_ID }}
ANSIBLE_PROXMOX_TOKEN_SECRET: ${{ secrets.ANSIBLE_PROXMOX_TOKEN_SECRET }}
run: |
inventory-collector --source ansible/inventory/static_hosts.ini -o ansible/inventory/hosts.yaml
inventory-collector --source ansible/inventory/static_hosts.ini --sort ip -o ansible/inventory/hosts.yaml
```
---
## 5. Deduplication & Conflict Warnings
## 6. Deduplication & Conflict Warnings
When the same machine is defined in multiple sources (e.g. in a static INI and dynamically discovered via Proxmox):
- **Groups & Tags:** Merged into a unified set.