|
@@ -0,0 +1,120 @@
|
|
|
+---
|
|
|
+- name: Create temp directory for doing work in on target
|
|
|
+ command: mktemp -td openshift-metering-ansible-XXXXXX
|
|
|
+ register: mktemp
|
|
|
+ changed_when: False
|
|
|
+
|
|
|
+- name: Ensures {{ mktemp.stdout }}/metering-manifests directories exists
|
|
|
+ file:
|
|
|
+ path: "{{ item }}"
|
|
|
+ state: directory
|
|
|
+ with_items:
|
|
|
+ - "{{ mktemp.stdout }}/metering-manifests/operator"
|
|
|
+
|
|
|
+- name: Copy operator files to temp directory
|
|
|
+ copy:
|
|
|
+ src: "{{ item }}"
|
|
|
+ dest: "{{ mktemp.stdout }}/metering-manifests/operator/{{ item | basename }}"
|
|
|
+ with_fileglob:
|
|
|
+ - "files/operator/*.yaml"
|
|
|
+ register: temp_operator_files
|
|
|
+
|
|
|
+- name: Update Metering Helm Operator deployment image
|
|
|
+ yedit:
|
|
|
+ src: "{{ mktemp.stdout }}/metering-manifests/operator/metering-helm-operator-deployment.yaml"
|
|
|
+ edits:
|
|
|
+ - key: spec.template.spec.containers[0].image
|
|
|
+ value: "{{ openshift_metering_operator_image }}"
|
|
|
+ - key: spec.template.spec.containers[1].image
|
|
|
+ value: "{{ openshift_metering_operator_image }}"
|
|
|
+ when: openshift_metering_operator_image != ""
|
|
|
+
|
|
|
+- name: Update Metering config
|
|
|
+ yedit:
|
|
|
+ src: "{{ mktemp.stdout }}/metering-manifests/operator/metering.yaml"
|
|
|
+ edits:
|
|
|
+ - key: spec
|
|
|
+ value: "{{ openshift_metering_config }}"
|
|
|
+ when: openshift_metering_config != None
|
|
|
+
|
|
|
+- name: Fetch updated operator manifests
|
|
|
+ fetch:
|
|
|
+ src: "{{ item.dest }}"
|
|
|
+ dest: "/tmp/updated_manifests/"
|
|
|
+ flat: true
|
|
|
+ with_items: "{{ temp_operator_files.results }}"
|
|
|
+ register: updated_operator_manifests
|
|
|
+ loop_control:
|
|
|
+ label: "{{ item.dest }}"
|
|
|
+
|
|
|
+- name: "Create {{ __openshift_metering_namespace }} project"
|
|
|
+ oc_project:
|
|
|
+ state: present
|
|
|
+ name: "{{ __openshift_metering_namespace }}"
|
|
|
+ description: Openshift Metering
|
|
|
+ node_selector: ""
|
|
|
+
|
|
|
+- name: Create metering namespace viewer cluster role
|
|
|
+ oc_clusterrole:
|
|
|
+ state: present
|
|
|
+ name: "openshift-metering-namespace-viewer-{{ __openshift_metering_namespace }}"
|
|
|
+ rules:
|
|
|
+ - apiGroups: [""]
|
|
|
+ resources: ["namespaces"]
|
|
|
+ verbs: ["get"]
|
|
|
+
|
|
|
+- name: Create namespace viewer clusterrolebinding
|
|
|
+ oc_obj:
|
|
|
+ state: present
|
|
|
+ kind: ClusterRoleBinding
|
|
|
+ name: "openshift-metering-namespace-viewer-{{ __openshift_metering_namespace }}"
|
|
|
+ content:
|
|
|
+ path: "{{ mktemp.stdout }}/openshift-metering-namespace-viewer-{{ __openshift_metering_namespace }}"
|
|
|
+ data:
|
|
|
+ apiVersion: v1
|
|
|
+ kind: ClusterRoleBinding
|
|
|
+ metadata:
|
|
|
+ name: "openshift-metering-namespace-viewer-{{ __openshift_metering_namespace }}"
|
|
|
+ roleRef:
|
|
|
+ apiGroup: rbac.authorization.k8s.io
|
|
|
+ kind: ClusterRole
|
|
|
+ name: "openshift-metering-namespace-viewer-{{ __openshift_metering_namespace }}"
|
|
|
+ subjects:
|
|
|
+ - kind: ServiceAccount
|
|
|
+ name: metering
|
|
|
+ namespace: "{{ __openshift_metering_namespace }}"
|
|
|
+
|
|
|
+- name: Install Metering CRDs
|
|
|
+ oc_obj:
|
|
|
+ state: present
|
|
|
+ kind: "{{ obj.kind }}"
|
|
|
+ name: "{{ obj.metadata.name }}"
|
|
|
+ namespace: "{{ __openshift_metering_namespace }}"
|
|
|
+ content:
|
|
|
+ path: "/tmp/{{ obj.kind }}-{{ obj.metadata.name }}.yaml"
|
|
|
+ data: "{{ obj }}"
|
|
|
+ vars:
|
|
|
+ obj: "{{ lookup('file', item) | from_yaml }}"
|
|
|
+ with_fileglob:
|
|
|
+ - "files/crds/*.yaml"
|
|
|
+
|
|
|
+- name: Install Metering Helm Operator
|
|
|
+ oc_obj:
|
|
|
+ state: present
|
|
|
+ kind: "{{ obj.kind }}"
|
|
|
+ name: "{{ obj.metadata.name }}"
|
|
|
+ namespace: "{{ __openshift_metering_namespace }}"
|
|
|
+ content:
|
|
|
+ path: "/tmp/{{ obj.kind }}-{{ obj.metadata.name }}.yaml"
|
|
|
+ data: "{{ obj }}"
|
|
|
+ vars:
|
|
|
+ obj: "{{ lookup('file', item.dest) | from_yaml }}"
|
|
|
+ with_items: "{{ updated_operator_manifests.results }}"
|
|
|
+ loop_control:
|
|
|
+ label: "{{ item.dest }}"
|
|
|
+
|
|
|
+- name: Delete temp directory
|
|
|
+ file:
|
|
|
+ name: "{{ mktemp.stdout }}"
|
|
|
+ state: absent
|
|
|
+ changed_when: False
|