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 21a057a3..908a59bf 100755 --- a/local-app/python-tools/build-ansible-distribution/create-ansible.sh +++ b/local-app/python-tools/build-ansible-distribution/create-ansible.sh @@ -1,6 +1,6 @@ #!/bin/bash -VERSION="1.0.2" +VERSION="1.0.3" THIS=$(basename $0 .sh) # Define the target directory @@ -56,7 +56,6 @@ EOF # 4. Create the venv and install dependencies # Use --python to specify 3.12, 3.13, etc. uv venv --python "$PYTHON_VERSION" \ - --copy-python \ --link-mode copy \ --seed @@ -65,13 +64,38 @@ source .venv/bin/activate # 5. Sync the environment uv sync --link-mode copy -# 6. Create a convenient entry point symlink -mkdir -p bin -ln -sf "$APP_DIR/.venv/bin/ansible" "$APP_DIR/bin/ansible" -ln -sf "$APP_DIR/.venv/bin/ansible-playbook" "$APP_DIR/bin/ansible-playbook" +# 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 + +chmod +x "$APP_DIR/bin/ansible" +chmod +x "$APP_DIR/bin/ansible-playbook" -echo "------------------------------------------------" -echo "Ansible distribution created at $APP_DIR" -echo "Python version: $(python --version)" -echo "To use: source $APP_DIR/.venv/bin/activate" -echo "------------------------------------------------" +# 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." +fi +echo "--------------------"