This commit is contained in:
plasmagoat 2025-06-09 01:28:22 +02:00
parent 4ce062937d
commit 619cf146fc
4 changed files with 120 additions and 49 deletions

View file

@ -1,6 +1,63 @@
#!/bin/bash
set -euo pipefail
echo "Starting Ansible CI/CD run..."
# --- 1. Validate required environment variables ---
if [[ -z "${PROXMOX_LOCAL_IMAGE_PATH_FROM_BUILD}" ]]; then
echo "Error: PROXMOX_LOCAL_IMAGE_PATH_FROM_BUILD environment variable not set. Cannot find built image."
exit 1
fi
# --- 2. Navigate to the Ansible directory ---
SCRIPT_DIR=$(cd "$(dirname "${BASH_SOURCE[0]}")" &>/dev/null && pwd -P)
ANSIBLE_DIR="${SCRIPT_DIR}/../ansible"
if [[ ! -d "${ANSIBLE_DIR}" ]]; then
echo "Error: Ansible directory not found at ${ANSIBLE_DIR}"
exit 1
fi
cd "${ANSIBLE_DIR}"
echo "Changed directory to: $(pwd)"
# --- 3. Define Ansible Extra Variables ---
# Base extra variables from our static definitions
EXTRA_VARS=(
# "local_image_path_ci=${PROXMOX_LOCAL_IMAGE_PATH_FROM_BUILD}" # Path to the image file on the CI runner
# "image_filename=$(basename "${PROXMOX_LOCAL_IMAGE_PATH_FROM_BUILD}")" # Extract filename
)
# Append any other variables passed via ANSIBLE_EXTRA_VARS from the workflow
if [[ -n "${ANSIBLE_EXTRA_VARS:-}" ]]; then
# Split by space or newline and add to array
IFS=$'\n' read -r -d '' -a ADDITIONAL_VARS <<< "${ANSIBLE_EXTRA_VARS}" || true
for var in "${ADDITIONAL_VARS[@]}"; do
EXTRA_VARS+=("${var}")
done
fi
# --- 4. Execute the Ansible Playbook ---
echo "Executing Ansible playbook: upload-template.yml"
# Construct the full --extra-vars string
EXTRA_VARS_ARGS=""
for var in "${EXTRA_VARS[@]}"; do
EXTRA_VARS_ARGS+=" -e ${var}"
done
ansible-playbook upload-template.yml \
--inventory inventory/hosts.yml \
${EXTRA_VARS_ARGS} \
--diff \
--check false # Set to true for a dry run, false for actual execution
echo "Ansible playbook execution finished."
#!/bin/bash
set -euo pipefail
# Navigate to the ansible directory
cd ansible