Fixed hostname for rhel5 python 2.4.3
This commit is contained in:
parent
54b836f0b8
commit
541070be4c
1 changed files with 20 additions and 18 deletions
|
@ -298,13 +298,14 @@ class OpenRCStrategy(GenericStrategy):
|
||||||
|
|
||||||
def get_permanent_hostname(self):
|
def get_permanent_hostname(self):
|
||||||
try:
|
try:
|
||||||
f = open(self.HOSTNAME_FILE, 'r')
|
try:
|
||||||
for line in f:
|
f = open(self.HOSTNAME_FILE, 'r')
|
||||||
line = line.strip()
|
for line in f:
|
||||||
if line.startswith('hostname='):
|
line = line.strip()
|
||||||
return line[10:].strip('"')
|
if line.startswith('hostname='):
|
||||||
except Exception, err:
|
return line[10:].strip('"')
|
||||||
self.module.fail_json(msg="failed to read hostname: %s" % str(err))
|
except Exception, err:
|
||||||
|
self.module.fail_json(msg="failed to read hostname: %s" % str(err))
|
||||||
finally:
|
finally:
|
||||||
f.close()
|
f.close()
|
||||||
|
|
||||||
|
@ -312,19 +313,20 @@ class OpenRCStrategy(GenericStrategy):
|
||||||
|
|
||||||
def set_permanent_hostname(self, name):
|
def set_permanent_hostname(self, name):
|
||||||
try:
|
try:
|
||||||
f = open(self.HOSTNAME_FILE, 'r')
|
try:
|
||||||
lines = [x.strip() for x in f]
|
f = open(self.HOSTNAME_FILE, 'r')
|
||||||
|
lines = [x.strip() for x in f]
|
||||||
|
|
||||||
for i, line in enumerate(lines):
|
for i, line in enumerate(lines):
|
||||||
if line.startswith('hostname='):
|
if line.startswith('hostname='):
|
||||||
lines[i] = 'hostname="%s"' % name
|
lines[i] = 'hostname="%s"' % name
|
||||||
break
|
break
|
||||||
f.close()
|
f.close()
|
||||||
|
|
||||||
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:
|
||||||
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