Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
badra001 committed Jan 30, 2026
1 parent 18cfdf6 commit f2db57e
Showing 1 changed file with 35 additions and 11 deletions.
46 changes: 35 additions & 11 deletions local-app/python-tools/build-ansible-distribution/create-ansible.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/bin/bash

VERSION="1.0.2"
VERSION="1.0.3"
THIS=$(basename $0 .sh)

# Define the target directory
Expand Down Expand Up @@ -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

Expand All @@ -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 <<EOF > "$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 <<EOF > "$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 "--------------------"

0 comments on commit f2db57e

Please sign in to comment.