From d8867d7ce3b5d83d02d1d81d1ff821d5bb263d85 Mon Sep 17 00:00:00 2001 From: Nikolay Sokolov Date: Mon, 18 Apr 2016 00:10:09 -0700 Subject: [PATCH] Fix duplicate host with different uuid created after add_host If add_host is performed with hostname existing in inventory, but not yet accessed and put in inventory cache, additional host with same hostname and different uuid is created, causing patterns to misbehave. --- lib/ansible/plugins/strategy/__init__.py | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/lib/ansible/plugins/strategy/__init__.py b/lib/ansible/plugins/strategy/__init__.py index f06d4f6f755..64decb0fad5 100644 --- a/lib/ansible/plugins/strategy/__init__.py +++ b/lib/ansible/plugins/strategy/__init__.py @@ -399,10 +399,9 @@ class StrategyBase: host_name = host_info.get('host_name') - # Check if host in cache, add if not - if host_name in self._inventory._hosts_cache: - new_host = self._inventory._hosts_cache[host_name] - else: + # Check if host in inventory, add if not + new_host = self._inventory.get_host(host_name) + if not new_host: new_host = Host(name=host_name) self._inventory._hosts_cache[host_name] = new_host