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

Fixes #80520
This commit is contained in:
Rogier Krieger
2023-04-14 10:41:44 -04:00
committed by GitHub
parent 2e62724a8a
commit 6aac0e2460
2 changed files with 22 additions and 1 deletions
@@ -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).
+20 -1
View File
@@ -387,10 +387,29 @@ class OpenRCStrategy(BaseStrategy):
class OpenBSDStrategy(FileStrategy):
"""
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'
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):