From ceff3b6ba30417715dce62036076872b2f4c7a7e Mon Sep 17 00:00:00 2001 From: James Cammarata Date: Thu, 8 Aug 2013 21:08:46 -0500 Subject: [PATCH] Minor modification to set_fact with_items patch Previous patch was reverted due to the fact that there was an issue with the results not always being a dictionary (they're sometimes a unicode string, ie. when the with_items is used with yum). This minor change corrects that by checking for a dict object. --- lib/ansible/playbook/__init__.py | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/lib/ansible/playbook/__init__.py b/lib/ansible/playbook/__init__.py index 716ac597b1..15ac998fd1 100644 --- a/lib/ansible/playbook/__init__.py +++ b/lib/ansible/playbook/__init__.py @@ -361,8 +361,16 @@ class PlayBook(object): # add facts to the global setup cache for host, result in contacted.iteritems(): - facts = result.get('ansible_facts', {}) - self.SETUP_CACHE[host].update(facts) + if 'results' in result: + # task ran with_ lookup plugin, so facts are encapsulated in + # multiple list items in the results key + for res in result['results']: + if type(res) == dict: + facts = res.get('ansible_facts', {}) + self.SETUP_CACHE[host].update(facts) + else: + facts = result.get('ansible_facts', {}) + self.SETUP_CACHE[host].update(facts) # extra vars need to always trump - so update again following the facts self.SETUP_CACHE[host].update(self.extra_vars) if task.register: