From 01bf8747778f3fed9554d864bc854df7b523b6bf Mon Sep 17 00:00:00 2001
From: Andrew Butcher <abutcher@redhat.com>
Date: Mon, 27 Nov 2017 13:48:24 -0500
Subject: Fix openshift_env fact creation within openshift_facts.

---
 roles/openshift_facts/library/openshift_facts.py | 25 ++++++++++++++++++------
 1 file changed, 19 insertions(+), 6 deletions(-)

(limited to 'roles')

diff --git a/roles/openshift_facts/library/openshift_facts.py b/roles/openshift_facts/library/openshift_facts.py
index f94e0e097..3c121877a 100755
--- a/roles/openshift_facts/library/openshift_facts.py
+++ b/roles/openshift_facts/library/openshift_facts.py
@@ -2253,14 +2253,27 @@ class OpenShiftFacts(object):
                 oo_env_facts = dict()
                 current_level = oo_env_facts
                 keys = self.split_openshift_env_fact_keys(fact, openshift_env_structures)[1:]
+
                 if len(keys) > 0 and keys[0] != self.role:
                     continue
-                for key in keys:
-                    if key == keys[-1]:
-                        current_level[key] = value
-                    elif key not in current_level:
-                        current_level[key] = dict()
-                        current_level = current_level[key]
+
+                # Build a dictionary from the split fact keys.
+                # After this loop oo_env_facts is the resultant dictionary.
+                # For example:
+                # fact = "openshift_metrics_install_metrics"
+                # value = 'true'
+                # keys = ['metrics', 'install', 'metrics']
+                # result = {'metrics': {'install': {'metrics': 'true'}}}
+                for i, _ in enumerate(keys):
+                    # This is the last key. Set the value.
+                    if i == (len(keys) - 1):
+                        current_level[keys[i]] = value
+                    # This is a key other than the last key. Set as
+                    # dictionary and continue.
+                    else:
+                        current_level[keys[i]] = dict()
+                        current_level = current_level[keys[i]]
+
                 facts_to_set = merge_facts(orig=facts_to_set,
                                            new=oo_env_facts,
                                            additive_facts_to_overwrite=[],
-- 
cgit v1.2.3