From 5bb4ee0c1e90dfa1e9be9f15c4345b46ae3823e0 Mon Sep 17 00:00:00 2001 From: jctanner Date: Thu, 19 May 2016 22:34:19 -0400 Subject: [PATCH] Avoid duplicate system related fact calls. (#15716) * Avoid duplicate system related fact calls. Addresses #1461 --- lib/ansible/module_utils/facts.py | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/lib/ansible/module_utils/facts.py b/lib/ansible/module_utils/facts.py index 8113f5ecba9..96e6b49895f 100644 --- a/lib/ansible/module_utils/facts.py +++ b/lib/ansible/module_utils/facts.py @@ -170,10 +170,13 @@ class Facts(object): { 'path' : '/usr/local/sbin/pkg', 'name' : 'pkgng' }, ] - def __init__(self, module, load_on_init=True): + def __init__(self, module, load_on_init=True, cached_facts=None): self.module = module - self.facts = {} + if not cached_facts: + self.facts = {} + else: + self.facts = cached_facts ### TODO: Eventually, these should all get moved to populate(). But # some of the values are currently being used by other subclasses (for # instance, os_family and distribution). Have to sort out what to do @@ -3180,7 +3183,9 @@ def ansible_facts(module, gather_subset): facts['gather_subset'] = list(gather_subset) facts.update(Facts(module).populate()) for subset in gather_subset: - facts.update(FACT_SUBSETS[subset](module).populate()) + facts.update(FACT_SUBSETS[subset](module, + load_on_init=False, + cached_facts=facts).populate()) return facts def get_all_facts(module):