From 3c06882dc73a036e936eda3f181fd99b3cbdf361 Mon Sep 17 00:00:00 2001 From: Marek Czernek Date: Thu, 18 Apr 2024 10:24:40 +0200 Subject: [PATCH] Allow explicit reboot on transactional minions --- salt/modules/transactional_update.py | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/salt/modules/transactional_update.py b/salt/modules/transactional_update.py index d6915475f5..4f108e53b9 100644 --- a/salt/modules/transactional_update.py +++ b/salt/modules/transactional_update.py @@ -985,13 +985,30 @@ def call(function, *args, **kwargs): else: return local except ValueError: - return {"result": False, "retcode": 1, "comment": ret_stdout} + local = {"result": False, "retcode": 1, "comment": ret_stdout} + return local finally: # Check if reboot is needed - if activate_transaction and pending_transaction(): + if (activate_transaction and pending_transaction()) or _user_specified_reboot( + local + ): reboot() +def _user_specified_reboot(local): + if not isinstance(local, dict): + # Skip if execution is not state/highstate + return False + + explicit_reboot_cmds = ["reboot", "init 6", "shutdown -r", "shutdown --reboot"] + names = [] + for _, value in local.items(): + if isinstance(value, dict) and "name" in value: + names.append(value["name"]) + # Partial match reboot_cmds to names, so that e.g. "reboot" matches "system.reboot" + return any([cmd in name for cmd in explicit_reboot_cmds for name in names]) + + def apply_(mods=None, **kwargs): """Apply an state inside a transaction.