Browse code

Remove duplicates from host list *before* caching it

Ansible previously added hosts to the host list multiple times for commands
like `ansible -i 'localhost,' -c local -m ping 'localhost,localhost'
--list-hosts`.
8d5f36a fixed the obvious error, but still added the un-deduplicated list to a
cache, so all future invocations of get_hosts() would retrieve a
non-deduplicated list.
This caused problems down the line: For some reason, Ansible only ever
schedules "flush_handlers" tasks (instead of scheduling any actual tasks from
the playbook) for hosts that are contained in the host lists multiple times.
This probably happens because the host states are stored in a dictionary
indexed by the hostnames, so duplicate hostname would cause the state to be
overwritten by subsequent invocations of … something.

Nils Steinger authored on 2015/12/05 23:28:37
Showing 1 changed files
... ...
@@ -195,8 +195,8 @@ class Inventory(object):
195 195
             if self._restriction is not None:
196 196
                 hosts = [ h for h in hosts if h in self._restriction ]
197 197
 
198
-        HOSTS_PATTERNS_CACHE[pattern_hash] = hosts[:]
199
-        return list(set(hosts))
198
+        HOSTS_PATTERNS_CACHE[pattern_hash] = list(set(hosts))
199
+        return HOSTS_PATTERNS_CACHE[pattern_hash][:]
200 200
 
201 201
     @classmethod
202 202
     def split_host_pattern(cls, pattern):