Merge pull request #526 from Jmainguy/centos5_hostname
Fixed hostname for rhel5 python 2.4.3
This commit is contained in:
commit
07989f1f49
1 changed files with 20 additions and 18 deletions
|
@ -298,13 +298,14 @@ class OpenRCStrategy(GenericStrategy):
|
|||
|
||||
def get_permanent_hostname(self):
|
||||
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))
|
||||
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()
|
||||
|
||||
|
@ -312,19 +313,20 @@ class OpenRCStrategy(GenericStrategy):
|
|||
|
||||
def set_permanent_hostname(self, name):
|
||||
try:
|
||||
f = open(self.HOSTNAME_FILE, 'r')
|
||||
lines = [x.strip() for x in f]
|
||||
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()
|
||||
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))
|
||||
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()
|
||||
|
||||
|
|
Loading…
Reference in a new issue