Skip to content

Commit

Permalink
Merge pull request ansible#5215 from dhml/devel
Browse files Browse the repository at this point in the history
Fix issue ansible#5214: hostname persistence on RedHat/CentOS
  • Loading branch information
jctanner committed Dec 19, 2013
1 parent a5e2fae commit 06e52f3
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions library/system/hostname
Original file line number Diff line number Diff line change
Expand Up @@ -203,15 +203,19 @@ class RedHatStrategy(GenericStrategy):
def set_permanent_hostname(self, name):
try:
lines = []
found = False
f = open(self.NETWORK_FILE, 'rb')
try:
for line in f.readlines():
if line.startswith('HOSTNAME'):
lines.append("HOSTNAME=%s\n" % name)
found = True
else:
lines.append(line)
finally:
f.close()
if not found:
lines.append("HOSTNAME=%s\n" % name)
f = open(self.NETWORK_FILE, 'w+')
try:
f.writelines(lines)
Expand Down

0 comments on commit 06e52f3

Please sign in to comment.