-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsetup.sh
42 lines (35 loc) · 1.29 KB
/
setup.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
#!/bin/bash
type -p ansible-playbook > /dev/null
if [ $? -ne 0 ]; then
echo "Oops! I cannot find ansible. Please be sure to install ansible before proceeding."
echo "For guidance on installing ansible, consult http://docs.ansible.com/intro_installation.html."
exit 1
fi
# Allow exit codes to trickle through a pipe
set -o pipefail
TIMESTAMP=$(date --utc +"%F-%T")
LOG_DIR="/var/log/awx"
LOG_FILE="${LOG_DIR}/setup-${TIMESTAMP}.log"
# When using an interactive shell, force colorized ansible output
if [ -t "0" ]; then
ANSIBLE_FORCE_COLOR=True
fi
getopts "e:" EXTRA_ARGS
if [ "$OPTARG" != "" ]; then
echo "Running with extra args: ${OPTARG}"
sudo PYTHONUNBUFFERED=x ANSIBLE_FORCE_COLOR=$ANSIBLE_FORCE_COLOR ANSIBLE_ERROR_ON_UNDEFINED_VARS=True ansible-playbook -i myhosts -c local -v -e "$OPTARG" site.yml | tee setup.log
else
sudo PYTHONUNBUFFERED=x ANSIBLE_FORCE_COLOR=$ANSIBLE_FORCE_COLOR ANSIBLE_ERROR_ON_UNDEFINED_VARS=True ansible-playbook -i myhosts -c local -v site.yml | tee setup.log
fi
RC=$?
if [ ${RC} -ne 0 ]; then
echo "Oops! An error occured while running setup."
else
echo "The setup process completed successfully."
fi
# Save logfile
if [ -d "${LOG_DIR}" ]; then
sudo cp setup.log "${LOG_FILE}"
echo "Setup log saved to ${LOG_FILE}"
fi
exit ${RC}