Extend OpenBSDStrategy to also update current hostname. (#80521)

Fixes #80520
pull/80528/head
Rogier Krieger 2 years ago committed by GitHub
parent 2e62724a8a
commit 6aac0e2460
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -0,0 +1,2 @@
bugfixes:
- The ``hostname`` module now also updates both current and permanent hostname on OpenBSD. Before it only updated the permanent hostname (https://github.com/ansible/ansible/issues/80520).

@ -387,10 +387,29 @@ class OpenRCStrategy(BaseStrategy):
class OpenBSDStrategy(FileStrategy): class OpenBSDStrategy(FileStrategy):
""" """
This is a OpenBSD family Hostname manipulation strategy class - it edits This is a OpenBSD family Hostname manipulation strategy class - it edits
the /etc/myname file. the /etc/myname file for the permanent hostname and executes hostname
command for the current hostname.
""" """
FILE = '/etc/myname' FILE = '/etc/myname'
COMMAND = "hostname"
def __init__(self, module):
super(OpenBSDStrategy, self).__init__(module)
self.hostname_cmd = self.module.get_bin_path(self.COMMAND, True)
def get_current_hostname(self):
cmd = [self.hostname_cmd]
rc, out, err = self.module.run_command(cmd)
if rc != 0:
self.module.fail_json(msg="Command failed rc=%d, out=%s, err=%s" % (rc, out, err))
return to_native(out).strip()
def set_current_hostname(self, name):
cmd = [self.hostname_cmd, name]
rc, out, err = self.module.run_command(cmd)
if rc != 0:
self.module.fail_json(msg="Command failed rc=%d, out=%s, err=%s" % (rc, out, err))
class SolarisStrategy(BaseStrategy): class SolarisStrategy(BaseStrategy):

Loading…
Cancel
Save