From bcf8310c592e9567f4b112cbf3117cffbd3f317d Mon Sep 17 00:00:00 2001 From: Guillaume Raffy Date: Tue, 5 Dec 2023 13:38:09 +0100 Subject: [PATCH] restored the init_machine command, as it can be useful deboco also now prints the debops error code --- home/bin/deboco | 62 +++++++++++++++++++++++++++++++++++-------------- 1 file changed, 45 insertions(+), 17 deletions(-) diff --git a/home/bin/deboco b/home/bin/deboco index 16022dc..2669d17 100755 --- a/home/bin/deboco +++ b/home/bin/deboco @@ -218,7 +218,33 @@ deboco__configure_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' "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 @@ -229,22 +255,17 @@ deboco__configure_machine() local local_repos_path=$(controller__get_local_repos_path "$debops_controller_path") local virtual_env_path=$(controller__get_virtualenv_path "$debops_controller_path") - + local debops_exit_code='' pushd "$local_repos_path" source "$virtual_env_path/bin/activate" ANS_HOST=$(echo ${target_host_fqdn} | sed -E 's/\.univ-rennes[1]?\.fr$//') log 'debug' "ANS_HOST=${ANS_HOST}" 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 - 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' error_code="$RETURNCODE_ERROR" fi @@ -256,8 +277,8 @@ deboco__configure_machine() deboco__update_machine() { local debops_controller_path="$1" - local machine_fqdn="$2" # eg alambix-108.ipr.univ-rennes.fr - log 'info' "updating $machine_fqdn using debobs controller $debops_controller_path" + local target_host_fqdn="$2" # eg alambix-108.ipr.univ-rennes.fr + log 'info' "updating $target_host_fqdn using debobs controller $debops_controller_path" 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 virtual_env_path=$(controller__get_virtualenv_path "$debops_controller_path") + local debops_exit_code='' pushd "$local_repos_path" source "$virtual_env_path/bin/activate" ANS_HOST=$(echo ${target_host_fqdn} | sed -E 's/\.univ-rennes[1]?\.fr$//') log 'debug' "ANS_HOST=${ANS_HOST}" 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 log 'error' 'debops run site failed' error_code="$RETURNCODE_ERROR" @@ -299,11 +323,15 @@ deboco_print_usage() echo " update " echo " updates the debops controller in " echo - echo " configure-machine " - echo " configures the machine using the debops controller in " + echo " init_machine " + echo " installs debops bootstrap on the machine using the debops controller in " echo - echo " update-machine " + echo " update_machine " echo " updates the machine using the debops controller in " + echo + echo " configure_machine " + echo " configures the machine using the debops controller in ". Equivivalent to a init_machine followed by update_machine + echo } deboco()