mirror of
https://github.com/ansible-collections/community.general.git
synced 2024-09-14 20:13:21 +02:00
parent
4c93b5dab6
commit
2ad9c6c9e5
1 changed files with 62 additions and 0 deletions
|
@ -399,6 +399,57 @@ class SolarisStrategy(GenericStrategy):
|
|||
|
||||
# ===========================================
|
||||
|
||||
class FreeBSDStrategy(GenericStrategy):
|
||||
"""
|
||||
This is a FreeBSD hostname manipulation strategy class - it edits
|
||||
the /etc/rc.conf.d/hostname file.
|
||||
"""
|
||||
|
||||
HOSTNAME_FILE = '/etc/rc.conf.d/hostname'
|
||||
|
||||
def get_permanent_hostname(self):
|
||||
|
||||
if not os.path.isfile(self.HOSTNAME_FILE):
|
||||
try:
|
||||
open(self.HOSTNAME_FILE, "a").write("hostname=temporarystub\n")
|
||||
except IOError, err:
|
||||
self.module.fail_json(msg="failed to write file: %s" %
|
||||
str(err))
|
||||
try:
|
||||
try:
|
||||
f = open(self.HOSTNAME_FILE, 'r')
|
||||
for line in f:
|
||||
line = line.strip()
|
||||
if line.startswith('hostname='):
|
||||
return line[10:].strip('"')
|
||||
except Exception, err:
|
||||
self.module.fail_json(msg="failed to read hostname: %s" % str(err))
|
||||
finally:
|
||||
f.close()
|
||||
|
||||
return None
|
||||
|
||||
def set_permanent_hostname(self, name):
|
||||
try:
|
||||
try:
|
||||
f = open(self.HOSTNAME_FILE, 'r')
|
||||
lines = [x.strip() for x in f]
|
||||
|
||||
for i, line in enumerate(lines):
|
||||
if line.startswith('hostname='):
|
||||
lines[i] = 'hostname="%s"' % name
|
||||
break
|
||||
f.close()
|
||||
|
||||
f = open(self.HOSTNAME_FILE, 'w')
|
||||
f.write('\n'.join(lines) + '\n')
|
||||
except Exception, err:
|
||||
self.module.fail_json(msg="failed to update hostname: %s" % str(err))
|
||||
finally:
|
||||
f.close()
|
||||
|
||||
# ===========================================
|
||||
|
||||
class FedoraHostname(Hostname):
|
||||
platform = 'Linux'
|
||||
distribution = 'Fedora'
|
||||
|
@ -527,6 +578,17 @@ class OpenBSDHostname(Hostname):
|
|||
distribution = None
|
||||
strategy_class = OpenBSDStrategy
|
||||
|
||||
class SolarisHostname(Hostname):
|
||||
platform = 'SunOS'
|
||||
distribution = None
|
||||
strategy_class = SolarisStrategy
|
||||
|
||||
class FreeBSDHostname(Hostname):
|
||||
platform = 'FreeBSD'
|
||||
distribution = None
|
||||
strategy_class = FreeBSDStrategy
|
||||
|
||||
|
||||
# ===========================================
|
||||
|
||||
def main():
|
||||
|
|
Loading…
Add table
Reference in a new issue