reboot: Fix typo and support bare Linux systems (#45607)

* reboot: Fix typo and support bare Linux systems

This fixes a problem for bare Linux systems that do not support 'who -b' or 'uptime -s'.

* Accumulate stdout and stderr information
pull/45746/head
Dag Wieers 6 years ago committed by Sam Doran
parent 21ff9c6a4a
commit a7a99c5fd4

@ -94,6 +94,8 @@ class ActionModule(ActionBase):
return reboot_command
def get_system_boot_time(self):
stdout = ''
stderr = ''
command_result = self._low_level_execute_command(self.DEFAULT_BOOT_TIME_COMMAND, sudoable=self.DEFAULT_SUDOABLE)
# For single board computers, e.g., Raspberry Pi, that lack a real time clock and are using fake-hwclock
@ -101,11 +103,22 @@ class ActionModule(ActionBase):
# Fall back to using uptime -s for those systems.
# https://github.com/systemd/systemd/issues/6057
if '1970-01-01 00:00' in command_result['stdout']:
stdout += command_result['stdout']
stderr += command_result['stderr']
command_result = self._low_level_execute_command('uptime -s', sudoable=self.DEFAULT_SUDOABLE)
# This is a last resort for bare Linux systems (e.g. OpenELEC) where 'who -b' or 'uptime -s' are not supported.
# Other options like parsing /proc/uptime or default uptime output are less reliable than this
if command_result['rc'] != 0:
stdout += command_result['stdout']
stderr += command_result['stderr']
command_result = self._low_level_execute_command('cat /proc/sys/kernel/random/boot_id', sudoable=self.DEFAULT_SUDOABLE)
if command_result['rc'] != 0:
stdout += command_result['stdout']
stderr += command_result['stderr']
raise AnsibleError("%s: failed to get host boot time info, rc: %d, stdout: %s, stderr: %s"
% (self._task.action, command_result.rc, to_native(command_result['stdout']), to_native(command_result['stderr'])))
% (self._task.action, command_result['rc'], to_native(stdout), to_native(stderr)))
return command_result['stdout'].strip()

Loading…
Cancel
Save