mirror of
https://github.com/kevinveenbirkenbach/computer-playbook.git
synced 2026-11-08 11:46:35 +00:00
Move:
- cli/build/inventory/full -> cli/administration/inventory/devices
- cli/create/inventory -> cli/administration/inventory/provision
- cli/create/credentials -> cli/administration/inventory/credentials
- cli/encrypt/inventory -> cli/administration/inventory/encrypt
Delete:
- cli/create/role + templates/roles/ (stale scaffolder)
- roles/web-app-baserow/templates/javascript.js.j2 + dead sso_warning snippet
- js_application_name across akaunting/baserow/opencloud/opentalk/taiga,
javascript service disabled for baserow + taiga
Wire-through:
- argv lists in cli/deploy/{container,development}/* + 2 shell scripts
now invoke 'infinito administration inventory provision'
- subprocess module names + docs (contributing/* + administration/deploy.md)
- discovery resolver test + folder-item-limit whitelist updated
- ruff fixes in devices/command.py (RET504 inline + Path.open over open)
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
109 lines
2.9 KiB
Python
109 lines
2.9 KiB
Python
from __future__ import annotations
|
|
|
|
import argparse
|
|
import json
|
|
import sys
|
|
from pathlib import Path
|
|
|
|
from plugins.filter.get_all_invokable_apps import get_all_invokable_apps
|
|
from utils.cache.yaml import dump_yaml_str
|
|
|
|
|
|
def build_group_inventory(apps: list[str], host: str) -> dict:
|
|
"""
|
|
Build an Ansible inventory in which each application is a group containing the given host.
|
|
"""
|
|
groups = {app: {"hosts": [host]} for app in apps}
|
|
return {
|
|
"all": {
|
|
"hosts": [host],
|
|
"children": {app: {} for app in apps},
|
|
},
|
|
**groups,
|
|
}
|
|
|
|
|
|
def build_hostvar_inventory(apps: list[str], host: str) -> dict:
|
|
"""
|
|
Alternative: Build an inventory where all invokable apps are set as a host variable (as a list).
|
|
"""
|
|
return {
|
|
"all": {"hosts": [host]},
|
|
"_meta": {
|
|
"hostvars": {
|
|
host: {
|
|
"invokable_applications": apps,
|
|
}
|
|
}
|
|
},
|
|
}
|
|
|
|
|
|
def main(argv: list[str] | None = None) -> int:
|
|
parser = argparse.ArgumentParser(
|
|
description="Build a dynamic Ansible inventory for a given host with all invokable applications."
|
|
)
|
|
parser.add_argument(
|
|
"--host",
|
|
required=True,
|
|
help="Hostname to assign to all invokable application groups",
|
|
)
|
|
parser.add_argument(
|
|
"-f",
|
|
"--format",
|
|
choices=["json", "yaml"],
|
|
default="yaml",
|
|
help="Output format (yaml [default], json)",
|
|
)
|
|
parser.add_argument(
|
|
"--inventory-style",
|
|
choices=["group", "hostvars"],
|
|
default="group",
|
|
help="Inventory style: group (default, one group per app) or hostvars (list as hostvar)",
|
|
)
|
|
parser.add_argument(
|
|
"-o",
|
|
"--output",
|
|
help="Write output to file instead of stdout",
|
|
)
|
|
parser.add_argument(
|
|
"-i",
|
|
"--ignore",
|
|
action="append",
|
|
default=[],
|
|
help="Application ID(s) to ignore (can be specified multiple times or comma-separated)",
|
|
)
|
|
|
|
args = parser.parse_args(argv)
|
|
|
|
try:
|
|
apps = get_all_invokable_apps()
|
|
except Exception as exc:
|
|
sys.stderr.write(f"Error: {exc}\n")
|
|
return 1
|
|
|
|
ignore_ids: set[str] = set()
|
|
for entry in args.ignore:
|
|
ignore_ids.update(i.strip() for i in entry.split(",") if i.strip())
|
|
|
|
if ignore_ids:
|
|
apps = [app for app in apps if app not in ignore_ids]
|
|
|
|
if args.inventory_style == "group":
|
|
inventory = build_group_inventory(apps, args.host)
|
|
else:
|
|
inventory = build_hostvar_inventory(apps, args.host)
|
|
|
|
if args.format == "json":
|
|
output = json.dumps(inventory, indent=2)
|
|
else:
|
|
output = dump_yaml_str(inventory)
|
|
|
|
if args.output:
|
|
with Path(args.output).open("w", encoding="utf-8") as fh:
|
|
fh.write(output)
|
|
else:
|
|
print(output)
|
|
|
|
return 0
|