auto ansi?
All checks were successful
Gitea Actions Demo / Explore-Gitea-Actions (push) Successful in 0s

This commit is contained in:
hogweed1
2025-11-21 01:15:42 +10:00
parent 7ac5bd3ec6
commit b615b5884a

View File

@@ -1,27 +1,35 @@
#!/bin/bash
# Get the list of changed files
CHANGED_FILES=$(git diff --name-only HEAD~1 HEAD)
# Initialize an array for playbooks to run
PLAYBOOKS_TO_RUN=()
PLAYBOOKS_TO_RUN_JUST_CREATED=()
# Check for changes in specific directories and add corresponding playbooks
if echo "$CHANGED_FILES" | grep -q "roles/webserver/"; then
PLAYBOOKS_TO_RUN+=("playbooks/webserver.yml")
if echo "$CHANGED_FILES" | grep -q "files/prometheus/"; then
PLAYBOOKS_TO_RUN+=("playbooks/software/prometheus.yml")
fi
if echo "$CHANGED_FILES" | grep -q "roles/database/"; then
PLAYBOOKS_TO_RUN+=("playbooks/database.yml")
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_RUN[@]} -gt 0 ]; then
for playbook in "${PLAYBOOKS_TO_RUN[@]}"; do
if [ ${#PLAYBOOKS_TO_RUN2[@]} -gt 0 ]; then
for playbook in "${PLAYBOOKS_TO_RUN2[@]}"; do
echo "Running playbook: $playbook"
ansible-playbook "$playbook" -i inventory.ini
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
shell: bash