vps/ansible-playbook-selector.sh

28 lines
754 B
Bash
Raw Normal View History

2024-02-17 19:01:04 +01:00
#!/bin/bash
script_relative_path="$(dirname "$0")"
declare -i playbook_number=1
mapfile -t playbook_list < <(find "$script_relative_path/playbooks" -type f | grep -oP '[^/]+\.yml$')
echo "Playbook list:"
for playbook in "${playbook_list[@]}"; do
echo " [$playbook_number] $playbook"
playbook_number+=1
done
read -rp "Select playbook number to execute: " selected_playbook_number
selected_playbook_name="${playbook_list[((selected_playbook_number - 1))]}"
if ! echo "$selected_playbook_number" | grep -qP '^[1-9][0-9]*$' || [[ -z "$selected_playbook_name" ]]; then
echo "Invalid playbook number entered."
exit 1
fi
echo "Selected playbook: $selected_playbook_name"
ansible-playbook "$script_relative_path/playbooks/$selected_playbook_name"