1
0
Fork 0
mirror of https://github.com/iiab/iiab.git synced 2025-02-12 11:12:06 +00:00
iiab/runrole
2019-11-28 05:28:49 -06:00

84 lines
2.4 KiB
Bash
Executable file

#!/bin/bash
INVENTORY="ansible_hosts"
PLAYBOOK="run-one-role.yml"
ARGS=""
REINSTALL=0
CWD=`pwd`
APPS=/etc/iiab/iiab_state.yml
VARS=/etc/iiab/local_vars.yml
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
if [[ $# -eq 0 ]] ; then
echo " usage: ./runrole <name of role>"
echo " usage: ./runrole --reinstall <name of role>"
echo " Last variable would be full path to log file."
echo " If ommited current directory is used."
exit 0
fi
clear_marker(){
if [ ! $1 == "internetarchive" ]; then # special handling
if [ $1 == "calibre-web" ]; then # role directory & installed marker differ
sed -i -e '/^calibreweb/d' $APPS
elif [ $1 == "captive-portal" ]; then # role directory & installed marker differ
sed -i -e '/^captiveportal/d' $APPS
elif [ $1 == "bluetooth" ]; then # role directory & installed marker differ
sed -i -e '/^pan_bluetooth/d' $APPS
fi
sed -i -e "/^$1/d" $APPS
fi
}
if [ "$1" == "--reinstall" ]; then
ARGS="$ARGS --extra-vars reinstall=True"
REINSTALL=1
shift 1
fi
# Needed for Stages 1-3 if not installed yet
if [ ! -f $IIAB_STATE_FILE ]; then
touch $IIAB_STATE_FILE
fi
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
if [ "$REINSTALL" == "1" ]; then
clear_marker
fi
if [ $# -eq 2 ]; then
export ANSIBLE_LOG_PATH="$2"
else
export ANSIBLE_LOG_PATH="$CWD/iiab-debug.log"
fi
ansible -m setup -i $INVENTORY localhost ${ARGS} --connection=local | grep python
ansible-playbook -i $INVENTORY $PLAYBOOK ${ARGS} --connection=local -e "role_to_run=$1"