From 504995bda220cb271d080ae569c9186798dabc71 Mon Sep 17 00:00:00 2001 From: Brian Coca Date: Thu, 13 Nov 2014 18:32:27 -0500 Subject: [PATCH] allow fact objects to be instantiated w/o triggering all fact collection this opens the ability to do specific facts at much lower cost. --- lib/ansible/module_utils/facts.py | 31 +++++++++++++++++-------------- 1 file changed, 17 insertions(+), 14 deletions(-) diff --git a/lib/ansible/module_utils/facts.py b/lib/ansible/module_utils/facts.py index 5ceeb405d5..0ad70f61a9 100644 --- a/lib/ansible/module_utils/facts.py +++ b/lib/ansible/module_utils/facts.py @@ -46,7 +46,7 @@ except ImportError: import simplejson as json # -------------------------------------------------------------- -# timeout function to make sure some fact gathering +# timeout function to make sure some fact gathering # steps do not exceed a time limit class TimeoutError(Exception): @@ -118,20 +118,23 @@ class Facts(object): { 'path' : '/usr/bin/pkg', 'name' : 'pkg' }, ] - def __init__(self): + def __init__(self, load_on_init=True): + self.facts = {} - self.get_platform_facts() - self.get_distribution_facts() - self.get_cmdline() - self.get_public_ssh_host_keys() - self.get_selinux_facts() - self.get_fips_facts() - self.get_pkg_mgr_facts() - self.get_lsb_facts() - self.get_date_time_facts() - self.get_user_facts() - self.get_local_facts() - self.get_env_facts() + + if load_on_init: + self.get_platform_facts() + self.get_distribution_facts() + self.get_cmdline() + self.get_public_ssh_host_keys() + self.get_selinux_facts() + self.get_fips_facts() + self.get_pkg_mgr_facts() + self.get_lsb_facts() + self.get_date_time_facts() + self.get_user_facts() + self.get_local_facts() + self.get_env_facts() def populate(self): return self.facts