From 7021d132fc730f47962eb09414c2e5cd89f409d3 Mon Sep 17 00:00:00 2001 From: badra001 Date: Mon, 2 Feb 2026 15:36:48 -0500 Subject: [PATCH] do not make it relocatable or standalone --- .../create-ansible.sh | 101 ++++++++---------- .../build-ansible-distribution/manage_uv.sh | 2 +- 2 files changed, 43 insertions(+), 60 deletions(-) mode change 100755 => 100644 local-app/python-tools/build-ansible-distribution/create-ansible.sh diff --git a/local-app/python-tools/build-ansible-distribution/create-ansible.sh b/local-app/python-tools/build-ansible-distribution/create-ansible.sh old mode 100755 new mode 100644 index d9f92a9b..d3615960 --- a/local-app/python-tools/build-ansible-distribution/create-ansible.sh +++ b/local-app/python-tools/build-ansible-distribution/create-ansible.sh @@ -1,51 +1,54 @@ #!/bin/bash THIS=$(basename $0 .sh) -VERSION="1.0.7" +VERSION="1.1.5" # --- Configuration --- -APP_DIR="${1:-/apps/ansible}" +APP_DIR="/apps/ansible" +UV_MANAGED_DIR="/apps/uv" PYTHON_VERSION="3.13" -MAKE_RELOCATABLE=0 OWNER="root" GROUP="root" UMASK="022" # --------------------- -if [ $(id -u) == 0 ] -then - IS_ROOT=1 -else - IS_ROOT=0 -fi - -echo "Initializing Ansible Distribution v$VERSION..." - # 0. export environment variables needed export SSL_CERT_FILE=/etc/pki/tls/certs/ca-bundle.crt #export UV_PYTHON_INSTALL_DIR=/apps/uv/share export UV_LINK_MODE=copy export UV_NATIVE_TLS=true -# 1. Prepare Directory +# 1. Ensure UV Environment is active +if [ -f "$UV_MANAGED_DIR/uv_env.sh" ]; then + source "$UV_MANAGED_DIR/uv_env.sh" +else + echo "Error: UV environment not found at $UV_MANAGED_DIR/uv_env.sh" + exit 1 +fi + +echo "Building Ansible Distribution v$VERSION using Shared UV..." + +# 2. Prepare Directory mkdir -p "$APP_DIR" +# chown $OWNER:$GROUP "$APP_DIR" +chmod 755 "$APP_DIR" +cd "$APP_DIR" + if [ ! -z "$UMASK" ] then umask $UMASK fi -cd "$APP_DIR" -chmod 755 "$APP_DIR" -# chown $OWNER:$GROUP "$APP_DIR" -# 2. Initialize project +# 3. Initialize project with specific Python version +# uv will pull this from the shared /apps/uv/share directory uv init --no-workspace --app --python "$PYTHON_VERSION" -# 3. Create pyproject.toml +# 4. Create pyproject.toml cat < pyproject.toml [project] name = "ansible-dist" version = "$VERSION" -description = "Self-contained Ansible distribution" +description = "Ansible distribution using shared UV toolchain" requires-python = ">=$PYTHON_VERSION" dependencies = [ "ansible>=10.0.0", @@ -62,54 +65,34 @@ name = "pypi" url = "https://nexus.it.census.gov:8443/repository/DataScience-Group/simple" EOF -# 4. Create the Venv with Hard Copies -uv venv .venv --python "$PYTHON_VERSION" --seed --link-mode copy - -# 4.1. The "Encodings" Fix: Ensure pyvenv.cfg is correct -# We need to tell Python that the 'home' is the venv bin directory -cat < .venv/pyvenv.cfg -home = $APP_DIR/.venv/bin -include-system-site-packages = false -version = $PYTHON_VERSION -executable = $APP_DIR/.venv/bin/python -command = $UV_MANAGED_DIR/bin/uv venv .venv --python $PYTHON_VERSION --seed --link-mode copy -EOF +# 5. Create the Venv +# We use default linking (symlinks) to the shared UV python toolchain. +# This preserves the 'umbilical cord' so encodings/stdlib are found. +uv venv .venv --python "$PYTHON_VERSION" --seed -# 5. Sync dependencies -source .venv/bin/activate -uv sync --link-mode copy +# 6. Sync dependencies +# This installs Ansible into .venv/lib/python3.13/site-packages +uv sync -# 6. Physical Python Binary Copy -REAL_PYTHON=$(readlink -f .venv/bin/python) -if [ -L ".venv/bin/python" ]; then - rm .venv/bin/python - cp "$REAL_PYTHON" .venv/bin/python -fi - -# 6.1. Verify the Library structure -# Python needs the 'lib' folder in the same parent as 'bin' -if [ ! -d ".venv/lib" ] && [ -d ".venv/lib64" ]; then - ln -s lib64 .venv/lib -fi - -# 7. Optional: Relocatable Shebangs -if [ "$MAKE_RELOCATABLE" -eq 1 ]; then - find .venv/bin -maxdepth 1 -type f -executable -exec \ - sed -i '1s|#!.*python|#!/usr/bin/env python|' {} + -fi - -# 8. Link bin +# 7. Link top-level bin to venv bin ln -snf .venv/bin bin -# 9. Create /etc/profile.d script +# 8. Create Path Profile Script cat < ansible_path.sh # Ansible Distribution Path Configuration -# version $VERSION - -# Copy or link this to /etc/profile.d/ansible.sh if [ -d "$APP_DIR/bin" ]; then export PATH="$APP_DIR/bin:\$PATH" fi EOF -echo "Setup complete. Version $VERSION created." +# 9. Final Validation +echo "--- Final Validation ---" +if ./bin/ansible --version; then + echo "------------------------------------------------" + echo "Ansible v$VERSION is ready at $APP_DIR" + echo "Using Shared Python: \$(./bin/python -c 'import sys; print(sys.executable)')" + echo "------------------------------------------------" +else + echo "ERROR: Distribution check failed." + exit 1 +fi diff --git a/local-app/python-tools/build-ansible-distribution/manage_uv.sh b/local-app/python-tools/build-ansible-distribution/manage_uv.sh index 14327ed1..f4a18a6e 100755 --- a/local-app/python-tools/build-ansible-distribution/manage_uv.sh +++ b/local-app/python-tools/build-ansible-distribution/manage_uv.sh @@ -69,7 +69,7 @@ EOF #fi # Ensure the desired Python version is pre-installed in the shared location -$BASE_DIR/bin/uv python install 3.13 +$BASE_DIR/bin/uv python install 3.12 echo "------------------------------------------------" echo "uv $UV_VERSION installed successfully."