From cc3678730c97244efe1e8a2a5b1b0b323a7beb7a Mon Sep 17 00:00:00 2001 From: David Hummel Date: Sat, 7 Dec 2013 21:10:42 -0500 Subject: [PATCH] Fix issue #5214: hostname persistence on RedHat/CentOS --- library/system/hostname | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/library/system/hostname b/library/system/hostname index 0dafdf778d9..9aa7c206a4b 100644 --- a/library/system/hostname +++ b/library/system/hostname @@ -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)