From f4b07b105bffd98b3647a8757bc39517e60ff87f Mon Sep 17 00:00:00 2001 From: Jonathan Mainguy Date: Sun, 17 May 2015 23:42:49 -0400 Subject: [PATCH] added openbsd to hostname module --- lib/ansible/modules/system/hostname.py | 43 ++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) diff --git a/lib/ansible/modules/system/hostname.py b/lib/ansible/modules/system/hostname.py index 3b67036f089..307a8b687be 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():