mirror of
https://github.com/ansible-collections/community.general.git
synced 2024-09-14 20:13:21 +02:00
Port hostname to a py24 and py3 compatible syntax (#3676)
This commit is contained in:
parent
e02f401225
commit
907b3fb667
1 changed files with 32 additions and 16 deletions
|
@ -161,7 +161,8 @@ class DebianStrategy(GenericStrategy):
|
||||||
if not os.path.isfile(self.HOSTNAME_FILE):
|
if not os.path.isfile(self.HOSTNAME_FILE):
|
||||||
try:
|
try:
|
||||||
open(self.HOSTNAME_FILE, "a").write("")
|
open(self.HOSTNAME_FILE, "a").write("")
|
||||||
except IOError, err:
|
except IOError:
|
||||||
|
err = get_exception()
|
||||||
self.module.fail_json(msg="failed to write file: %s" %
|
self.module.fail_json(msg="failed to write file: %s" %
|
||||||
str(err))
|
str(err))
|
||||||
try:
|
try:
|
||||||
|
@ -170,7 +171,8 @@ class DebianStrategy(GenericStrategy):
|
||||||
return f.read().strip()
|
return f.read().strip()
|
||||||
finally:
|
finally:
|
||||||
f.close()
|
f.close()
|
||||||
except Exception, err:
|
except Exception:
|
||||||
|
err = get_exception()
|
||||||
self.module.fail_json(msg="failed to read hostname: %s" %
|
self.module.fail_json(msg="failed to read hostname: %s" %
|
||||||
str(err))
|
str(err))
|
||||||
|
|
||||||
|
@ -181,7 +183,8 @@ class DebianStrategy(GenericStrategy):
|
||||||
f.write("%s\n" % name)
|
f.write("%s\n" % name)
|
||||||
finally:
|
finally:
|
||||||
f.close()
|
f.close()
|
||||||
except Exception, err:
|
except Exception:
|
||||||
|
err = get_exception()
|
||||||
self.module.fail_json(msg="failed to update hostname: %s" %
|
self.module.fail_json(msg="failed to update hostname: %s" %
|
||||||
str(err))
|
str(err))
|
||||||
|
|
||||||
|
@ -198,7 +201,8 @@ class SLESStrategy(GenericStrategy):
|
||||||
if not os.path.isfile(self.HOSTNAME_FILE):
|
if not os.path.isfile(self.HOSTNAME_FILE):
|
||||||
try:
|
try:
|
||||||
open(self.HOSTNAME_FILE, "a").write("")
|
open(self.HOSTNAME_FILE, "a").write("")
|
||||||
except IOError, err:
|
except IOError:
|
||||||
|
err = get_exception()
|
||||||
self.module.fail_json(msg="failed to write file: %s" %
|
self.module.fail_json(msg="failed to write file: %s" %
|
||||||
str(err))
|
str(err))
|
||||||
try:
|
try:
|
||||||
|
@ -207,7 +211,8 @@ class SLESStrategy(GenericStrategy):
|
||||||
return f.read().strip()
|
return f.read().strip()
|
||||||
finally:
|
finally:
|
||||||
f.close()
|
f.close()
|
||||||
except Exception, err:
|
except Exception:
|
||||||
|
err = get_exception()
|
||||||
self.module.fail_json(msg="failed to read hostname: %s" %
|
self.module.fail_json(msg="failed to read hostname: %s" %
|
||||||
str(err))
|
str(err))
|
||||||
|
|
||||||
|
@ -218,7 +223,8 @@ class SLESStrategy(GenericStrategy):
|
||||||
f.write("%s\n" % name)
|
f.write("%s\n" % name)
|
||||||
finally:
|
finally:
|
||||||
f.close()
|
f.close()
|
||||||
except Exception, err:
|
except Exception:
|
||||||
|
err = get_exception()
|
||||||
self.module.fail_json(msg="failed to update hostname: %s" %
|
self.module.fail_json(msg="failed to update hostname: %s" %
|
||||||
str(err))
|
str(err))
|
||||||
|
|
||||||
|
@ -241,7 +247,8 @@ class RedHatStrategy(GenericStrategy):
|
||||||
return v.strip()
|
return v.strip()
|
||||||
finally:
|
finally:
|
||||||
f.close()
|
f.close()
|
||||||
except Exception, err:
|
except Exception:
|
||||||
|
err = get_exception()
|
||||||
self.module.fail_json(msg="failed to read hostname: %s" %
|
self.module.fail_json(msg="failed to read hostname: %s" %
|
||||||
str(err))
|
str(err))
|
||||||
|
|
||||||
|
@ -266,7 +273,8 @@ class RedHatStrategy(GenericStrategy):
|
||||||
f.writelines(lines)
|
f.writelines(lines)
|
||||||
finally:
|
finally:
|
||||||
f.close()
|
f.close()
|
||||||
except Exception, err:
|
except Exception:
|
||||||
|
err = get_exception()
|
||||||
self.module.fail_json(msg="failed to update hostname: %s" %
|
self.module.fail_json(msg="failed to update hostname: %s" %
|
||||||
str(err))
|
str(err))
|
||||||
|
|
||||||
|
@ -337,7 +345,8 @@ class OpenRCStrategy(GenericStrategy):
|
||||||
line = line.strip()
|
line = line.strip()
|
||||||
if line.startswith('hostname='):
|
if line.startswith('hostname='):
|
||||||
return line[10:].strip('"')
|
return line[10:].strip('"')
|
||||||
except Exception, err:
|
except Exception:
|
||||||
|
err = get_exception()
|
||||||
self.module.fail_json(msg="failed to read hostname: %s" % str(err))
|
self.module.fail_json(msg="failed to read hostname: %s" % str(err))
|
||||||
finally:
|
finally:
|
||||||
f.close()
|
f.close()
|
||||||
|
@ -358,7 +367,8 @@ class OpenRCStrategy(GenericStrategy):
|
||||||
|
|
||||||
f = open(self.HOSTNAME_FILE, 'w')
|
f = open(self.HOSTNAME_FILE, 'w')
|
||||||
f.write('\n'.join(lines) + '\n')
|
f.write('\n'.join(lines) + '\n')
|
||||||
except Exception, err:
|
except Exception:
|
||||||
|
err = get_exception()
|
||||||
self.module.fail_json(msg="failed to update hostname: %s" % str(err))
|
self.module.fail_json(msg="failed to update hostname: %s" % str(err))
|
||||||
finally:
|
finally:
|
||||||
f.close()
|
f.close()
|
||||||
|
@ -377,7 +387,8 @@ class OpenBSDStrategy(GenericStrategy):
|
||||||
if not os.path.isfile(self.HOSTNAME_FILE):
|
if not os.path.isfile(self.HOSTNAME_FILE):
|
||||||
try:
|
try:
|
||||||
open(self.HOSTNAME_FILE, "a").write("")
|
open(self.HOSTNAME_FILE, "a").write("")
|
||||||
except IOError, err:
|
except IOError:
|
||||||
|
err = get_exception()
|
||||||
self.module.fail_json(msg="failed to write file: %s" %
|
self.module.fail_json(msg="failed to write file: %s" %
|
||||||
str(err))
|
str(err))
|
||||||
try:
|
try:
|
||||||
|
@ -386,7 +397,8 @@ class OpenBSDStrategy(GenericStrategy):
|
||||||
return f.read().strip()
|
return f.read().strip()
|
||||||
finally:
|
finally:
|
||||||
f.close()
|
f.close()
|
||||||
except Exception, err:
|
except Exception:
|
||||||
|
err = get_exception()
|
||||||
self.module.fail_json(msg="failed to read hostname: %s" %
|
self.module.fail_json(msg="failed to read hostname: %s" %
|
||||||
str(err))
|
str(err))
|
||||||
|
|
||||||
|
@ -397,7 +409,8 @@ class OpenBSDStrategy(GenericStrategy):
|
||||||
f.write("%s\n" % name)
|
f.write("%s\n" % name)
|
||||||
finally:
|
finally:
|
||||||
f.close()
|
f.close()
|
||||||
except Exception, err:
|
except Exception:
|
||||||
|
err = get_exception()
|
||||||
self.module.fail_json(msg="failed to update hostname: %s" %
|
self.module.fail_json(msg="failed to update hostname: %s" %
|
||||||
str(err))
|
str(err))
|
||||||
|
|
||||||
|
@ -449,7 +462,8 @@ class FreeBSDStrategy(GenericStrategy):
|
||||||
if not os.path.isfile(self.HOSTNAME_FILE):
|
if not os.path.isfile(self.HOSTNAME_FILE):
|
||||||
try:
|
try:
|
||||||
open(self.HOSTNAME_FILE, "a").write("hostname=temporarystub\n")
|
open(self.HOSTNAME_FILE, "a").write("hostname=temporarystub\n")
|
||||||
except IOError, err:
|
except IOError:
|
||||||
|
err = get_exception()
|
||||||
self.module.fail_json(msg="failed to write file: %s" %
|
self.module.fail_json(msg="failed to write file: %s" %
|
||||||
str(err))
|
str(err))
|
||||||
try:
|
try:
|
||||||
|
@ -459,7 +473,8 @@ class FreeBSDStrategy(GenericStrategy):
|
||||||
line = line.strip()
|
line = line.strip()
|
||||||
if line.startswith('hostname='):
|
if line.startswith('hostname='):
|
||||||
return line[10:].strip('"')
|
return line[10:].strip('"')
|
||||||
except Exception, err:
|
except Exception:
|
||||||
|
err = get_exception()
|
||||||
self.module.fail_json(msg="failed to read hostname: %s" % str(err))
|
self.module.fail_json(msg="failed to read hostname: %s" % str(err))
|
||||||
finally:
|
finally:
|
||||||
f.close()
|
f.close()
|
||||||
|
@ -480,7 +495,8 @@ class FreeBSDStrategy(GenericStrategy):
|
||||||
|
|
||||||
f = open(self.HOSTNAME_FILE, 'w')
|
f = open(self.HOSTNAME_FILE, 'w')
|
||||||
f.write('\n'.join(lines) + '\n')
|
f.write('\n'.join(lines) + '\n')
|
||||||
except Exception, err:
|
except Exception:
|
||||||
|
err = get_exception()
|
||||||
self.module.fail_json(msg="failed to update hostname: %s" % str(err))
|
self.module.fail_json(msg="failed to update hostname: %s" % str(err))
|
||||||
finally:
|
finally:
|
||||||
f.close()
|
f.close()
|
||||||
|
|
Loading…
Reference in a new issue