diff --git a/lib/ansible/modules/system/hostname.py b/lib/ansible/modules/system/hostname.py index 3b67036f08..307a8b687b 100644 --- a/lib/ansible/modules/system/hostname.py +++ b/lib/ansible/modules/system/hostname.py @@ -321,6 +321,44 @@ class OpenRCStrategy(GenericStrategy): # =========================================== +class OpenBSDStrategy(GenericStrategy): + """ + This is a OpenBSD family Hostname manipulation strategy class - it edits + the /etc/myname file. + """ + + HOSTNAME_FILE = '/etc/myname' + + def get_permanent_hostname(self): + if not os.path.isfile(self.HOSTNAME_FILE): + try: + open(self.HOSTNAME_FILE, "a").write("") + except IOError, err: + self.module.fail_json(msg="failed to write file: %s" % + str(err)) + try: + f = open(self.HOSTNAME_FILE) + try: + return f.read().strip() + finally: + f.close() + except Exception, err: + self.module.fail_json(msg="failed to read hostname: %s" % + str(err)) + + def set_permanent_hostname(self, name): + try: + f = open(self.HOSTNAME_FILE, 'w+') + try: + f.write("%s\n" % name) + finally: + f.close() + except Exception, err: + self.module.fail_json(msg="failed to update hostname: %s" % + str(err)) + +# =========================================== + class FedoraHostname(Hostname): platform = 'Linux' distribution = 'Fedora' @@ -430,6 +468,11 @@ class ALTLinuxHostname(Hostname): distribution = 'Altlinux' strategy_class = RedHatStrategy +class OpenBSDHostname(Hostname): + platform = 'OpenBSD' + distribution = None + strategy_class = OpenBSDStrategy + # =========================================== def main():