]> Frank Brehm's Git Trees - pixelpark/pp-admin-tools.git/commitdiff
Adding output of return value of puppet to scripts/exec-puppet-agent
authorFrank Brehm <frank@brehm-online.com>
Thu, 10 Nov 2022 16:27:37 +0000 (17:27 +0100)
committerFrank Brehm <frank@brehm-online.com>
Thu, 10 Nov 2022 16:27:37 +0000 (17:27 +0100)
scripts/exec-puppet-agent

index 2a07a86d66fe68b2537692d28d029ededbd084ea..b310664f0a89ad60e76c4c2a64217e2519fa9131 100755 (executable)
@@ -13,6 +13,7 @@ CONF_DIR="${BASE_DIR}/etc"
 PUPPET_BASE="/opt/puppetlabs"
 PUPPET_BIN="${PUPPET_BASE}/bin/puppet"
 PUPPET_RUN_LOCK="${PUPPET_BASE}/puppet/cache/state/agent_catalog_run.lock"
+RETVAL="0"
 
 if [[ -f "${BIN_DIR}/functions.rc" ]] ; then
     . "${BIN_DIR}/functions.rc"
@@ -114,10 +115,20 @@ exec_puppet_agent() {
         cmd+=" --noop"
     fi
     debug "Executing: ${cmd}"
+    set +e
     eval ${cmd}
+    RETVAL="$?"
+    set -e
+
+    local rv_color="${RED}"
+    if [[ "${RETVAL}" == 0 ]] ; then
+        rv_color="${CYAN}"
+    elif [[ "${RETVAL}" == "1" || "${RETVAL}" == "2" ]] ; then
+        rv_color="${YELLOW}"
+    fi
 
     empty_line
-    info "${CYAN}Finished${NORMAL}."
+    info "${CYAN}Finished${NORMAL} with return value of ${rv_color}${RETVAL}${NORMAL}."
 }
 
 #------------------------------------------------------------------------------
@@ -130,6 +141,6 @@ main() {
 }
 
 main "$@"
-exit 0
+exit "${RETVAL}"
 
 # vim: et list