operator-install.yml 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177
  1. ---
  2. - name: Create temp directory for doing work in on target
  3. command: mktemp -td openshift-metering-ansible-XXXXXX
  4. register: mktemp
  5. changed_when: False
  6. - name: Ensures {{ mktemp.stdout }}/metering-manifests directories exists
  7. file:
  8. path: "{{ item }}"
  9. state: directory
  10. with_items:
  11. - "{{ mktemp.stdout }}/metering-manifests/operator"
  12. - name: Copy operator files to temp directory
  13. copy:
  14. src: "{{ item }}"
  15. dest: "{{ mktemp.stdout }}/metering-manifests/operator/{{ item | basename }}"
  16. with_fileglob:
  17. - "files/operator/*.yaml"
  18. register: temp_operator_files
  19. - name: Update Metering Helm Operator deployment image
  20. yedit:
  21. src: "{{ mktemp.stdout }}/metering-manifests/operator/metering-helm-operator-deployment.yaml"
  22. edits:
  23. - key: spec.template.spec.containers[0].image
  24. value: "{{ openshift_metering_operator_image }}"
  25. - key: spec.template.spec.containers[1].image
  26. value: "{{ openshift_metering_operator_image }}"
  27. when: openshift_metering_operator_image != ""
  28. - name: Update Metering config
  29. yedit:
  30. src: "{{ mktemp.stdout }}/metering-manifests/operator/metering.yaml"
  31. edits:
  32. - key: spec
  33. value: "{{ openshift_metering_config }}"
  34. when: openshift_metering_config != None
  35. - name: Update Metering config with custom database config for Hive metastore
  36. yedit:
  37. src: "{{ mktemp.stdout }}/metering-manifests/operator/metering.yaml"
  38. edits:
  39. - key: spec.presto.hive.config.dbConnectionURL
  40. value: "{{ openshift_metering_hive_metastore_db_url }}"
  41. - key: spec.presto.hive.config.dbDriver
  42. value: "{{ openshift_metering_hive_metastore_db_driver }}"
  43. - key: spec.presto.hive.config.dbConnectionUsername
  44. value: "{{ openshift_metering_hive_metastore_db_username }}"
  45. - key: spec.presto.hive.config.dbConnectionPassword
  46. value: "{{ openshift_metering_hive_metastore_db_password }}"
  47. when: openshift_metering_hive_metastore_db_use_custom | bool
  48. - name: Update Metering config with custom default storage location
  49. yedit:
  50. src: "{{ mktemp.stdout }}/metering-manifests/operator/metering.yaml"
  51. edits:
  52. - key: spec.metering-operator.config.defaultStorage
  53. value:
  54. create: true
  55. isDefault: true
  56. name: "{{ openshift_metering_default_storage_name }}"
  57. type: "{{ openshift_metering_default_storage_type }}"
  58. - key: "spec.metering-operator.config.defaultStorage.{{ openshift_metering_default_storage_type }}"
  59. value: "{{ openshift_metering_default_storage_config[openshift_metering_default_storage_type] }}"
  60. when: openshift_metering_default_storage_use_custom | bool
  61. - name: Update Metering config to enable or disable HDFS
  62. yedit:
  63. src: "{{ mktemp.stdout }}/metering-manifests/operator/metering.yaml"
  64. edits:
  65. - key: spec.hdfs.enabled
  66. value: "{{ openshift_metering_hdfs_enabled }}"
  67. when: openshift_metering_default_storage_use_custom | bool
  68. - name: Update Metering config with AWS credentials
  69. yedit:
  70. src: "{{ mktemp.stdout }}/metering-manifests/operator/metering.yaml"
  71. edits:
  72. - key: "{{ item.key }}"
  73. value: "{{ item.value }}"
  74. # If the value is empty, then the credentials aren't set and we don't need to
  75. # make the edit
  76. when: item.value != ""
  77. with_items:
  78. - key: spec.metering-operator.config.awsAccessKeyID
  79. value: "{{ openshift_metering_aws_access_key_id }}"
  80. - key: spec.metering-operator.config.awsSecretAccessKey
  81. value: "{{ openshift_metering_aws_secret_access_key }}"
  82. - key: spec.presto.config.awsAccessKeyID
  83. value: "{{ openshift_metering_aws_access_key_id }}"
  84. - key: spec.presto.config.awsSecretAccessKey
  85. value: "{{ openshift_metering_aws_secret_access_key }}"
  86. # Hide secrets
  87. no_log: True
  88. - name: Fetch updated operator manifests
  89. fetch:
  90. src: "{{ item.dest }}"
  91. dest: "/tmp/updated_manifests/"
  92. flat: true
  93. with_items: "{{ temp_operator_files.results }}"
  94. register: updated_operator_manifests
  95. loop_control:
  96. label: "{{ item.dest }}"
  97. - name: "Create {{ __openshift_metering_namespace }} project"
  98. oc_project:
  99. state: present
  100. name: "{{ __openshift_metering_namespace }}"
  101. description: Openshift Metering
  102. node_selector: ""
  103. - name: Create metering namespace viewer cluster role
  104. oc_clusterrole:
  105. state: present
  106. name: "openshift-metering-namespace-viewer-{{ __openshift_metering_namespace }}"
  107. rules:
  108. - apiGroups: [""]
  109. resources: ["namespaces"]
  110. verbs: ["get"]
  111. - name: Create namespace viewer clusterrolebinding
  112. oc_obj:
  113. state: present
  114. kind: ClusterRoleBinding
  115. name: "openshift-metering-namespace-viewer-{{ __openshift_metering_namespace }}"
  116. content:
  117. path: "{{ mktemp.stdout }}/openshift-metering-namespace-viewer-{{ __openshift_metering_namespace }}"
  118. data:
  119. apiVersion: v1
  120. kind: ClusterRoleBinding
  121. metadata:
  122. name: "openshift-metering-namespace-viewer-{{ __openshift_metering_namespace }}"
  123. roleRef:
  124. apiGroup: rbac.authorization.k8s.io
  125. kind: ClusterRole
  126. name: "openshift-metering-namespace-viewer-{{ __openshift_metering_namespace }}"
  127. subjects:
  128. - kind: ServiceAccount
  129. name: metering
  130. namespace: "{{ __openshift_metering_namespace }}"
  131. - name: Install Metering CRDs
  132. oc_obj:
  133. state: present
  134. kind: "{{ obj.kind }}"
  135. name: "{{ obj.metadata.name }}"
  136. namespace: "{{ __openshift_metering_namespace }}"
  137. content:
  138. path: "/tmp/{{ obj.kind }}-{{ obj.metadata.name }}.yaml"
  139. data: "{{ obj }}"
  140. vars:
  141. obj: "{{ lookup('file', item) | from_yaml }}"
  142. with_fileglob:
  143. - "files/crds/*.yaml"
  144. - name: Install Metering Helm Operator
  145. oc_obj:
  146. state: present
  147. kind: "{{ obj.kind }}"
  148. name: "{{ obj.metadata.name }}"
  149. namespace: "{{ __openshift_metering_namespace }}"
  150. content:
  151. path: "/tmp/{{ obj.kind }}-{{ obj.metadata.name }}.yaml"
  152. data: "{{ obj }}"
  153. vars:
  154. obj: "{{ lookup('file', item.dest) | from_yaml }}"
  155. with_items: "{{ updated_operator_manifests.results }}"
  156. loop_control:
  157. label: "{{ item.dest }}"
  158. - name: Delete temp directory
  159. file:
  160. name: "{{ mktemp.stdout }}"
  161. state: absent
  162. changed_when: False