diff options
Diffstat (limited to 'bootstrap.sh')
| -rwxr-xr-x | bootstrap.sh | 56 |
1 files changed, 56 insertions, 0 deletions
diff --git a/bootstrap.sh b/bootstrap.sh new file mode 100755 index 0000000..6fe4797 --- /dev/null +++ b/bootstrap.sh @@ -0,0 +1,56 @@ +#!/bin/sh +set -e + +PLAYBOOK_DIR="$(cd "$(dirname "$0")" && pwd)" +PLAYBOOK="${PLAYBOOK_DIR}/site.yml" + +main() { + ensure_ansible_installed + ensure_ansible_collections_installed + run_playbook "$@" +} + +ensure_ansible_installed() { + log_step "Checking for Ansible" + if ! bin_exists ansible-playbook; then + log_step "Installing Ansible" + if bin_exists brew; then + brew install ansible + else + log_err "brew (homebrew) not found. Unsupported package manager. Install Ansible manually." + exit 1 + fi + else + log_step "Ansible already installed" + fi +} + +ensure_ansible_collections_installed() { + log_step "Checking for required ansible collections" + if ! ansible-galaxy collection list 2>/dev/null | grep --quiet community.general; then + log_step "Installing required Ansible collections..." + ansible-galaxy collection install community.general + else + log_step "Ansible collections already installed" + fi +} + +run_playbook() { + log_step "Running playbook" + ansible-playbook --ask-become-pass "$PLAYBOOK" "$@" + log_step "Done!" +} + +bin_exists() { + command -v "$1" >/dev/null 2>&1 +} + +log_step() { + echo "==> $1" +} + +log_err() { + echo "[ERROR] $1" >&2 +} + +main "$@" |