From aaac5ade66fb3345bcb6f3c3a979d596c91c602e Mon Sep 17 00:00:00 2001 From: Guido Günther Date: Fri, 5 Aug 2016 16:52:55 +0200 Subject: Allow to disable fact cache This brings down inventory generation by about 50% and I doubt lots of people use it to fetch facts from other hosts. --- foreman_ansible_inventory.py | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) (limited to 'foreman_ansible_inventory.py') diff --git a/foreman_ansible_inventory.py b/foreman_ansible_inventory.py index bba2cdd..e42aeb3 100755 --- a/foreman_ansible_inventory.py +++ b/foreman_ansible_inventory.py @@ -68,8 +68,10 @@ class ForemanInventory(object): self.inventory['_meta']['hostvars'][hostname] = { 'foreman': self.cache[hostname], 'foreman_params': self.params[hostname], - 'foreman_facts': self.facts[hostname], } + if self.want_facts: + self.inventory['_meta']['hostvars'][hostname]['foreman_facts'] = self.facts[hostname] + data_to_print += self.json_format_dict(self.inventory, True) print(data_to_print) @@ -121,6 +123,11 @@ class ForemanInventory(object): except (ConfigParser.NoOptionError, ConfigParser.NoSectionError): self.group_prefix = "foreman_" + try: + self.want_facts = config.getboolean('ansible', 'want_facts') + except (ConfigParser.NoOptionError, ConfigParser.NoSectionError): + self.want_facts = True + # Cache related try: cache_path = os.path.expanduser(config.get('cache', 'path')) @@ -200,6 +207,9 @@ class ForemanInventory(object): """ Fetch all host facts of the host """ + if not self.want_facts: + return {} + ret = self._get_facts_by_id(host['id']) if len(ret.values()) == 0: facts = {} @@ -293,7 +303,8 @@ class ForemanInventory(object): def load_facts_from_cache(self): """ Reads the index from the cache file sets self.index """ - + if not self.want_facts: + return cache = open(self.cache_path_facts, 'r') json_facts = cache.read() self.facts = json.loads(json_facts) -- cgit v1.2.3