From d24b09802339e80e7d1d1c2fe81dbdb117bbf0cd Mon Sep 17 00:00:00 2001 From: "Eric D. Helms" Date: Wed, 22 Jul 2026 09:27:23 -0400 Subject: [PATCH] Proof of concept to use --target within the wrapper script to allow multi-host management --- anvil | 114 ++++++++++++++++++ .../certificate-bundle.yaml | 3 +- src/playbooks/checks/checks.yaml | 2 +- src/playbooks/deploy-proxy/deploy-proxy.yaml | 3 +- src/playbooks/deploy/deploy.yaml | 3 +- src/playbooks/features/features.yaml | 2 +- src/playbooks/health/health.yaml | 2 +- src/playbooks/migrate/migrate.yaml | 3 +- src/playbooks/pull-images/pull-images.yaml | 3 +- 9 files changed, 122 insertions(+), 13 deletions(-) create mode 100755 anvil diff --git a/anvil b/anvil new file mode 100755 index 000000000..6b1752b08 --- /dev/null +++ b/anvil @@ -0,0 +1,114 @@ +#!/bin/bash + +OBSAH_NAME=anvil +OBSAH_BASE=$(dirname $(readlink -f $0)) +OBSAH_INVENTORY=${OBSAH_BASE}/inventories +OBSAH_PERSIST_PARAMS=true + +ANSIBLE_COLLECTIONS_PATH=${OBSAH_BASE}/build/collections/foremanctl:${OBSAH_BASE}/build/collections/forge +ANSIBLE_COLLECTIONS_SCAN_SYS_PATH=false + +obsah_help() { + OBSAH_NAME=anvil OBSAH_DATA="${OBSAH_BASE}/$1" OBSAH_INVENTORY="${OBSAH_INVENTORY}" \ + OBSAH_STATE="${OBSAH_BASE}/.var/lib/anvil" obsah --help 2>&1 +} + +extract_commands() { + sed -n '/^ [a-z]/p' +} + +show_help() { + cat <] [options] + +Options: + --target Target host for deployment and state isolation + (scopes parameters, secrets, and .installed per host) + +Server and proxy commands: +$(obsah_help src | extract_commands) + +Development commands: +$(obsah_help development | extract_commands) + +Run 'anvil --help' for command-specific options. +EOF +} + +# Extract --target before obsah sees the arguments +TARGET="" +ARGS=() +while [[ $# -gt 0 ]]; do + case "$1" in + --target=*) + TARGET="${1#--target=}" + shift + ;; + --target) + if [[ -z "$2" || "$2" == -* ]]; then + echo "Error: --target requires a hostname argument" >&2 + exit 1 + fi + TARGET="$2" + shift 2 + ;; + *) + ARGS+=("$1") + shift + ;; + esac +done +set -- "${ARGS[@]}" + +if [[ -z "$1" || "$1" == "--help" || "$1" == "-h" ]]; then + show_help + exit 0 +fi + +case "$1" in + deploy|backup|health|checks|features|migrate|certificate-bundle|pull-images) + OBSAH_DATA=${OBSAH_BASE}/src + if [[ -n "$TARGET" ]]; then + OBSAH_STATE=${OBSAH_BASE}/.var/lib/anvil/server/${TARGET} + else + OBSAH_STATE=${OBSAH_BASE}/.var/lib/anvil/server + fi + ANSIBLE_LOG_PATH=${OBSAH_STATE}/anvil.log + export ANSIBLE_LOG_PATH + unset http_proxy HTTP_PROXY https_proxy HTTPS_PROXY + ;; + deploy-proxy) + OBSAH_DATA=${OBSAH_BASE}/src + if [[ -n "$TARGET" ]]; then + OBSAH_STATE=${OBSAH_BASE}/.var/lib/anvil/proxy/${TARGET} + else + OBSAH_STATE=${OBSAH_BASE}/.var/lib/anvil/proxy + fi + ANSIBLE_LOG_PATH=${OBSAH_STATE}/anvil.log + export ANSIBLE_LOG_PATH + unset http_proxy HTTP_PROXY https_proxy HTTPS_PROXY + ;; + deploy-dev|vms|test|smoker|custom-certs|fetch-bundle|security|sos|lock) + OBSAH_DATA=${OBSAH_BASE}/development + if [[ -n "$TARGET" ]]; then + OBSAH_STATE=${OBSAH_BASE}/.var/lib/anvil/dev/${TARGET} + else + OBSAH_STATE=${OBSAH_BASE}/.var/lib/anvil/dev + fi + ;; + *) + OBSAH_DATA=${OBSAH_BASE}/development + OBSAH_STATE=${OBSAH_BASE}/.var/lib/anvil/dev + ;; +esac + +mkdir -p "${OBSAH_STATE}" + +export OBSAH_NAME OBSAH_DATA OBSAH_INVENTORY OBSAH_STATE OBSAH_PERSIST_PARAMS +export ANSIBLE_COLLECTIONS_PATH ANSIBLE_COLLECTIONS_SCAN_SYS_PATH + +if [[ -n "$TARGET" ]]; then + exec obsah "$@" -e "target_host=${TARGET}" +else + exec obsah "$@" +fi diff --git a/src/playbooks/certificate-bundle/certificate-bundle.yaml b/src/playbooks/certificate-bundle/certificate-bundle.yaml index 7971da4ec..58a591a7f 100644 --- a/src/playbooks/certificate-bundle/certificate-bundle.yaml +++ b/src/playbooks/certificate-bundle/certificate-bundle.yaml @@ -1,7 +1,6 @@ --- - name: Generate a certificate bundle for a hostname - hosts: - - quadlet + hosts: "{{ target_host | default('quadlet') }}" become: true vars_files: - "../../vars/base.yaml" diff --git a/src/playbooks/checks/checks.yaml b/src/playbooks/checks/checks.yaml index de24fa466..0dad5ecc1 100644 --- a/src/playbooks/checks/checks.yaml +++ b/src/playbooks/checks/checks.yaml @@ -1,6 +1,6 @@ --- - name: Run preflight checks - hosts: quadlet + hosts: "{{ target_host | default('quadlet') }}" gather_facts: true vars: flavor: katello diff --git a/src/playbooks/deploy-proxy/deploy-proxy.yaml b/src/playbooks/deploy-proxy/deploy-proxy.yaml index 151c08e87..2f71a765f 100644 --- a/src/playbooks/deploy-proxy/deploy-proxy.yaml +++ b/src/playbooks/deploy-proxy/deploy-proxy.yaml @@ -1,7 +1,6 @@ --- - name: Setup proxy machine - hosts: - - proxy + hosts: "{{ target_host | default('proxy') }}" become: true vars: flavor: foreman-proxy-content diff --git a/src/playbooks/deploy/deploy.yaml b/src/playbooks/deploy/deploy.yaml index 4e77b6398..6c7fa9a8f 100644 --- a/src/playbooks/deploy/deploy.yaml +++ b/src/playbooks/deploy/deploy.yaml @@ -1,7 +1,6 @@ --- - name: Setup machine - hosts: - - quadlet + hosts: "{{ target_host | default('quadlet') }}" become: true vars: flavor: katello diff --git a/src/playbooks/features/features.yaml b/src/playbooks/features/features.yaml index 12e501c0d..e66765bba 100644 --- a/src/playbooks/features/features.yaml +++ b/src/playbooks/features/features.yaml @@ -1,6 +1,6 @@ --- - name: List features - hosts: quadlet + hosts: "{{ target_host | default('quadlet') }}" gather_facts: false tags: - foremanctl_suppress_default_output diff --git a/src/playbooks/health/health.yaml b/src/playbooks/health/health.yaml index d35b49762..8aff7f97e 100644 --- a/src/playbooks/health/health.yaml +++ b/src/playbooks/health/health.yaml @@ -1,6 +1,6 @@ --- - name: Run Foreman health checks - hosts: quadlet + hosts: "{{ target_host | default('quadlet') }}" become: true gather_facts: true vars: diff --git a/src/playbooks/migrate/migrate.yaml b/src/playbooks/migrate/migrate.yaml index 8518f92b9..e5024a748 100644 --- a/src/playbooks/migrate/migrate.yaml +++ b/src/playbooks/migrate/migrate.yaml @@ -1,7 +1,6 @@ --- - name: Migrate from foreman-installer to foremanctl - hosts: - - quadlet + hosts: "{{ target_host | default('quadlet') }}" gather_facts: true become: true vars_files: diff --git a/src/playbooks/pull-images/pull-images.yaml b/src/playbooks/pull-images/pull-images.yaml index fe2a26b8d..d7e2e551a 100644 --- a/src/playbooks/pull-images/pull-images.yaml +++ b/src/playbooks/pull-images/pull-images.yaml @@ -1,7 +1,6 @@ --- - name: Pull images - hosts: - - quadlet + hosts: "{{ target_host | default('quadlet') }}" vars: flavor: katello vars_files: