Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for OpenBSD to the (new) reboot module #46147

Merged
merged 1 commit into from
Sep 28, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 2 additions & 0 deletions changelogs/fragments/reboot_openbsd_support.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
bugfixes:
- reboot - add support for OpenBSD
2 changes: 1 addition & 1 deletion lib/ansible/modules/system/reboot.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
pre_reboot_delay:
description:
- Seconds for shutdown to wait before requesting reboot.
- On Linux and macOS, this is converted to minutes and rounded down. If less than 60, it will be set to 0.
- On Linux, macOS and OpenBSD, this is converted to minutes and rounded down. If less than 60, it will be set to 0.
- On Solaris and FreeBSD, this will be seconds.
default: 0
type: int
Expand Down
16 changes: 14 additions & 2 deletions lib/ansible/plugins/action/reboot.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,18 +42,24 @@ class ActionModule(ActionBase):

DEPRECATED_ARGS = {}

BOOT_TIME_COMMANDS = {
'openbsd': "/sbin/sysctl kern.boottime",
}

SHUTDOWN_COMMANDS = {
'linux': DEFAULT_SHUTDOWN_COMMAND,
'freebsd': DEFAULT_SHUTDOWN_COMMAND,
'sunos': '/usr/sbin/shutdown',
'darwin': '/sbin/shutdown',
'openbsd': DEFAULT_SHUTDOWN_COMMAND,
}

SHUTDOWN_COMMAND_ARGS = {
'linux': '-r {delay_min} "{message}"',
'freebsd': '-r +{delay_sec}s "{message}"',
'sunos': '-y -g {delay_sec} -r "{message}"',
'darwin': '-r +{delay_min_macos} "{message}"'
'darwin': '-r +{delay_min_macos} "{message}"',
'openbsd': '-r +{delay_min} "{message}"',
}

def __init__(self, *args, **kwargs):
Expand Down Expand Up @@ -96,7 +102,13 @@ def construct_command(self):
def get_system_boot_time(self):
stdout = u''
stderr = u''
command_result = self._low_level_execute_command(self.DEFAULT_BOOT_TIME_COMMAND, sudoable=self.DEFAULT_SUDOABLE)

# Determine the system distribution in order to use the correct shutdown command arguments
uname_result = self._low_level_execute_command('uname')
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would have used platform.system rather than uname, but I see that's also what is used in the rest of the code.

Copy link
Contributor

@samdoran samdoran Sep 26, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree. But in order to do that it would end up being self._low_level_execute_command((python -c 'import platform; print(platform.system())') since the action plugin is running on the control node, not the managed node. And that would also need to take into account ansible_python_interpreter on the remote node, further complicating matters.

For 2.8, I want to add proper platform support since how it is today isn't scaling well. The commands and parameters between various *nix distributions varies a lot more than I had hoped.

I have a (very rough) WIP PR #45656 where I welcome your feedback.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Platform is also not present in Python 3.8 i think

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sivel pointed out that platform.system() is not one of the things deprecated in the platform stdlib library. platform.dist() is the main thing that's going away.

distribution = uname_result['stdout'].strip().lower()

boot_time_command = self.BOOT_TIME_COMMANDS.get(distribution, self.DEFAULT_BOOT_TIME_COMMAND)
command_result = self._low_level_execute_command(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
# launched by systemd, the update of utmp/wtmp is not done correctly.
Expand Down