summaryrefslogtreecommitdiffstats
path: root/ipaserver/install/installutils.py
diff options
context:
space:
mode:
Diffstat (limited to 'ipaserver/install/installutils.py')
-rw-r--r--ipaserver/install/installutils.py19
1 files changed, 14 insertions, 5 deletions
diff --git a/ipaserver/install/installutils.py b/ipaserver/install/installutils.py
index 563333bd..9f4bd615 100644
--- a/ipaserver/install/installutils.py
+++ b/ipaserver/install/installutils.py
@@ -159,13 +159,22 @@ def verify_ip_address(ip):
def record_in_hosts(ip, host_name, file="/etc/hosts"):
hosts = open(file, 'r').readlines()
for line in hosts:
- hosts_ip = line.split()[0]
- if hosts_ip != ip:
+ line = line.rstrip('\n')
+ fields = line.partition('#')[0].split()
+ if len(fields) == 0:
continue
- names = line.split()[1:]
- if host_name in names:
- return True
+ try:
+ hosts_ip = fields[0]
+ names = fields[1:]
+
+ if hosts_ip != ip:
+ continue
+ if host_name in names:
+ return True
+ except IndexError:
+ print "Warning: Erroneous line '%s' in %s" % (line, file)
+ continue
return False