install.yml 9.1 KB

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