Browse Source

properly set changes when oc apply

Jeff Cantrill 8 years ago
parent
commit
e96de3d7eb

+ 9 - 7
roles/openshift_metrics/tasks/install_metrics.yaml

@@ -1,9 +1,9 @@
 ---
-- name: check that hawkular_metrics_hostname is set
+- name: Check that hawkular_metrics_hostname is set
   fail: msg='the openshift_metrics_hawkular_hostname variable is required'
   when: openshift_metrics_hawkular_hostname is not defined
 
-- name: check the value of openshift_metrics_cassandra_storage_type
+- name: Check the value of openshift_metrics_cassandra_storage_type
   fail:
     msg: >
       openshift_metrics_cassandra_storage_type ({{ openshift_metrics_cassandra_storage_type }})
@@ -20,11 +20,13 @@
   loop_control:
     loop_var: include_file
 
-- name: create objects
-  command: >
-    {{ openshift.common.client_binary }} -n {{ openshift_metrics_project }}
-    --config={{ mktemp.stdout }}/admin.kubeconfig
-    apply -f {{ item }}
+- name: Create objects
+  include: oc_apply.yaml
+  vars:
+      kubeconfig: "{{ mktemp.stdout }}/admin.kubeconfig"
+      namespace: "{{ openshift_metrics_project }}"
+      file_name: "{{ item }}"
+      file_content: "{{ lookup('file',item) | from_yaml }}"
   with_fileglob:
     - "{{ mktemp.stdout }}/templates/*.yaml"
 

+ 31 - 0
roles/openshift_metrics/tasks/oc_apply.yaml

@@ -0,0 +1,31 @@
+---
+- name: Checking generation of {{file_content.kind}} {{file_content.metadata.name}}
+  command: >
+    {{ openshift.common.client_binary }} 
+    --config={{ kubeconfig }}
+    get {{file_content.kind}} {{file_content.metadata.name}}
+    -o jsonpath='{.metadata.resourceVersion}' 
+    -n {{namespace}}
+  register: generation_init
+  changed_when: no
+
+- name: Applying {{file_name}}
+  command: >
+    {{ openshift.common.client_binary }} --config={{ kubeconfig }}
+    apply -f {{ file_name }}
+    -n {{ openshift_metrics_project }}
+  register: generation_apply
+  failed_when: "'error' in generation_apply.stderr"
+  changed_when: no
+
+- name: Determine change status of {{file_content.kind}} {{file_content.metadata.name}}
+  command: >
+    {{ openshift.common.client_binary }} --config={{ kubeconfig }}
+    get {{file_content.kind}} {{file_content.metadata.name}}
+    -o jsonpath='{.metadata.resourceVersion}' 
+    -n {{namespace}}
+  register: version_changed
+  vars:
+    init_version: "{{ (generation_init is defined) | ternary(generation_init.stdout, '0') }}"
+  failed_when: "'error' in version_changed.stderr"
+  changed_when: version_changed.stdout | int  > init_version | int

+ 1 - 1
roles/openshift_metrics/tasks/start_metrics.yaml

@@ -43,7 +43,7 @@
     -o name
     -n {{openshift_metrics_project}}
   register: metrics_heapster_rc
-  check_mode: no
+  changed_when: no
 
 - name: Start Heapster
   include: scale.yaml