aboutsummaryrefslogtreecommitdiffstats
path: root/bootstrap.sh
blob: be0f4b729824b2a84748645b9deadea5f42035a5 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
#!/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 "$@"