restored the init_machine command, as it can be useful

deboco also now prints the debops error code
This commit is contained in:
Guillaume Raffy 2023-12-05 13:38:09 +01:00
parent 161fe8ea80
commit bcf8310c59
1 changed files with 45 additions and 17 deletions

View File

@ -218,7 +218,33 @@ deboco__configure_machine()
{ {
local debops_controller_path="$1" local debops_controller_path="$1"
local target_host_fqdn="$2" # the machine on which we want to install debops bootstrap, eg alambix-108.ipr.univ-rennes.fr local target_host_fqdn="$2" # the machine on which we want to install debops bootstrap, eg alambix-108.ipr.univ-rennes.fr
log 'info' "configuring $machine_fqdn using debobs controller $debops_controller_path" log 'info' "configuring $target_host_fqdn using debobs controller $debops_controller_path"
local error_code=$RETURNCODE_SUCCESS
deboco__init_machine "$debops_controller_path" "$target_host_fqdn"
if [ $? = 0 ]
then
deboco__update_machine "$debops_controller_path" "$target_host_fqdn"
if [ $? != 0 ]
then
log 'error' "update_machine failed"
error_code=$RETURNCODE_ERROR
fi
else
log 'error' "init_machine failed"
error_code=$RETURNCODE_ERROR
fi
return "$error_code"
}
deboco__init_machine()
{
local debops_controller_path="$1"
local target_host_fqdn="$2" # the machine on which we want to install debops bootstrap, eg alambix-108.ipr.univ-rennes.fr
log 'info' "installing debops bootstrap on $target_host_fqdn using debobs controller $debops_controller_path"
local error_code=$RETURNCODE_SUCCESS local error_code=$RETURNCODE_SUCCESS
@ -229,22 +255,17 @@ deboco__configure_machine()
local local_repos_path=$(controller__get_local_repos_path "$debops_controller_path") local local_repos_path=$(controller__get_local_repos_path "$debops_controller_path")
local virtual_env_path=$(controller__get_virtualenv_path "$debops_controller_path") local virtual_env_path=$(controller__get_virtualenv_path "$debops_controller_path")
local debops_exit_code=''
pushd "$local_repos_path" pushd "$local_repos_path"
source "$virtual_env_path/bin/activate" source "$virtual_env_path/bin/activate"
ANS_HOST=$(echo ${target_host_fqdn} | sed -E 's/\.univ-rennes[1]?\.fr$//') ANS_HOST=$(echo ${target_host_fqdn} | sed -E 's/\.univ-rennes[1]?\.fr$//')
log 'debug' "ANS_HOST=${ANS_HOST}" log 'debug' "ANS_HOST=${ANS_HOST}"
debops run bootstrap-ldap -l "${ANS_HOST:-/dev/null}" | tee --append ${report_file_path} debops run bootstrap-ldap -l "${ANS_HOST:-/dev/null}" | tee --append ${report_file_path}
if [ $? = "$RETURNCODE_SUCCESS" ] debops_exit_code=$?
echo "return code for debops run bootstrap-ldap -l ${ANS_HOST:-/dev/null} : $debops_exit_code" >> "${report_file_path}"
log 'debug' "debops_exit_code=$debops_exit_code"
if [ "$debops_exit_code" != "$RETURNCODE_SUCCESS" ]
then then
log 'info' "debops bootstrap installed successfully. Now applying the configuration on ${target_host_fqdn}"
debops run site --limit "${ANS_HOST:-/dev/null}" | tee --append ${report_file_path}
if [ $? != "$RETURNCODE_SUCCESS" ]
then
log 'error' 'debops run site failed'
error_code="$RETURNCODE_ERROR"
fi
else
log 'error' 'debops run bootstrap-ldap failed' log 'error' 'debops run bootstrap-ldap failed'
error_code="$RETURNCODE_ERROR" error_code="$RETURNCODE_ERROR"
fi fi
@ -256,8 +277,8 @@ deboco__configure_machine()
deboco__update_machine() deboco__update_machine()
{ {
local debops_controller_path="$1" local debops_controller_path="$1"
local machine_fqdn="$2" # eg alambix-108.ipr.univ-rennes.fr local target_host_fqdn="$2" # eg alambix-108.ipr.univ-rennes.fr
log 'info' "updating $machine_fqdn using debobs controller $debops_controller_path" log 'info' "updating $target_host_fqdn using debobs controller $debops_controller_path"
local error_code=$RETURNCODE_SUCCESS local error_code=$RETURNCODE_SUCCESS
@ -268,13 +289,16 @@ deboco__update_machine()
local local_repos_path=$(controller__get_local_repos_path "$debops_controller_path") local local_repos_path=$(controller__get_local_repos_path "$debops_controller_path")
local virtual_env_path=$(controller__get_virtualenv_path "$debops_controller_path") local virtual_env_path=$(controller__get_virtualenv_path "$debops_controller_path")
local debops_exit_code=''
pushd "$local_repos_path" pushd "$local_repos_path"
source "$virtual_env_path/bin/activate" source "$virtual_env_path/bin/activate"
ANS_HOST=$(echo ${target_host_fqdn} | sed -E 's/\.univ-rennes[1]?\.fr$//') ANS_HOST=$(echo ${target_host_fqdn} | sed -E 's/\.univ-rennes[1]?\.fr$//')
log 'debug' "ANS_HOST=${ANS_HOST}" log 'debug' "ANS_HOST=${ANS_HOST}"
debops run site --limit "${ANS_HOST:-/dev/null}" | tee --append ${report_file_path} debops run site --limit "${ANS_HOST:-/dev/null}" | tee --append ${report_file_path}
if [ $? != "$RETURNCODE_SUCCESS" ] debops_exit_code=$?
echo "return code for debops run site --limit ${ANS_HOST:-/dev/null} : $debops_exit_code" >> "${report_file_path}"
if [ "$debops_exit_code" != "$RETURNCODE_SUCCESS" ]
then then
log 'error' 'debops run site failed' log 'error' 'debops run site failed'
error_code="$RETURNCODE_ERROR" error_code="$RETURNCODE_ERROR"
@ -299,11 +323,15 @@ deboco_print_usage()
echo " update <debobs-controller-path>" echo " update <debobs-controller-path>"
echo " updates the debops controller in <debobs-controller-path>" echo " updates the debops controller in <debobs-controller-path>"
echo echo
echo " configure-machine <debobs-controller-path> <machine-fqdn>" echo " init_machine <debobs-controller-path> <machine-fqdn>"
echo " configures the machine <machine-fqdn> using the debops controller in <debobs-controller-path>" echo " installs debops bootstrap on the machine <machine-fqdn> using the debops controller in <debobs-controller-path>"
echo echo
echo " update-machine <debobs-controller-path> <machine-fqdn>" echo " update_machine <debobs-controller-path> <machine-fqdn>"
echo " updates the machine <machine-fqdn> using the debops controller in <debobs-controller-path>" echo " updates the machine <machine-fqdn> using the debops controller in <debobs-controller-path>"
echo
echo " configure_machine <debobs-controller-path> <machine-fqdn>"
echo " configures the machine <machine-fqdn> using the debops controller in <debobs-controller-path>". Equivivalent to a init_machine followed by update_machine
echo
} }
deboco() deboco()