Browse Source

Merge pull request #309 from brenton/manage_node

delegate_to doesn't appear to be thread safe
Thomas Wiest 9 years ago
parent
commit
a27076bee3

+ 4 - 3
filter_plugins/oo_filters.py

@@ -52,8 +52,9 @@ class FilterModule(object):
     @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 match
-            _ALL_ of filters.
+            list. If filter is specified then we will include all items that
+            match _ALL_ of filters.  If a dict entry is missing the key in a
+            filter it will be excluded from the match.
             Ex: data = [ {'a':1, 'b':5, 'z': 'z'}, # True, return
                          {'a':2, 'z': 'z'},        # True, return
                          {'a':3, 'z': 'z'},        # True, return
@@ -74,7 +75,7 @@ class FilterModule(object):
                 raise errors.AnsibleFilterError("|fialed expects filter to be a"
                                                 " dict")
             retval = [FilterModule.get_attr(d, attribute) for d in data if (
-                all([d[key] == filters[key] for key in filters]))]
+                all([d.get(key, None) == filters[key] for key in filters]))]
         else:
             retval = [FilterModule.get_attr(d, attribute) for d in data]
 

+ 15 - 0
playbooks/common/openshift-node/config.yml

@@ -135,3 +135,18 @@
   roles:
   - os_env_extras
   - os_env_extras_node
+
+- name: Set scheduleability
+  hosts: oo_first_master
+  vars:
+    openshift_unscheduleable_nodes: "{{ hostvars
+                                        | oo_select_keys(groups['oo_nodes_to_config']) 
+                                        | oo_collect('openshift_hostname', {'openshift_scheduleable': False}) }}"
+  pre_tasks:
+  - set_fact:
+      openshift_scheduleable_nodes: "{{ hostvars
+                                      | oo_select_keys(groups['oo_nodes_to_config'])
+                                      | oo_collect('openshift_hostname') 
+                                      | difference(openshift_unscheduleable_nodes) }}"
+  roles:
+  - openshift_manage_node

+ 11 - 0
roles/openshift_manage_node/tasks/main.yml

@@ -0,0 +1,11 @@
+- name: Handle unscheduleable node
+  delegate_to: "{{ openshift_first_master }}"
+  command: >
+    {{ openshift.common.admin_binary }} manage-node {{ item }} --schedulable=false
+  with_items: openshift_unscheduleable_nodes
+
+- name: Handle scheduleable node
+  delegate_to: "{{ openshift_first_master }}"
+  command: >
+    {{ openshift.common.admin_binary }} manage-node {{ item }} --schedulable=true
+  with_items: openshift_scheduleable_nodes

+ 0 - 21
roles/openshift_node/tasks/main.yml

@@ -73,24 +73,3 @@
 
 - name: Start and enable openshift-node
   service: name=openshift-node enabled=yes state=started
-
-- name: Check scheduleable state
-  delegate_to: "{{ openshift_first_master }}"
-  command: >
-    {{ openshift.common.client_binary }} get node {{ openshift.common.hostname }}
-  register: ond_get_node
-  until: ond_get_node.rc == 0
-  retries: 10
-  delay: 5
-
-- name: Handle unscheduleable node
-  delegate_to: "{{ openshift_first_master }}"
-  command: >
-    {{ openshift.common.admin_binary }} manage-node {{ openshift.common.hostname }} --schedulable=false
-  when: openshift_scheduleable is defined and openshift_scheduleable == False and "SchedulingDisabled" not in ond_get_node.stdout
-
-- name: Handle scheduleable node
-  delegate_to: "{{ openshift_first_master }}"
-  command: >
-    {{ openshift.common.admin_binary }} manage-node {{ openshift.common.hostname }} --schedulable=true
-  when: (openshift_scheduleable is not defined or openshift_scheduleable == True) and "SchedulingDisabled" in ond_get_node.stdout