2018-04-03 15:55:36 +00:00
|
|
|
#!/bin/bash
|
|
|
|
|
2019-10-25 01:05:47 +00:00
|
|
|
INVENTORY=ansible_hosts
|
|
|
|
PLAYBOOK=run-one-role.yml
|
2019-08-10 20:53:56 +00:00
|
|
|
ARGS=""
|
2019-10-17 14:04:12 +00:00
|
|
|
REINSTALL=0
|
2018-04-03 15:55:36 +00:00
|
|
|
CWD=`pwd`
|
2019-10-25 01:05:47 +00:00
|
|
|
IIAB_STATE_FILE=/etc/iiab/iiab_state.yml
|
|
|
|
LOCAL_VARS_FILE=/etc/iiab/local_vars.yml
|
2020-02-11 21:51:03 +00:00
|
|
|
|
2019-10-16 05:37:37 +00:00
|
|
|
if [ ! -f $PLAYBOOK ]; then
|
|
|
|
echo "Exiting: IIAB Playbook not found."
|
|
|
|
echo "Please run this in /opt/iiab/iiab (top level of the git repo)."
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
2020-04-29 12:15:40 +00:00
|
|
|
if [[ $# -eq 0 ]] || [ "$2" == "--reinstall" ] || [ "$3" == "--reinstall" ] ; then
|
2019-10-25 01:05:47 +00:00
|
|
|
echo "Usage: ./runrole <name of role>"
|
|
|
|
echo "Usage: ./runrole --reinstall <name of role>"
|
|
|
|
echo
|
|
|
|
echo "Optional 2nd parameter is full PATH/FILENAME for logging."
|
|
|
|
echo "If omitted, <current directory>/iiab-debug.log is used."
|
2019-10-16 05:37:37 +00:00
|
|
|
exit 0
|
|
|
|
fi
|
|
|
|
|
2019-11-19 17:34:43 +00:00
|
|
|
if [ "$1" == "--reinstall" ]; then
|
2020-01-05 06:25:14 +00:00
|
|
|
ARGS="$ARGS -e reinstall=True"
|
2019-11-19 17:34:43 +00:00
|
|
|
REINSTALL=1
|
|
|
|
shift 1
|
|
|
|
fi
|
|
|
|
|
2020-01-05 06:25:14 +00:00
|
|
|
#if ! grep -q "^""$1""_install: True" $LOCAL_VARS_FILE; then
|
|
|
|
# echo "ERROR: $LOCAL_VARS_FILE must contain '""$1""_install: True'"
|
|
|
|
# exit 1
|
|
|
|
#fi
|
2019-10-25 01:05:47 +00:00
|
|
|
|
2020-08-05 17:57:58 +00:00
|
|
|
# 2020-08-05: yes /etc/iiab/iiab_state.yml is necessary, but we DON'T
|
|
|
|
# want to encourage sloppy operators to delete/touch this file.
|
|
|
|
#
|
|
|
|
# (The iiab_state.yml file should always be created by ./iiab-install,
|
|
|
|
# for IIAB's Ansible roles that then auto-populate this file.)
|
|
|
|
#
|
2020-08-05 18:20:02 +00:00
|
|
|
# FYI ./iiab-network and ./iiab-configure likewise warn operators (IN RED!)
|
2020-08-05 17:57:58 +00:00
|
|
|
# if they try to run without the existence of /etc/iiab/iiab_state.yml :
|
|
|
|
#
|
|
|
|
# ERROR! vars file /etc/iiab/iiab_state.yml was not found
|
|
|
|
#
|
2019-10-24 16:51:56 +00:00
|
|
|
# Needed for Stages 1-3 if not installed yet
|
2020-08-05 17:57:58 +00:00
|
|
|
#if [ ! -f $IIAB_STATE_FILE ]; then
|
|
|
|
# touch $IIAB_STATE_FILE
|
|
|
|
#fi
|
2019-10-16 15:37:33 +00:00
|
|
|
|
2020-01-05 06:25:14 +00:00
|
|
|
#if ! grep -q $1_install $LOCAL_VARS_FILE; then
|
|
|
|
# echo " $1_install: not found in $VARS"
|
|
|
|
# echo " Please review $VARS and edit as required"
|
|
|
|
# exit 1
|
|
|
|
#elif grep $1_install $LOCAL_VARS_FILE | grep -q --exclude "#" False; then
|
|
|
|
# echo " $1_install: set to False found in $VARS"
|
|
|
|
# echo " Please review $VARS and edit as required"
|
|
|
|
# exit 1
|
|
|
|
#elif grep $1_install $LOCAL_VARS_FILE | grep -q "#"; then
|
|
|
|
# echo " $1_install: commented out (#) in $VARS"
|
|
|
|
# echo " Please review $VARS and edit as required"
|
|
|
|
# exit 1
|
|
|
|
#else
|
|
|
|
# if grep $1_install $LOCAL_VARS_FILE | grep -q --exclude "#" True; then
|
|
|
|
# echo " $1_install: set to True found in $VARS"
|
|
|
|
# echo " continuing...."
|
|
|
|
# else
|
|
|
|
# echo "somthing went wrong to get here"
|
|
|
|
# exit 1
|
|
|
|
# fi
|
|
|
|
#fi
|
2019-10-17 14:04:12 +00:00
|
|
|
|
|
|
|
if [ "$REINSTALL" == "1" ]; then
|
2020-02-11 21:51:03 +00:00
|
|
|
if [ $1 == "calibre-web" ]; then # role directory & installed marker differ
|
|
|
|
sed -i -e '/^calibreweb/d' $IIAB_STATE_FILE
|
|
|
|
elif [ $1 == "httpd" ]; then # role directory & installed marker differ
|
|
|
|
sed -i -e '/^apache/d' $IIAB_STATE_FILE
|
|
|
|
elif [ $1 == "osm-vector-maps" ]; then # role directory & installed marker differ
|
|
|
|
sed -i -e '/^osm_vector_maps/d' $IIAB_STATE_FILE
|
|
|
|
else
|
|
|
|
sed -i -e "/^$1/d" $IIAB_STATE_FILE
|
|
|
|
fi
|
2019-08-10 22:27:39 +00:00
|
|
|
fi
|
2019-08-10 20:53:56 +00:00
|
|
|
|
2019-08-10 22:27:39 +00:00
|
|
|
if [ $# -eq 2 ]; then
|
|
|
|
export ANSIBLE_LOG_PATH="$2"
|
2019-04-14 21:29:56 +00:00
|
|
|
else
|
|
|
|
export ANSIBLE_LOG_PATH="$CWD/iiab-debug.log"
|
|
|
|
fi
|
2018-04-03 15:55:36 +00:00
|
|
|
|
2019-10-31 02:38:06 +00:00
|
|
|
ansible -m setup -i $INVENTORY localhost ${ARGS} --connection=local | grep python
|
|
|
|
ansible-playbook -i $INVENTORY $PLAYBOOK ${ARGS} --connection=local -e "role_to_run=$1"
|