blob: 6fe479703484e1cb2650da433ac950148e3dccfc (
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
48
49
50
51
52
53
54
55
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 "$@"
|