-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
72 additions
and
0 deletions.
There are no files selected for viewing
72 changes: 72 additions & 0 deletions
72
local-app/python-tools/build-ansible-distribution/create-ansible.sh
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,72 @@ | ||
| #!/bin/bash | ||
|
|
||
| VERSION="1.0.0" | ||
| THIS=$(basename $0 .sh) | ||
|
|
||
| # Define the target directory | ||
| if [ -z "$1" ] | ||
| then | ||
| APP_DIR="/apps/ansible" | ||
| else | ||
| APP_DIR="$1" | ||
| fi | ||
|
|
||
| PYTHON_VERSION="3.13" # Can be changed to 3.12 or latest | ||
|
|
||
| # 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. Create and enter the directory | ||
| mkdir -p "$APP_DIR" | ||
| chown $(whoami):$(whoami) "$APP_DIR" | ||
| cd "$APP_DIR" | ||
|
|
||
| # 2. Initialize the uv project | ||
| uv init --no-workspace --app | ||
|
|
||
| # 3. Create the pyproject.toml with Ansible dependencies | ||
| cat <<EOF > pyproject.toml | ||
| [project] | ||
| name = "ansible-distribution" | ||
| version = "1.0.0" | ||
| description = "Self-contained Ansible distribution" | ||
| readme = "README.md" | ||
| requires-python = ">=3.12" | ||
| dependencies = [ | ||
| "ansible>=10.0.0", | ||
| "ansible-lint", | ||
| "jmespath", | ||
| "netaddr", | ||
| "dnspython>=2.8.0", | ||
| ] | ||
| [tool.uv] | ||
| # This ensures the venv is created within the project folder | ||
| dev-dependencies = [] | ||
| [[tool.uv.index]] | ||
| name = "pypi" | ||
| url = "https://nexus.it.census.gov:8443/repository/DataScience-Group/simple" | ||
| EOF | ||
|
|
||
| # 4. Create the venv and install dependencies | ||
| # Use --python to specify 3.12, 3.13, etc. | ||
| uv venv --python "$PYTHON_VERSION" | ||
| source .venv/bin/activate | ||
|
|
||
| # 5. Sync the environment | ||
| uv sync | ||
|
|
||
| # 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" | ||
|
|
||
| echo "------------------------------------------------" | ||
| echo "Ansible distribution created at $APP_DIR" | ||
| echo "Python version: $(python --version)" | ||
| echo "To use: source $APP_DIR/.venv/bin/activate" | ||
| echo "------------------------------------------------" |