operator-install.yml 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195
  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 Operator deployment image
  20. yedit:
  21. src: "{{ mktemp.stdout }}/metering-manifests/operator/metering-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.spec.hive.config.dbConnectionURL
  40. value: "{{ openshift_metering_hive_metastore_db_url }}"
  41. - key: spec.presto.spec.hive.config.dbDriver
  42. value: "{{ openshift_metering_hive_metastore_db_driver }}"
  43. - key: spec.presto.spec.hive.config.dbConnectionUsername
  44. value: "{{ openshift_metering_hive_metastore_db_username }}"
  45. - key: spec.presto.spec.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.reporting-operator.spec.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.reporting-operator.spec.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.reporting-operator.spec.config.awsAccessKeyID
  79. value: "{{ openshift_metering_aws_access_key_id }}"
  80. - key: spec.reporting-operator.spec.config.awsSecretAccessKey
  81. value: "{{ openshift_metering_aws_secret_access_key }}"
  82. - key: spec.presto.spec.config.awsAccessKeyID
  83. value: "{{ openshift_metering_aws_access_key_id }}"
  84. - key: spec.presto.spec.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 reporting operator cluster role
  104. oc_clusterrole:
  105. state: present
  106. name: "openshift-reporting-operator-{{ __openshift_metering_namespace }}"
  107. rules:
  108. # Grant namespace viewer access to allow authing to cluster monitoring Prometheus
  109. - apiGroups: [""]
  110. resources: ["namespaces"]
  111. verbs: ["get"]
  112. # Grant subject access review and token review access to allow metering
  113. # auth-proxy to authenticate requests using openshift authentication
  114. # methods
  115. - apiGroups:
  116. - authorization.k8s.io
  117. resources:
  118. - subjectaccessreviews
  119. verbs:
  120. - create
  121. - apiGroups:
  122. - authentication.k8s.io
  123. resources:
  124. - tokenreviews
  125. verbs:
  126. - create
  127. # Grant access to reporting-operator so it can talk to prometheus and
  128. # authenticate it's API using auth-proxy
  129. - name: Create reporting operator clusterrolebinding
  130. oc_obj:
  131. state: present
  132. kind: ClusterRoleBinding
  133. name: "openshift-reporting-operator-{{ __openshift_metering_namespace }}"
  134. content:
  135. path: "{{ mktemp.stdout }}/openshift-reporting-operator-{{ __openshift_metering_namespace }}"
  136. data:
  137. apiVersion: v1
  138. kind: ClusterRoleBinding
  139. metadata:
  140. name: "openshift-reporting-operator-{{ __openshift_metering_namespace }}"
  141. roleRef:
  142. apiGroup: rbac.authorization.k8s.io
  143. kind: ClusterRole
  144. name: "openshift-reporting-operator-{{ __openshift_metering_namespace }}"
  145. subjects:
  146. - kind: ServiceAccount
  147. name: reporting-operator
  148. namespace: "{{ __openshift_metering_namespace }}"
  149. - name: Install Metering CRDs
  150. oc_obj:
  151. state: present
  152. kind: "{{ obj.kind }}"
  153. name: "{{ obj.metadata.name }}"
  154. namespace: "{{ __openshift_metering_namespace }}"
  155. content:
  156. path: "/tmp/{{ obj.kind }}-{{ obj.metadata.name }}.yaml"
  157. data: "{{ obj }}"
  158. vars:
  159. obj: "{{ lookup('file', item) | from_yaml }}"
  160. with_fileglob:
  161. - "files/crds/*.yaml"
  162. - name: Install Metering Operator
  163. oc_obj:
  164. state: present
  165. kind: "{{ obj.kind }}"
  166. name: "{{ obj.metadata.name }}"
  167. namespace: "{{ __openshift_metering_namespace }}"
  168. content:
  169. path: "/tmp/{{ obj.kind }}-{{ obj.metadata.name }}.yaml"
  170. data: "{{ obj }}"
  171. vars:
  172. obj: "{{ lookup('file', item.dest) | from_yaml }}"
  173. with_items: "{{ updated_operator_manifests.results }}"
  174. loop_control:
  175. label: "{{ item.dest }}"
  176. - name: Delete temp directory
  177. file:
  178. name: "{{ mktemp.stdout }}"
  179. state: absent
  180. changed_when: False