install.yml 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  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. # Generate a new config when a config map is not defined.
  40. - when: existing_config_map_data['webconsole-config.yaml'] is not defined
  41. block:
  42. # Migrate the previous master-config.yaml asset config if it exists into the new
  43. # web console config config map.
  44. - name: Read existing assetConfig in master-config.yaml
  45. slurp:
  46. src: "{{ openshift.common.config_base }}/master/master-config.yaml"
  47. register: master_config_output
  48. - set_fact:
  49. config_to_migrate: "{{ master_config_output.content | b64decode | from_yaml }}"
  50. - set_fact:
  51. 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 }}"
  52. # Update properties in the config template based on inventory vars when the
  53. # asset config does not exist.
  54. - name: Set web console config properties from inventory variables
  55. yedit:
  56. src: "{{ mktemp.stdout }}/{{ __console_config_file }}"
  57. edits:
  58. - key: clusterInfo#consolePublicURL
  59. # Must have a trailing slash
  60. value: "{{ openshift.master.public_console_url }}/"
  61. - key: clusterInfo#masterPublicURL
  62. value: "{{ openshift.master.public_api_url }}"
  63. - key: clusterInfo#logoutPublicURL
  64. value: "{{ openshift.master.logout_url | default('') }}"
  65. - key: features#inactivityTimeoutMinutes
  66. value: "{{ openshift_web_console_inactivity_timeout_minutes | default(0) }}"
  67. - key: features#clusterResourceOverridesEnabled
  68. value: "{{ openshift_web_console_cluster_resource_overrides_enabled | default(cro_plugin_enabled) }}"
  69. - key: extensions#scriptURLs
  70. value: "{{ openshift_web_console_extension_script_urls | default([]) }}"
  71. - key: extensions#stylesheetURLs
  72. value: "{{ openshift_web_console_extension_stylesheet_urls | default([]) }}"
  73. - key: extensions#properties
  74. value: "{{ openshift_web_console_extension_properties | default({}) }}"
  75. separator: '#'
  76. state: present
  77. when: config_to_migrate.assetConfig is not defined
  78. - name: Migrate assetConfig from master-config.yaml
  79. yedit:
  80. src: "{{ mktemp.stdout }}/{{ __console_config_file }}"
  81. edits:
  82. - key: clusterInfo#consolePublicURL
  83. value: "{{ config_to_migrate.assetConfig.publicURL }}"
  84. - key: clusterInfo#masterPublicURL
  85. value: "{{ config_to_migrate.assetConfig.masterPublicURL }}"
  86. - key: clusterInfo#logoutPublicURL
  87. value: "{{ config_to_migrate.assetConfig.logoutURL | default('') }}"
  88. - key: clusterInfo#metricsPublicURL
  89. value: "{{ config_to_migrate.assetConfig.metricsPublicURL | default('') }}"
  90. - key: clusterInfo#loggingPublicURL
  91. value: "{{ config_to_migrate.assetConfig.loggingPublicURL | default('') }}"
  92. - key: servingInfo#maxRequestsInFlight
  93. value: "{{ config_to_migrate.assetConfig.servingInfo.maxRequestsInFlight | default(0) }}"
  94. - key: servingInfo#requestTimeoutSeconds
  95. value: "{{ config_to_migrate.assetConfig.servingInfo.requestTimeoutSeconds | default(0) }}"
  96. - key: features#clusterResourceOverridesEnabled
  97. value: "{{ openshift_web_console_cluster_resource_overrides_enabled | default(cro_plugin_enabled) }}"
  98. separator: '#'
  99. state: present
  100. when: config_to_migrate.assetConfig is defined
  101. - slurp:
  102. src: "{{ mktemp.stdout }}/{{ __console_config_file }}"
  103. register: updated_console_config
  104. # Avoids an issue where existing replica sets can be orphaned due to the label selector changing.
  105. - name: Apply the app label to pods and replica sets
  106. shell: >
  107. {{ openshift_client_binary }} label rs,pods -l webconsole=true app=openshift-web-console --overwrite=true -n openshift-web-console
  108. --config={{ mktemp.stdout }}/admin.kubeconfig
  109. when: not create_console_project.changed
  110. - name: Apply the web console template file
  111. shell: >
  112. {{ openshift_client_binary }} process -f "{{ mktemp.stdout }}/{{ __console_template_file }}"
  113. --param API_SERVER_CONFIG="{{ updated_console_config['content'] | b64decode }}"
  114. --param IMAGE="{{ openshift_web_console_image }}"
  115. --param NODE_SELECTOR={{ openshift_web_console_nodeselector | to_json | quote }}
  116. --param REPLICA_COUNT="{{ openshift_web_console_replica_count }}"
  117. --config={{ mktemp.stdout }}/admin.kubeconfig
  118. | {{ openshift_client_binary }} apply --config={{ mktemp.stdout }}/admin.kubeconfig -f -
  119. - name: Remove temp directory
  120. file:
  121. state: absent
  122. name: "{{ mktemp.stdout }}"
  123. changed_when: False
  124. # Wait to give the rollout time to start before verifying that the console is
  125. # running. Unfortunately, we can't check if the deployment revision changed
  126. # because it's possible applying the template did not result in any changes to
  127. # the pod template spec, which would skip a new revision.
  128. - name: Pause for the web console deployment to start
  129. pause:
  130. seconds: 30
  131. # Skip if the project didn't exist since there was no previous deployment.
  132. when: not create_console_project.changed
  133. - include_tasks: start.yml