Files
ansible-worker/files/entrypoint.sh-backup
ansible user 110301f862 first commit
2025-10-22 14:11:49 +02:00

36 lines
1.1 KiB
Bash

#!/usr/bin/env bash
set -euo pipefail
APP_DIR="/opt/containers/ansible-worker"
DATA_DIR="${APP_DIR}/data"
VENV_DIR="${DATA_DIR}/ansible_venv"
COLL_BASE="${DATA_DIR}/collections"
COLL_NETBOX_DIR="${COLL_BASE}/ansible_collections/netbox/netbox"
mkdir -p "$DATA_DIR"
# Bootstrap venv on first run
if [ ! -x "${VENV_DIR}/bin/ansible" ]; then
echo "[entrypoint] Creating venv in ${VENV_DIR} and installing packages..."
python3 -m venv "${VENV_DIR}"
"${VENV_DIR}/bin/python" -m pip install --upgrade pip setuptools wheel
"${VENV_DIR}/bin/pip" install \
"ansible-core==2.16.*" \
"pytz" \
"pynetbox==7.*"
echo "[entrypoint] venv bootstrap complete."
fi
# Ensure NetBox collection exists in the PERSISTENT collections path
if [ ! -d "${COLL_NETBOX_DIR}" ]; then
echo "[entrypoint] Installing netbox.netbox collection into ${COLL_BASE} ..."
mkdir -p "${COLL_BASE}"
"${VENV_DIR}/bin/ansible-galaxy" collection install netbox.netbox -p "${COLL_BASE}"
echo "[entrypoint] netbox.netbox installed."
fi
# Put venv first on PATH
export PATH="${VENV_DIR}/bin:${PATH}"
exec "$@"