#!/bin/sh set -o errexit set -o nounset main() { ensure_ansible_installed ensure_ansible_collections_installed } 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 } bin_exists() { command -v "$1" >/dev/null 2>&1 } log_step() { echo "==> $1" } log_err() { echo "[ERROR] $1" >&2 } main "$@"