diff options
author | jctanner <tanner.jc@gmail.com> | 2013-12-09 06:51:52 -0800 |
---|---|---|
committer | James Tanner <tanner.jc@gmail.com> | 2013-12-18 20:25:16 -0500 |
commit | 06e52f34a77485e7426997db081300e28d96d039 (patch) | |
tree | b89e9dd67ea3d8f9096d05d743b19822c8ad7207 | |
parent | a5e2fae2b3a22fe9b0108f392e9acf5bf75f85c1 (diff) | |
download | ansible-06e52f34a77485e7426997db081300e28d96d039.tar.gz |
Merge pull request #5215 from dhml/devel
Fix issue #5214: hostname persistence on RedHat/CentOS
-rw-r--r-- | library/system/hostname | 4 |
1 files changed, 4 insertions, 0 deletions
diff --git a/library/system/hostname b/library/system/hostname index 04a831bc9d..7ed14d9c8c 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) |