Skip to content

Commit 58ce285

Browse files
committed
Refactor install scripts to improve PATH handling and streamline package installation
1 parent 676dbee commit 58ce285

2 files changed

Lines changed: 13 additions & 14 deletions

File tree

install-ansible

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,21 +4,19 @@ set -euo pipefail
44
SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"
55

66
USER_BIN="$(python3 -m site --user-base)/bin"
7-
export PATH="${PATH}:${USER_BIN}"
7+
export PATH="${USER_BIN}:${PATH}"
88

99
# Persist to ~/.bashrc if not already present
1010
if ! grep -qF "${USER_BIN}" "${HOME}/.bashrc"; then
1111
printf '\nexport PATH="${PATH}:%s"\n' "${USER_BIN}" >> "${HOME}/.bashrc"
1212
echo "Added ${USER_BIN} to ~/.bashrc"
1313
fi
1414

15-
PIPX_PACKAGES=(
16-
ansible-core
17-
ansible-lint
18-
yamllint
19-
)
15+
# Install ansible-core as the primary package, then inject ansible-lint into
16+
# the same venv so both share the same ansible binary and collections path.
17+
pipx upgrade ansible-core 2>/dev/null || pipx install ansible-core
18+
pipx inject --include-apps --force ansible-core ansible-lint
2019

21-
for package in "${PIPX_PACKAGES[@]}"; do
22-
pipx upgrade "${package}" 2>/dev/null || pipx install "${package}"
23-
done
24-
ansible-galaxy collection install -r "${SCRIPT_DIR}/requirements.yml" --upgrade
20+
pipx upgrade yamllint 2>/dev/null || pipx install yamllint
21+
22+
ansible-galaxy collection install -r "${SCRIPT_DIR}/requirements.yml" --upgrade

install-requirements

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
set -euo pipefail
33

44
SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"
5+
REQ_FILE="${SCRIPT_DIR}/requirements.txt"
56

67
# Ensure python3, pip, and venv are installed
78
PYTHON_PACKAGES=(
@@ -16,10 +17,10 @@ if ! dpkg -s "${PYTHON_PACKAGES[@]}" &>/dev/null; then
1617
sudo apt-get install -y "${PYTHON_PACKAGES[@]}"
1718
fi
1819

19-
# Ensure user-local bin is on PATH for pip-installed CLIs
20-
export PATH="${PATH}:$(python3 -m site --user-base)/bin"
20+
USER_BIN="$(python3 -m site --user-base)/bin"
21+
export PATH="${USER_BIN}:${PATH}"
2122

22-
# Install requirements
23-
REQ_FILE="${SCRIPT_DIR}/requirements.txt"
23+
# Install pip if missing
2424
python3 -m ensurepip --upgrade >/dev/null 2>&1 || true
2525
python3 -m pip install --user --break-system-packages --upgrade -r "${REQ_FILE}"
26+

0 commit comments

Comments
 (0)