1
0
Fork 0
mirror of https://github.com/ansible-collections/community.general.git synced 2024-09-14 20:13:21 +02:00

win_reboot: display message before rebooting (#19986)

Show a message to users when rebooting the system.

TODO: Look if this message is logged in the EventLog properly, if not,
fix that :-)
This commit is contained in:
Dag Wieers 2017-01-10 22:59:39 +01:00 committed by Matt Davis
parent f928696b5d
commit b7594070b3
2 changed files with 8 additions and 2 deletions

View file

@ -53,6 +53,10 @@ options:
description: description:
- Command to expect success for to determine the machine is ready for management - Command to expect success for to determine the machine is ready for management
default: whoami default: whoami
msg:
description:
- Message to display to users
default: Reboot initiated by Ansible
author: author:
- Matt Davis (@nitzmahone) - Matt Davis (@nitzmahone)
''' '''

View file

@ -45,6 +45,7 @@ class ActionModule(ActionBase):
DEFAULT_CONNECT_TIMEOUT_SEC = 5 DEFAULT_CONNECT_TIMEOUT_SEC = 5
DEFAULT_PRE_REBOOT_DELAY_SEC = 2 DEFAULT_PRE_REBOOT_DELAY_SEC = 2
DEFAULT_TEST_COMMAND = 'whoami' DEFAULT_TEST_COMMAND = 'whoami'
DEFAULT_REBOOT_MESSAGE = 'Reboot initiated by Ansible.'
def do_until_success_or_timeout(self, what, timeout_sec, what_desc, fail_sleep_sec=1): def do_until_success_or_timeout(self, what, timeout_sec, what_desc, fail_sleep_sec=1):
max_end_time = datetime.utcnow() + timedelta(seconds=timeout_sec) max_end_time = datetime.utcnow() + timedelta(seconds=timeout_sec)
@ -70,7 +71,8 @@ class ActionModule(ActionBase):
reboot_timeout_sec = int(self._task.args.get('reboot_timeout_sec', self.DEFAULT_REBOOT_TIMEOUT_SEC)) reboot_timeout_sec = int(self._task.args.get('reboot_timeout_sec', self.DEFAULT_REBOOT_TIMEOUT_SEC))
connect_timeout_sec = int(self._task.args.get('connect_timeout_sec', self.DEFAULT_CONNECT_TIMEOUT_SEC)) connect_timeout_sec = int(self._task.args.get('connect_timeout_sec', self.DEFAULT_CONNECT_TIMEOUT_SEC))
pre_reboot_delay_sec = int(self._task.args.get('pre_reboot_delay_sec', self.DEFAULT_PRE_REBOOT_DELAY_SEC)) pre_reboot_delay_sec = int(self._task.args.get('pre_reboot_delay_sec', self.DEFAULT_PRE_REBOOT_DELAY_SEC))
test_command = self._task.args.get('test_command', self.DEFAULT_TEST_COMMAND) test_command = str(self._task.args.get('test_command', self.DEFAULT_TEST_COMMAND))
msg = str(self._task.args.get('msg', self.DEFAULT_REBOOT_MESSAGE))
if self._play_context.check_mode: if self._play_context.check_mode:
display.vvv("win_reboot: skipping for check_mode") display.vvv("win_reboot: skipping for check_mode")
@ -82,7 +84,7 @@ class ActionModule(ActionBase):
result = super(ActionModule, self).run(tmp, task_vars) result = super(ActionModule, self).run(tmp, task_vars)
# initiate reboot # initiate reboot
(rc, stdout, stderr) = self._connection.exec_command("shutdown /r /t %d" % pre_reboot_delay_sec) (rc, stdout, stderr) = self._connection.exec_command('shutdown /r /t %d /c "%s"' % (pre_reboot_delay_sec, msg))
if rc != 0: if rc != 0:
result['failed'] = True result['failed'] = True