Files
ansible-repo/playbooker.sh
hogweed1 a4f1125078
Some checks failed
Gitea Actions Demo / Explore-Gitea-Actions (push) Failing after 0s
auto ansi?
2025-11-21 01:19:26 +10:00

35 lines
1.0 KiB
Bash
Executable File

#!/bin/bash
CHANGED_FILES=$(git diff --name-only HEAD~1 HEAD)
PLAYBOOKS_TO_RUN=()
PLAYBOOKS_TO_RUN_JUST_CREATED=()
# Check for changes in specific directories and add corresponding playbooks
if echo "$CHANGED_FILES" | grep -q "files/prometheus/"; then
PLAYBOOKS_TO_RUN+=("playbooks/software/prometheus.yml")
fi
if echo "$CHANGED_FILES" | grep -q "environments/just-created/"; then
PLAYBOOKS_TO_RUN_JUST_CREATED+=("playbooks/_common-setup.yml")
fi
PLAYBOOKS_TO_RUN2=( $(printf "%s\n" "${PLAYBOOKS_TO_RUN[@]}" | sort -u) )
# Run the identified playbooks
if [ ${#PLAYBOOKS_TO_RUN2[@]} -gt 0 ]; then
for playbook in "${PLAYBOOKS_TO_RUN2[@]}"; do
echo "Running playbook: $playbook"
ansible-playbook "$playbook" -i environments/proxmoxes/hosts.yml
done
if [ ${#PLAYBOOKS_TO_RUN_JUST_CREATED[@]} -gt 0 ]; then
for playbook in "${PLAYBOOKS_TO_RUN_JUST_CREATED[@]}"; do
echo "Running playbook: $playbook"
ansible-playbook "$playbook" -i environments/just-created/hosts.yml
done
else
echo "No relevant playbooks modified. Skipping Ansible run."
fi