From 502d9f43e5b151749fd453f105c07b67018d9efe Mon Sep 17 00:00:00 2001 From: Rene Moser Date: Fri, 15 Nov 2013 13:38:32 +0100 Subject: [PATCH 1/4] host: fix changed is not available on fail --- system/host | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/system/host b/system/host index 0ca1de56222..c968360eb62 100644 --- a/system/host +++ b/system/host @@ -167,13 +167,13 @@ def main(): result['state'] = host.state result['changed'] = False - err = host.validate_has_hostname_on_present() - if err: - module.fail_json(msg=err) + result['msg'] = host.validate_has_hostname_on_present() + if result['msg']: + module.fail_json(**result) - err = host.validate_has_ip_or_hostname_on_absent() - if err: - module.fail_json(msg=err) + result['msg'] = host.validate_has_ip_or_hostname_on_absent() + if result['msg']: + module.fail_json(**result) host.proceed_hosts_entries() if host.state == 'present': From ee9dc73a63f7f13fc8f4c302b455687e8bce47a1 Mon Sep 17 00:00:00 2001 From: Rene Moser Date: Fri, 15 Nov 2013 13:40:51 +0100 Subject: [PATCH 2/4] host: skip lines beginning with new line --- system/host | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/system/host b/system/host index c968360eb62..f0daaac861d 100644 --- a/system/host +++ b/system/host @@ -100,7 +100,7 @@ class Host(object): f.close() for lineno, line in enumerate(self._hostsfile_lines): - if line.startswith("#"): + if line.startswith("#") or line.startswith("\n"): continue ip = line.split()[0:1] From 25f527a32db25a1173653ed18fd95415e3e97902 Mon Sep 17 00:00:00 2001 From: Rene Moser Date: Fri, 15 Nov 2013 13:51:18 +0100 Subject: [PATCH 3/4] host: removed unused self_has_aliases --- system/host | 3 --- 1 file changed, 3 deletions(-) diff --git a/system/host b/system/host index f0daaac861d..db37d1da786 100644 --- a/system/host +++ b/system/host @@ -75,7 +75,6 @@ class Host(object): self._ip_matches = False self._hostname_matches = False self._aliases_matches = False - self._has_aliases = False self._found_on_line = -1 def validate_has_hostname_on_present(self): @@ -117,8 +116,6 @@ class Host(object): # only look at aliases if we found hostname or ip if self._hostname_matches or self._ip_matches: - if aliases: - self._has_aliases = True if self.aliases and self.aliases == aliases: self._aliases_matches = True break From b1f27ca902333108dcd7a5f7e976259f5cdc41e0 Mon Sep 17 00:00:00 2001 From: Rene Moser Date: Fri, 15 Nov 2013 14:00:04 +0100 Subject: [PATCH 4/4] host: fix bug, alias was not removed --- system/host | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/system/host b/system/host index db37d1da786..3720ccc1017 100644 --- a/system/host +++ b/system/host @@ -116,14 +116,12 @@ class Host(object): # only look at aliases if we found hostname or ip if self._hostname_matches or self._ip_matches: - if self.aliases and self.aliases == aliases: + if self.aliases == aliases: self._aliases_matches = True break def full_entry_exists(self): - if self.aliases and not self._aliases_matches: - return False - return self._ip_matches and self._hostname_matches + return self._ip_matches and self._hostname_matches and self._aliases_matches def entry_exists(self): return self._ip_matches or self._hostname_matches @@ -154,7 +152,7 @@ def main(): state=dict(default='present', choices=['present', 'absent'], type='str'), ip=dict(default=None, type='str'), hostname=dict(default=None, type='str'), - aliases=dict(default=None, type='str'), + aliases=dict(default='', type='str'), ), supports_check_mode=True )