From 5915306dae3ea830eaffd331e350a164a6cee613 Mon Sep 17 00:00:00 2001 From: badra001 Date: Fri, 30 Jan 2026 08:37:38 -0500 Subject: [PATCH] update --- .../create-ansible.sh | 60 +++++++++---------- 1 file changed, 27 insertions(+), 33 deletions(-) diff --git a/local-app/python-tools/build-ansible-distribution/create-ansible.sh b/local-app/python-tools/build-ansible-distribution/create-ansible.sh index 908a59bf..d93c656a 100755 --- a/local-app/python-tools/build-ansible-distribution/create-ansible.sh +++ b/local-app/python-tools/build-ansible-distribution/create-ansible.sh @@ -12,6 +12,7 @@ else fi PYTHON_VERSION="3.13" # Can be changed to 3.12 or latest +MAKE_RELOCATABLE=0 # Set to 1 to patch shebangs for any-path portability # 0. export environment variables needed export SSL_CERT_FILE=/etc/pki/tls/certs/ca-bundle.crt @@ -64,38 +65,31 @@ source .venv/bin/activate # 5. Sync the environment uv sync --link-mode copy -# 6. Create a portable wrapper for Ansible -# This avoids shebang issues if the folder is moved -mkdir -p "$APP_DIR/bin" -cat < "$APP_DIR/bin/ansible" -#!/bin/bash -export VIRTUAL_ENV="$APP_DIR/.venv" -export PATH="\$VIRTUAL_ENV/bin:\$PATH" -unset PYTHONHOME -exec "\$VIRTUAL_ENV/bin/python" -m ansible "\$@" -EOF -cat < "$APP_DIR/bin/ansible-playbook" -#!/bin/bash -export VIRTUAL_ENV="$APP_DIR/.venv" -export PATH="\$VIRTUAL_ENV/bin:\$PATH" -unset PYTHONHOME -exec "\$VIRTUAL_ENV/bin/python" -m ansible-playbook "\$@" -EOF +# 6. Ensure the Python binary itself is a physical copy +# This severs the link to ~/.local/share/uv/python/... +REAL_PYTHON=$(readlink -f .venv/bin/python) +if [ -L ".venv/bin/python" ]; then + echo "Converting Python symlink to physical binary..." + rm .venv/bin/python + cp "$REAL_PYTHON" .venv/bin/python +fi -chmod +x "$APP_DIR/bin/ansible" -chmod +x "$APP_DIR/bin/ansible-playbook" - -# 7. Verification -echo "--- Verification ---" -echo "Project Path: $APP_DIR" -echo "Python Path: $(readlink -f .venv/bin/python)" -if [[ $(ls -l .venv/bin/python) == *"->"* ]]; then - echo "Warning: Python is still a symlink. Attempting hard copy..." - # Manual intervention for absolute isolation: - # Replace the symlink with the actual binary - REAL_PYTHON=$(readlink -f .venv/bin/python) - rm .venv/bin/python - cp "$REAL_PYTHON" .venv/bin/python - echo "Python binary physically copied." +# 7. Optional: Make Relocatable +if [ "$MAKE_RELOCATABLE" -eq 1 ]; then + echo "MAKE_RELOCATABLE is active. Patching shebangs..." + # Replaces absolute path shebangs with /usr/bin/env python + # This allows the binaries to work regardless of the parent directory path + find .venv/bin -maxdepth 1 -type f -executable -exec \ + sed -i '1s|#!.*python|#!/usr/bin/env python|' {} + +else + echo "Skipping relocation patch. Scripts will use absolute paths: $APP_DIR" fi -echo "--------------------" + +# 8. Link bin to .venv/bin for easy access to all tools +ln -snf .venv/bin bin + +echo "------------------------------------------------" +echo "Ansible distribution ready at $APP_DIR" +echo "Relocatable: $([ "$MAKE_RELOCATABLE" -eq 1 ] && echo "YES" || echo "NO")" +echo "Try: $APP_DIR/bin/ansible --version" +echo "------------------------------------------------"