install.yml 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199
  1. ---
  2. - name: Ensure openshift-web-console project exists
  3. oc_project:
  4. name: openshift-web-console
  5. state: present
  6. node_selector:
  7. - ""
  8. register: create_console_project
  9. - name: Make temp directory for web console templates
  10. command: mktemp -d /tmp/console-ansible-XXXXXX
  11. register: mktemp
  12. changed_when: False
  13. - name: Copy admin client config
  14. command: >
  15. cp {{ openshift.common.config_base }}/master//admin.kubeconfig {{ mktemp.stdout }}/admin.kubeconfig
  16. changed_when: false
  17. - name: Copy web console templates to temp directory
  18. copy:
  19. src: "{{ item }}"
  20. dest: "{{ mktemp.stdout }}/{{ item }}"
  21. with_items:
  22. - "{{ __console_template_file }}"
  23. - "{{ __console_rbac_file }}"
  24. - "{{ __console_config_file }}"
  25. # Check if an existing webconsole-config config map exists. If so, use those
  26. # contents so we don't overwrite changes.
  27. - name: Read the existing web console config map
  28. oc_configmap:
  29. namespace: openshift-web-console
  30. name: webconsole-config
  31. state: list
  32. register: webconsole_config_map
  33. - set_fact:
  34. existing_config_map_data: "{{ webconsole_config_map.results.results[0].data | default({}) }}"
  35. - name: Copy the existing web console config to temp directory
  36. copy:
  37. content: "{{ existing_config_map_data['webconsole-config.yaml'] }}"
  38. dest: "{{ mktemp.stdout }}/{{ __console_config_file }}"
  39. when: existing_config_map_data['webconsole-config.yaml'] is defined
  40. # Generate a new config when a config map is not defined.
  41. - when: existing_config_map_data['webconsole-config.yaml'] is not defined
  42. block:
  43. # Migrate the previous master-config.yaml asset config if it exists into the new
  44. # web console config config map.
  45. - name: Read existing assetConfig in master-config.yaml
  46. slurp:
  47. src: "{{ openshift.common.config_base }}/master/master-config.yaml"
  48. register: master_config_output
  49. - set_fact:
  50. config_to_migrate: "{{ master_config_output.content | b64decode | from_yaml }}"
  51. - set_fact:
  52. cro_plugin_enabled: "{{ config_to_migrate.admissionConfig is defined and config_to_migrate.admissionConfig.pluginConfig is defined and config_to_migrate.admissionConfig.pluginConfig.ClusterResourceOverrides is defined }}"
  53. # Update properties in the config template based on inventory vars when the
  54. # asset config does not exist.
  55. - name: Set web console config properties from inventory variables
  56. yedit:
  57. src: "{{ mktemp.stdout }}/{{ __console_config_file }}"
  58. edits:
  59. - key: clusterInfo#consolePublicURL
  60. # Must have a trailing slash
  61. value: "{{ openshift.master.public_console_url }}/"
  62. - key: clusterInfo#masterPublicURL
  63. value: "{{ openshift.master.public_api_url }}"
  64. - key: clusterInfo#logoutPublicURL
  65. value: "{{ openshift.master.logout_url | default('') }}"
  66. - key: features#inactivityTimeoutMinutes
  67. value: "{{ openshift_web_console_inactivity_timeout_minutes | default(0) }}"
  68. - key: features#clusterResourceOverridesEnabled
  69. value: "{{ openshift_web_console_cluster_resource_overrides_enabled | default(cro_plugin_enabled) }}"
  70. - key: extensions#scriptURLs
  71. value: "{{ openshift_web_console_extension_script_urls | default([]) }}"
  72. - key: extensions#stylesheetURLs
  73. value: "{{ openshift_web_console_extension_stylesheet_urls | default([]) }}"
  74. - key: extensions#properties
  75. value: "{{ openshift_web_console_extension_properties | default({}) }}"
  76. separator: '#'
  77. state: present
  78. when: config_to_migrate.assetConfig is not defined
  79. - name: Migrate assetConfig from master-config.yaml
  80. yedit:
  81. src: "{{ mktemp.stdout }}/{{ __console_config_file }}"
  82. edits:
  83. - key: clusterInfo#consolePublicURL
  84. value: "{{ config_to_migrate.assetConfig.publicURL }}"
  85. - key: clusterInfo#masterPublicURL
  86. value: "{{ config_to_migrate.assetConfig.masterPublicURL }}"
  87. - key: clusterInfo#logoutPublicURL
  88. value: "{{ config_to_migrate.assetConfig.logoutURL | default('') }}"
  89. - key: clusterInfo#metricsPublicURL
  90. value: "{{ config_to_migrate.assetConfig.metricsPublicURL | default('') }}"
  91. - key: clusterInfo#loggingPublicURL
  92. value: "{{ config_to_migrate.assetConfig.loggingPublicURL | default('') }}"
  93. - key: servingInfo#maxRequestsInFlight
  94. value: "{{ config_to_migrate.assetConfig.servingInfo.maxRequestsInFlight | default(0) }}"
  95. - key: servingInfo#requestTimeoutSeconds
  96. value: "{{ config_to_migrate.assetConfig.servingInfo.requestTimeoutSeconds | default(0) }}"
  97. - key: features#clusterResourceOverridesEnabled
  98. value: "{{ openshift_web_console_cluster_resource_overrides_enabled | default(cro_plugin_enabled) }}"
  99. separator: '#'
  100. state: present
  101. when: config_to_migrate.assetConfig is defined
  102. - slurp:
  103. src: "{{ mktemp.stdout }}/{{ __console_config_file }}"
  104. register: updated_console_config
  105. - name: Reconcile with the web console RBAC file
  106. shell: >
  107. {{ openshift_client_binary }} process -f "{{ mktemp.stdout }}/{{ __console_rbac_file }}" --config={{ mktemp.stdout }}/admin.kubeconfig
  108. | {{ openshift_client_binary }} auth reconcile --config={{ mktemp.stdout }}/admin.kubeconfig -f -
  109. - name: Apply the web console template file
  110. shell: >
  111. {{ openshift_client_binary }} process -f "{{ mktemp.stdout }}/{{ __console_template_file }}"
  112. --param API_SERVER_CONFIG="{{ updated_console_config['content'] | b64decode }}"
  113. --param IMAGE="{{ openshift_web_console_prefix }}{{ openshift_web_console_image_name }}:{{ openshift_web_console_version }}"
  114. --param NODE_SELECTOR={{ openshift_web_console_nodeselector | to_json | quote }}
  115. --param REPLICA_COUNT="{{ openshift_web_console_replica_count }}"
  116. --config={{ mktemp.stdout }}/admin.kubeconfig
  117. | {{ openshift_client_binary }} apply --config={{ mktemp.stdout }}/admin.kubeconfig -f -
  118. # Wait to give the rollout time to start before verifying that the console is
  119. # running. Unfortunately, we can't check if the deployment revision changed
  120. # because it's possible applying the template did not result in any changes to
  121. # the pod template spec, which would skip a new revision.
  122. - name: Pause for the web console deployment to start
  123. pause:
  124. seconds: 30
  125. # Skip if the project didn't exist since there was no previous deployment.
  126. when: not create_console_project.changed
  127. - name: Verify that the web console is running
  128. command: >
  129. curl -k https://webconsole.openshift-web-console.svc/healthz
  130. args:
  131. # Disables the following warning:
  132. # Consider using get_url or uri module rather than running curl
  133. warn: no
  134. register: console_health
  135. until: console_health.stdout == 'ok'
  136. retries: 60
  137. delay: 10
  138. changed_when: false
  139. # Ignore errors so we can log troubleshooting info on failures.
  140. ignore_errors: yes
  141. # Log the result of `oc status`, `oc get pods`, `oc get events`, and `oc logs deployment/webconsole` for troubleshooting failures.
  142. - when: console_health.stdout != 'ok'
  143. block:
  144. - name: Check status in the openshift-web-console namespace
  145. command: >
  146. {{ openshift_client_binary }} status --config={{ mktemp.stdout }}/admin.kubeconfig -n openshift-web-console
  147. register: console_status
  148. ignore_errors: true
  149. - debug:
  150. msg: "{{ console_status.stdout_lines }}"
  151. - name: Get pods in the openshift-web-console namespace
  152. command: >
  153. {{ openshift_client_binary }} get pods --config={{ mktemp.stdout }}/admin.kubeconfig -n openshift-web-console -o wide
  154. register: console_pods
  155. ignore_errors: true
  156. - debug:
  157. msg: "{{ console_pods.stdout_lines }}"
  158. - name: Get events in the openshift-web-console namespace
  159. command: >
  160. {{ openshift_client_binary }} get events --config={{ mktemp.stdout }}/admin.kubeconfig -n openshift-web-console
  161. register: console_events
  162. ignore_errors: true
  163. - debug:
  164. msg: "{{ console_events.stdout_lines }}"
  165. - name: Get console pod logs
  166. command: >
  167. {{ openshift_client_binary }} logs deployment/webconsole --tail=50 --config={{ mktemp.stdout }}/admin.kubeconfig -n openshift-web-console
  168. register: console_log
  169. ignore_errors: true
  170. - debug:
  171. msg: "{{ console_log.stdout_lines }}"
  172. - name: Remove temp directory
  173. file:
  174. state: absent
  175. name: "{{ mktemp.stdout }}"
  176. changed_when: False
  177. - name: Report console errors
  178. fail:
  179. msg: Console install failed.
  180. when: console_health.stdout != 'ok'