openstack-ansible/scripts/add-compute.sh
Dmitriy Rabotyagov 49b268634a Do not fail add-compute.sh script if exit code is 4
Right now exit code 4 stands for hosts being unreachable [1], that might
take place in envoronments at the moment of adding new computes

So instead of failing the script and asking for user to re-run commands
manually we silently proceed when anything fails with unreachable hosts.

[1] 74f6e6a134/lib/ansible/executor/task_queue_manager.py (L128C5-L128C26)

Change-Id: Ib422f181256a67cbde4b485c1f1e9079d0400faf
2023-10-18 12:28:31 +02:00

88 lines
3.1 KiB
Bash
Executable File

#!/usr/bin/env bash
# Copyright 2020, VEXXHOST, Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
export OSA_REPO_PATH=${OSA_REPO_PATH:-"/opt/openstack-ansible"}
export HOSTS=${1:-""}
function define_tasks {
if [[ ! -z ${PRE_OSA_TASKS} ]]; then
if [ "${BASH_VERSINFO[0]}" -ge 4 ] && [ "${BASH_VERSINFO[1]}" -ge 4 ]; then
readarray -td";" PRE_TASKS <<<"$PRE_OSA_TASKS"
else
readarray -t PRE_TASKS <<<"$(echo "$PRE_OSA_TASKS" | tr ';' '\n')"
fi
for i in ${!PRE_TASKS[@]}; do
RUN_TASKS+=("${PRE_TASKS[$i]}")
done
fi
RUN_TASKS+=("${OSA_REPO_PATH}/playbooks/setup-hosts.yml --limit ${HOSTS}")
RUN_TASKS+=("${OSA_REPO_PATH}/playbooks/openstack-hosts-setup.yml -e openstack_hosts_group=nova_compute --tags openstack_hosts-file")
RUN_TASKS+=("${OSA_REPO_PATH}/playbooks/setup-openstack.yml --limit ${HOSTS}")
RUN_TASKS+=("${OSA_REPO_PATH}/playbooks/unbound-install.yml --tags unbound-config")
if [[ ! -z ${POST_OSA_TASKS} ]]; then
if [ "${BASH_VERSINFO[0]}" -ge 4 ] && [ "${BASH_VERSINFO[1]}" -ge 4 ]; then
readarray -td";" POST_TASKS <<<"$POST_OSA_TASKS"
else
readarray -t POST_TASKS <<<"$(echo "$POST_OSA_TASKS" | tr ';' '\n')"
fi
for i in ${!POST_TASKS[@]}; do
RUN_TASKS+=("${POST_TASKS[$i]}")
done
fi
}
function run_tasks {
set +e
for item in ${!RUN_TASKS[@]}; do
eval "openstack-ansible ${RUN_TASKS[$item]}"
playbook_status="$?"
if [[ ${playbook_status} -ne 0 && ${playbook_status} -ne 4 ]]; then
echo "*********************** failure ************************"
echo "The compute deployment script has encountered a failure."
echo "Failed on task \"${RUN_TASKS[$item]}\" with status $playbook_status"
echo "Re-run the script, or execute tasks manually:"
for item in $(seq $item $((${#RUN_TASKS[@]} - 1))); do
if [ -n "${RUN_TASKS[$item]}" ]; then
echo "openstack-ansible ${RUN_TASKS[$item]}"
fi
done
echo "*********************** failure ************************"
exit ${playbook_status}
# else
# echo "task ${RUN_TASKS[$item]} ran successfully"
fi
done
set -e
}
function main {
if [[ -z ${HOSTS} ]]; then
echo "Hosts to setup are not provided"
exit 1
elif [[ ! -d ${OSA_REPO_PATH} ]]; then
echo "OSA repo is not found: ${OSA_REPO_PATH}. Define OSA_REPO_PATH to set another directory"
exit 1
fi
define_tasks
run_tasks
}
main