diff --git a/home/bin/deboco b/home/bin/deboco index 476282a..d9163b2 100755 --- a/home/bin/deboco +++ b/home/bin/deboco @@ -212,6 +212,31 @@ controller__check_integrity() popd } +controller__log_message_to_machine() +{ + local configured_machine_fqdn="$1" + local message_type="$2" # debug, info, warning, error + local message="$3" + + local deboco_log_file_path='/var/log/ipr/deboco.log' + local deboco_log_dir_path="$(dirname /var/log/ipr/deboco.log)" + local line="$(date --iso=seconds) [${message_type}] ${message}" + local commands="mkdir -p ${deboco_log_dir_path} && echo '${line}' >> ${deboco_log_file_path}" + ssh root@${configured_machine_fqdn} "$commands" +} + +controller__log_controller_state_to_machine() +{ + local debops_controller_path="$1" + local configured_machine_fqdn="$2" + + controller__log_message_to_machine "${configured_machine_fqdn}" 'info' "controller : $(whoami)@$(hostname --fqdn):${debops_controller_path}" + pushd $(controller__get_local_repos_path "$debops_controller_path") > /dev/null + local latest_commit_hash=$(git log -n 1 --pretty=format:"%H") + controller__log_message_to_machine "${configured_machine_fqdn}" 'info' "ansible.debops.git version : ${latest_commit_hash}" + popd +} + deboco__init() { local debops_controller_path="$1" @@ -372,6 +397,9 @@ deboco__configure_machine() debops_controller_path=$(realpath $debops_controller_path) log 'info' "configuring $target_host_fqdn using debobs controller $debops_controller_path" + controller__log_message_to_machine "${target_host_fqdn}" 'info' "deboco__configure_machine start" + controller__log_controller_state_to_machine "${debops_controller_path}" "${target_host_fqdn}" + local error_code=$RETURNCODE_SUCCESS deboco__init_machine "$debops_controller_path" "$target_host_fqdn" @@ -381,13 +409,17 @@ deboco__configure_machine() if [ $? != 0 ] then log 'error' "update_machine failed" + controller__log_message_to_machine "${target_host_fqdn}" 'error' "update_machine failed" error_code=$RETURNCODE_ERROR fi else log 'error' "init_machine failed" + controller__log_message_to_machine "${target_host_fqdn}" 'error' "init_machine failed" error_code=$RETURNCODE_ERROR fi + controller__log_message_to_machine "${target_host_fqdn}" 'info' "deboco__configure_machine end" + return "$error_code" } @@ -399,6 +431,8 @@ deboco__init_machine() debops_controller_path=$(realpath $debops_controller_path) log 'info' "installing debops bootstrap on $target_host_fqdn using debobs controller $debops_controller_path" + controller__log_message_to_machine "${target_host_fqdn}" 'info' "deboco__init_machine start" + controller__log_controller_state_to_machine "${debops_controller_path}" "${target_host_fqdn}" controller__check_integrity "$debops_controller_path" if [ $? != "$RETURNCODE_SUCCESS" ] @@ -432,6 +466,8 @@ deboco__init_machine() fi deactivate popd + + controller__log_message_to_machine "${target_host_fqdn}" 'info' "deboco__init_machine end" return "$error_code" } @@ -442,6 +478,10 @@ deboco__update_machine() debops_controller_path=$(realpath $debops_controller_path) log 'info' "updating $target_host_fqdn using debobs controller $debops_controller_path" + controller__log_message_to_machine "${target_host_fqdn}" 'info' "deboco__update_machine start" + controller__log_controller_state_to_machine "${debops_controller_path}" "${target_host_fqdn}" + + controller__check_integrity "$debops_controller_path" if [ $? != "$RETURNCODE_SUCCESS" ] @@ -478,6 +518,9 @@ deboco__update_machine() fi deactivate popd + + controller__log_message_to_machine "${target_host_fqdn}" 'info' "deboco__update_machine end" + return "$error_code" }