Skip to content

Commit

Permalink
do not make it relocatable or standalone
Browse files Browse the repository at this point in the history
  • Loading branch information
badra001 committed Feb 2, 2026
1 parent e15f60e commit 7021d13
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 60 deletions.
101 changes: 42 additions & 59 deletions local-app/python-tools/build-ansible-distribution/create-ansible.sh
100755 → 100644
Original file line number Diff line number Diff line change
@@ -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 <<EOF > 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",
Expand All @@ -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 <<EOF > .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 <<EOF > 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
Original file line number Diff line number Diff line change
Expand Up @@ -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."
Expand Down

0 comments on commit 7021d13

Please sign in to comment.