mirror of
https://github.com/ansible-collections/community.general.git
synced 2024-09-14 20:13:21 +02:00
Fix issue #5214: hostname persistence on RedHat/CentOS
This commit is contained in:
parent
fa8a02dcda
commit
cc3678730c
1 changed files with 4 additions and 0 deletions
|
@ -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)
|
||||
|
|
Loading…
Reference in a new issue