aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--foreman.ini2
-rwxr-xr-xforeman_ansible_inventory.py15
2 files changed, 15 insertions, 2 deletions
diff --git a/foreman.ini b/foreman.ini
index fb103a8..42312da 100644
--- a/foreman.ini
+++ b/foreman.ini
@@ -10,6 +10,8 @@ group_patterns = ["{app}-{tier}-{color}",
"{app}",
"{tier}"]
group_prefix = foreman_
+# Whether to fetch facts from Foreman and store them on the host
+want_facts = True
[cache]
path = .
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)