-
Notifications
You must be signed in to change notification settings - Fork 3
/
bootstrap-users.sh
executable file
·73 lines (62 loc) · 1.74 KB
/
bootstrap-users.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
67
68
69
70
71
72
73
#!/usr/bin/env bash
ANSIBLE_PLAYBOOK="run-remote.sh ansible-playbook"
PATH="${PATH}:."
usage() {
# reset
echo "" 1>&2
echo "Usage: ${0} node_name" 1>&2
echo " node_name: name of the node to bootstrap the setup for the users and user env" 1>&2
echo "" 1>&2
echo " Examples:" 1>&2
echo " ${0} node01" 1>&2
echo " ${0} all" 1>&2
echo "" 1>&2
exit ${1}
}
#if [[ ! $(type -P ${ANSIBLE_PLAYBOOK}) ]] ; then
# echo "${ANSIBLE_PLAYBOOK} must be in PATH"
# echo "${ANSIBLE_PLAYBOOK} not found in PATH=[${PATH}]"
# exit 1
#fi
while getopts "hx" opt; do
case "${opt}" in
h) usage 1 ;;
x) debug_container=1 ;;
\?) usage 2 ;;
:)
echo "Option -$OPTARG requires an argument." >&2
usage 3
;;
*)
usage 4
;;
esac
done
shift $((OPTIND-1))
if [ $# -lt 1 ]; then
echo "required node_name not specified" >&2
usage 5
fi
node_name=$1
ask_pass_opts="--ask-pass --ask-become-pass"
ansible_extra_vars=""
## ref: https://stackoverflow.com/questions/37004686/how-to-pass-a-user-password-in-ansible-command
if [[ ! -z ${ANSIBLE_SSH_PASSWORD} ]] ; then
ansible_extra_vars=" --extra-vars ansible_password=${ANSIBLE_SSH_PASSWORD}"
ask_pass_opts=""
fi
if [[ ! -z ${ANSIBLE_BECOME_PASSWORD} ]] ; then
ansible_extra_vars=" --extra-vars ansible_become_password=${ANSIBLE_BECOME_PASSWORD}"
ask_pass_opts=""
fi
#DEBUG_VERBOSITY="-v"
DEBUG_VERBOSITY="-vvvv"
ANSIBLE_COMMAND="${ANSIBLE_PLAYBOOK} ${DEBUG_VERBOSITY} site.yml --tags bootstrap-user ${ask_pass_opts} ${ansible_extra_vars}"
case "${node_name}" in
"all")
${ANSIBLE_COMMAND}
;;
*)
${ANSIBLE_COMMAND} --limit ${node_name}
;;
esac