install.yml 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164
  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_config_file }}"
  24. # Check if an existing webconsole-config config map exists. If so, use those
  25. # contents so we don't overwrite changes.
  26. - name: Read the existing web console config map
  27. oc_configmap:
  28. namespace: openshift-web-console
  29. name: webconsole-config
  30. state: list
  31. register: webconsole_config_map
  32. - set_fact:
  33. existing_config_map_data: "{{ webconsole_config_map.results.results[0].data | default({}) }}"
  34. - name: Copy the existing web console config to temp directory
  35. copy:
  36. content: "{{ existing_config_map_data['webconsole-config.yaml'] }}"
  37. dest: "{{ mktemp.stdout }}/{{ __console_config_file }}"
  38. when: existing_config_map_data['webconsole-config.yaml'] is defined
  39. - set_fact:
  40. console_picker_admin_console_public_url: "https://{{ openshift_console_hostname | default('console.{{openshift_master_default_subdomain}}') }}{{ openshift_console_base_path | default('/') }}"
  41. when: (openshift_web_console_enable_context_selector | default(true) | bool) and (openshift_console_install | default(true) | bool)
  42. # Generate a new config when a config map is not defined.
  43. - when: existing_config_map_data['webconsole-config.yaml'] is not defined
  44. block:
  45. # Migrate the previous master-config.yaml asset config if it exists into the new
  46. # web console config config map.
  47. - name: Read existing assetConfig in master-config.yaml
  48. slurp:
  49. src: "{{ openshift.common.config_base }}/master/master-config.yaml"
  50. register: master_config_output
  51. - set_fact:
  52. config_to_migrate: "{{ master_config_output.content | b64decode | from_yaml }}"
  53. - set_fact:
  54. 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 }}"
  55. # Update properties in the config template based on inventory vars when the
  56. # asset config does not exist.
  57. - name: Set web console config properties from inventory variables
  58. yedit:
  59. src: "{{ mktemp.stdout }}/{{ __console_config_file }}"
  60. edits:
  61. - key: clusterInfo#consolePublicURL
  62. # Must have a trailing slash
  63. value: "{{ openshift.master.public_console_url }}/"
  64. - key: clusterInfo#masterPublicURL
  65. value: "{{ openshift.master.public_api_url }}"
  66. - key: clusterInfo#logoutPublicURL
  67. value: "{{ openshift.master.logout_url | default('') }}"
  68. - key: features#inactivityTimeoutMinutes
  69. value: "{{ openshift_web_console_inactivity_timeout_minutes | default(0) }}"
  70. - key: features#clusterResourceOverridesEnabled
  71. value: "{{ openshift_web_console_cluster_resource_overrides_enabled | default(cro_plugin_enabled) }}"
  72. - key: extensions#scriptURLs
  73. value: "{{ openshift_web_console_extension_script_urls | default([]) }}"
  74. - key: extensions#stylesheetURLs
  75. value: "{{ openshift_web_console_extension_stylesheet_urls | default([]) }}"
  76. - key: extensions#properties
  77. value: "{{ openshift_web_console_extension_properties | default({}) }}"
  78. separator: '#'
  79. state: present
  80. when: config_to_migrate.assetConfig is not defined
  81. - name: Migrate assetConfig from master-config.yaml
  82. yedit:
  83. src: "{{ mktemp.stdout }}/{{ __console_config_file }}"
  84. edits:
  85. - key: clusterInfo#consolePublicURL
  86. value: "{{ config_to_migrate.assetConfig.publicURL }}"
  87. - key: clusterInfo#masterPublicURL
  88. value: "{{ config_to_migrate.assetConfig.masterPublicURL }}"
  89. - key: clusterInfo#logoutPublicURL
  90. value: "{{ config_to_migrate.assetConfig.logoutURL | default('') }}"
  91. - key: clusterInfo#metricsPublicURL
  92. value: "{{ config_to_migrate.assetConfig.metricsPublicURL | default('') }}"
  93. - key: clusterInfo#loggingPublicURL
  94. value: "{{ config_to_migrate.assetConfig.loggingPublicURL | default('') }}"
  95. - key: servingInfo#maxRequestsInFlight
  96. value: "{{ config_to_migrate.assetConfig.servingInfo.maxRequestsInFlight | default(0) }}"
  97. - key: servingInfo#requestTimeoutSeconds
  98. value: "{{ config_to_migrate.assetConfig.servingInfo.requestTimeoutSeconds | default(0) }}"
  99. - key: features#clusterResourceOverridesEnabled
  100. value: "{{ openshift_web_console_cluster_resource_overrides_enabled | default(cro_plugin_enabled) }}"
  101. separator: '#'
  102. state: present
  103. when: config_to_migrate.assetConfig is defined
  104. # Add the admin console URL to the console picker on upgrade, even if there is an existing config.
  105. - name: Add context selector URL
  106. yedit:
  107. src: "{{ mktemp.stdout }}/{{ __console_config_file }}"
  108. edits:
  109. - key: clusterInfo#adminConsolePublicURL
  110. value: "{{ console_picker_admin_console_public_url | default('') }}"
  111. separator: '#'
  112. state: present
  113. - slurp:
  114. src: "{{ mktemp.stdout }}/{{ __console_config_file }}"
  115. register: updated_console_config
  116. # Avoids an issue where existing replica sets can be orphaned due to the label selector changing.
  117. - name: Apply the app label to pods and replica sets
  118. shell: >
  119. {{ openshift_client_binary }} label rs,pods -l webconsole=true app=openshift-web-console --overwrite=true -n openshift-web-console
  120. --config={{ mktemp.stdout }}/admin.kubeconfig
  121. when: not create_console_project.changed
  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_image }}"
  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. - name: Remove temp directory
  132. file:
  133. state: absent
  134. name: "{{ mktemp.stdout }}"
  135. changed_when: False
  136. # Wait to give the rollout time to start before verifying that the console is
  137. # running. Unfortunately, we can't check if the deployment revision changed
  138. # because it's possible applying the template did not result in any changes to
  139. # the pod template spec, which would skip a new revision.
  140. - name: Pause for the web console deployment to start
  141. pause:
  142. seconds: 30
  143. # Skip if the project didn't exist since there was no previous deployment.
  144. when: not create_console_project.changed
  145. - include_tasks: start.yml