-
Notifications
You must be signed in to change notification settings - Fork 0
/
ansible.sh
executable file
·66 lines (59 loc) · 1.72 KB
/
ansible.sh
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
57
58
59
60
61
62
63
64
65
66
#!/usr/bin/env bash
set -euoE pipefail
cwd="$HOME/.dotfiles"
_usage() {
printf "
Usage:
my -h, --help
my COMMAND [ARGS]
[ARGS] are ansible-playbook args
COMMAND:
run [ARGS] Run playbook with args on local pc
dotfiles_link [ARGS] Only link dotfiles, without running other playbook steps
dotfiles_unlink [ARGS] Only unlink dotfiles, without running other playbook steps
ansible_deps [ARGS] Install ansible dependencies for this playbook
run_remote [ARGS] Run playbook with args on remote pc, using 'inventory' file
\n"
}
_install_ansible_deps() {
echo "⚪ [ansible] installing deps..."
ansible-galaxy install -r $cwd/requirements.yaml
if [ ! -f "$cwd/library/stow" ]; then
wget https://raw.githubusercontent.com/caian-org/ansible-stow/v1.1.0/stow
mkdir -p "$cwd/library"
mv stow "$cwd/library"
fi
echo "✅ [ansible] deps installed!"
}
_run_playbook() {
echo "⚪ [ansible] running playbook..."
local playbook_opts=(
"--inventory=$cwd/inventory"
"$cwd/main.yaml"
)
playbook_opts+=($@)
echo "parameters: ${playbook_opts[*]}"
ANSIBLE_CONFIG="$cwd/ansible.cfg" ansible-playbook ${playbook_opts[*]}
echo "✅ [ansible] configured!"
}
command="${1-}"
case $command in
run)
_run_playbook -K "${@:2}"
;;
run_remote)
_run_playbook -Kk -e hosts_var=remote_servers "${@:2}"
;;
dotfiles_link)
_run_playbook --tags "dotfiles" "${@:2}"
;;
dotfiles_unlink)
_run_playbook --tags "dotfiles" -e dotfiles_state=absent "${@:2}"
;;
ansible_deps)
_install_ansible_deps
;;
"" | -h | --help | *)
_usage
;;
esac