-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlocal
executable file
·42 lines (36 loc) · 1.21 KB
/
local
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
#!/bin/sh
set -e
fatal_usage() {
echo "Usage: $0 hostname [options] playbook..."
exit 1
}
# Hack - hostname must be first argument, before ansible-playbook options.
HOST="$1"
[ -n "$HOST" ] || fatal_usage
shift
# This script requires the user to pass the correct hostname.
# The idea is to encourage awareness and reduce accidents.
# Whether this is raelly a good idea may be debatable :).
#
# In case you wonder how I automate setting the hostname, I don't.
# I'm still using manual installers, which prompt you to enter one.
# (Except for nspawn containers. For those, I use a checklist.)
#
# Assumption: Hosts with the same short name are out of scope.
# This is a script for human use, and no-one wants to type in FQDNs.
#
# System hostnames seem not to be set to FQDNs by default.
# If this is wrong, simply replace `hostname` with `hostname -s` below.
LOCALHOST="$(hostname)"
if [ "$HOST" != "$LOCALHOST" ]; then
echo "Error: local hostname is actually '$LOCALHOST'"
fatal_usage
fi
# Run this script with sudo (if sudo is installed).
# It remembers the password, unlike `ansible --ask-become-pass`.
SUDO=
if command -v sudo > /dev/null; then
SUDO=sudo
fi
exec $SUDO \
ansible-playbook -c local --limit "$HOST" "$@"