Browse Source

Merge pull request #1733 from abutcher/hosted-facts

Fix hosted facts
Brenton Leanhardt 9 years ago
parent
commit
64c81e42bb

+ 14 - 0
filter_plugins/oo_filters.py

@@ -57,6 +57,19 @@ class FilterModule(object):
         return [item for sublist in data for item in sublist]
 
     @staticmethod
+    def oo_merge_dicts(first_dict, second_dict):
+        """ Merge two dictionaries where second_dict values take precedence.
+            Ex: first_dict={'a': 1, 'b': 2}
+                second_dict={'b': 3, 'c': 4}
+                returns {'a': 1, 'b': 3, 'c': 4}
+        """
+        if not isinstance(first_dict, dict) or not isinstance(second_dict, dict):
+            raise errors.AnsibleFilterError("|failed expects to merge two dicts")
+        merged = first_dict.copy()
+        merged.update(second_dict)
+        return merged
+
+    @staticmethod
     def oo_collect(data, attribute=None, filters=None):
         """ This takes a list of dict and collects all attributes specified into a
             list. If filter is specified then we will include all items that
@@ -755,4 +768,5 @@ class FilterModule(object):
             "oo_pods_match_component": self.oo_pods_match_component,
             "oo_get_hosts_from_hostvars": self.oo_get_hosts_from_hostvars,
             "oo_image_tag_to_rpm_version": self.oo_image_tag_to_rpm_version,
+            "oo_merge_dicts": self.oo_merge_dicts
         }

+ 3 - 5
roles/openshift_cloud_provider/tasks/main.yml

@@ -2,14 +2,12 @@
 - name: Set cloud provider facts
   openshift_facts:
     role: cloudprovider
-    openshift_env: "{{ item | oo_openshift_env }}"
+    openshift_env: "{{ hostvars[inventory_hostname]
+                       | oo_merge_dicts(hostvars)
+                       | oo_openshift_env }}"
     openshift_env_structures:
     - 'openshift.cloudprovider.aws.*'
     - 'openshift.cloudprovider.openstack.*'
-  no_log: true
-  with_items:
-  - "{{ hostvars[inventory_hostname] }}"
-  - "{{ hostvars }}"
 
 - name: Create cloudprovider config dir
   file:

+ 1 - 5
roles/openshift_common/tasks/main.yml

@@ -36,12 +36,8 @@
   action: "{{ ansible_pkg_mgr }} name={{ openshift.common.service_type }}{{ openshift_version | default('') | oo_image_tag_to_rpm_version }} state=present"
   when: not openshift.common.is_containerized | bool
 
-# This invocation also updates the version facts which are necessary
-# for setting the hostname below.
-- name: openshift_facts
+- name: Set version facts
   openshift_facts:
-    role: hosted
-    openshift_env: "{{ hostvars[inventory_hostname] | oo_openshift_env }}"
 
 # For enterprise versions < 3.1 and origin versions < 1.1 we want to set the
 # hostname by default.

+ 15 - 0
roles/openshift_hosted_facts/meta/main.yml

@@ -0,0 +1,15 @@
+---
+galaxy_info:
+  author: Andrew Butcher
+  description: OpenShift Hosted Facts
+  company: Red Hat, Inc.
+  license: Apache License, Version 2.0
+  min_ansible_version: 1.9
+  platforms:
+  - name: EL
+    versions:
+    - 7
+  categories:
+  - cloud
+dependencies:
+- role: openshift_facts

+ 7 - 0
roles/openshift_hosted_facts/tasks/main.yml

@@ -0,0 +1,7 @@
+---
+- name: Set hosted facts
+  openshift_facts:
+    role: hosted
+    openshift_env: "{{ hostvars[inventory_hostname]
+                       | oo_merge_dicts(hostvars)
+                       | oo_openshift_env }}"

+ 1 - 0
roles/openshift_master/meta/main.yml

@@ -16,3 +16,4 @@ dependencies:
 - role: openshift_cli
 - role: openshift_cloud_provider
 - role: openshift_master_facts
+- role: openshift_hosted_facts

+ 2 - 1
roles/openshift_persistent_volumes/meta/main.yml

@@ -10,4 +10,5 @@ galaxy_info:
     versions:
     - 7
 dependencies:
-- { role: openshift_common }
+- role: openshift_common
+- role: openshift_hosted_facts

+ 2 - 2
roles/openshift_registry/meta/main.yml

@@ -11,5 +11,5 @@ galaxy_info:
     - 7
   categories:
   - cloud
-  dependencies:
-  - openshift_facts
+dependencies:
+- role: openshift_hosted_facts

+ 3 - 3
roles/openshift_storage_nfs/meta/main.yml

@@ -10,6 +10,6 @@ galaxy_info:
     versions:
     - 7
 dependencies:
-- { role: os_firewall }
-- { role: openshift_facts }
-- { role: openshift_repos }
+- role: os_firewall
+- role: openshift_hosted_facts
+- role: openshift_repos