install.yml 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164
  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. - name: Make temp directory for web console templates
  22. command: mktemp -d /tmp/console-ansible-XXXXXX
  23. register: mktemp
  24. changed_when: False
  25. - name: Copy admin client config
  26. command: >
  27. cp {{ openshift.common.config_base }}/master//admin.kubeconfig {{ mktemp.stdout }}/admin.kubeconfig
  28. changed_when: false
  29. - name: Copy web console templates to temp directory
  30. copy:
  31. src: "{{ item }}"
  32. dest: "{{ mktemp.stdout }}/{{ item }}"
  33. with_items:
  34. - "{{ __console_template_file }}"
  35. - "{{ __console_rbac_file }}"
  36. - "{{ __console_config_file }}"
  37. # Check if an existing webconsole-config config map exists. If so, use those
  38. # contents so we don't overwrite changes.
  39. - name: Read the existing web console config map
  40. oc_configmap:
  41. namespace: openshift-web-console
  42. name: webconsole-config
  43. state: list
  44. register: webconsole_config_map
  45. - set_fact:
  46. existing_config_map_data: "{{ webconsole_config_map.results.results[0].data | default({}) }}"
  47. - name: Copy the existing web console config to temp directory
  48. copy:
  49. content: "{{ existing_config_map_data['webconsole-config.yaml'] }}"
  50. dest: "{{ mktemp.stdout }}/{{ __console_config_file }}"
  51. when: existing_config_map_data['webconsole-config.yaml'] is defined
  52. # Generate a new config when a config map is not defined.
  53. - when: existing_config_map_data['webconsole-config.yaml'] is not defined
  54. block:
  55. # Migrate the previous master-config.yaml asset config if it exists into the new
  56. # web console config config map.
  57. - name: Read existing assetConfig in master-config.yaml
  58. slurp:
  59. src: "{{ openshift.common.config_base }}/master/master-config.yaml"
  60. register: master_config_output
  61. - set_fact:
  62. config_to_migrate: "{{ master_config_output.content | b64decode | from_yaml }}"
  63. - set_fact:
  64. 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 }}"
  65. # Update properties in the config template based on inventory vars when the
  66. # asset config does not exist.
  67. - name: Set web console config properties from inventory variables
  68. yedit:
  69. src: "{{ mktemp.stdout }}/{{ __console_config_file }}"
  70. edits:
  71. - key: clusterInfo#consolePublicURL
  72. # Must have a trailing slash
  73. value: "{{ openshift.master.public_console_url }}/"
  74. - key: clusterInfo#masterPublicURL
  75. value: "{{ openshift.master.public_api_url }}"
  76. - key: clusterInfo#logoutPublicURL
  77. value: "{{ openshift.master.logout_url | default('') }}"
  78. - key: features#inactivityTimeoutMinutes
  79. value: "{{ openshift_web_console_inactivity_timeout_minutes | default(0) }}"
  80. - key: features#clusterResourceOverridesEnabled
  81. value: "{{ openshift_web_console_cluster_resource_overrides_enabled | default(cro_plugin_enabled) }}"
  82. - key: extensions#scriptURLs
  83. value: "{{ openshift_web_console_extension_script_urls | default([]) }}"
  84. - key: extensions#stylesheetURLs
  85. value: "{{ openshift_web_console_extension_stylesheet_urls | default([]) }}"
  86. - key: extensions#properties
  87. value: "{{ openshift_web_console_extension_properties | default({}) }}"
  88. separator: '#'
  89. state: present
  90. when: config_to_migrate.assetConfig is not defined
  91. - name: Migrate assetConfig from master-config.yaml
  92. yedit:
  93. src: "{{ mktemp.stdout }}/{{ __console_config_file }}"
  94. edits:
  95. - key: clusterInfo#consolePublicURL
  96. value: "{{ config_to_migrate.assetConfig.publicURL }}"
  97. - key: clusterInfo#masterPublicURL
  98. value: "{{ config_to_migrate.assetConfig.masterPublicURL }}"
  99. - key: clusterInfo#logoutPublicURL
  100. value: "{{ config_to_migrate.assetConfig.logoutURL | default('') }}"
  101. - key: clusterInfo#metricsPublicURL
  102. value: "{{ config_to_migrate.assetConfig.metricsPublicURL | default('') }}"
  103. - key: clusterInfo#loggingPublicURL
  104. value: "{{ config_to_migrate.assetConfig.loggingPublicURL | default('') }}"
  105. - key: servingInfo#maxRequestsInFlight
  106. value: "{{ config_to_migrate.assetConfig.servingInfo.maxRequestsInFlight | default(0) }}"
  107. - key: servingInfo#requestTimeoutSeconds
  108. value: "{{ config_to_migrate.assetConfig.servingInfo.requestTimeoutSeconds | default(0) }}"
  109. - key: features#clusterResourceOverridesEnabled
  110. value: "{{ openshift_web_console_cluster_resource_overrides_enabled | default(cro_plugin_enabled) }}"
  111. separator: '#'
  112. state: present
  113. when: config_to_migrate.assetConfig is defined
  114. - slurp:
  115. src: "{{ mktemp.stdout }}/{{ __console_config_file }}"
  116. register: updated_console_config
  117. - name: Reconcile with the web console RBAC file
  118. shell: >
  119. {{ openshift_client_binary }} process -f "{{ mktemp.stdout }}/{{ __console_rbac_file }}" --config={{ mktemp.stdout }}/admin.kubeconfig
  120. | {{ openshift_client_binary }} auth reconcile --config={{ mktemp.stdout }}/admin.kubeconfig -f -
  121. - name: Apply the web console template file
  122. shell: >
  123. {{ openshift_client_binary }} process -f "{{ mktemp.stdout }}/{{ __console_template_file }}"
  124. --param API_SERVER_CONFIG="{{ updated_console_config['content'] | b64decode }}"
  125. --param IMAGE="{{ openshift_web_console_prefix }}{{ openshift_web_console_image_name }}:{{ openshift_web_console_version }}"
  126. --param NODE_SELECTOR={{ openshift_web_console_nodeselector | to_json | quote }}
  127. --param REPLICA_COUNT="{{ openshift_web_console_replica_count }}"
  128. --config={{ mktemp.stdout }}/admin.kubeconfig
  129. | {{ openshift_client_binary }} apply --config={{ mktemp.stdout }}/admin.kubeconfig -f -
  130. - name: Verify that the web console is running
  131. command: >
  132. curl -k https://webconsole.openshift-web-console.svc/healthz
  133. args:
  134. # Disables the following warning:
  135. # Consider using get_url or uri module rather than running curl
  136. warn: no
  137. register: console_health
  138. until: console_health.stdout == 'ok'
  139. retries: 120
  140. delay: 1
  141. changed_when: false
  142. - name: Remove temp directory
  143. file:
  144. state: absent
  145. name: "{{ mktemp.stdout }}"
  146. changed_when: False