install.yml 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157
  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: "{{ __console_files_location }}/{{ 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. # Update properties in the config template based on inventory vars when the
  64. # asset config does not exist.
  65. - name: Set web console config properties from inventory variables
  66. yedit:
  67. src: "{{ mktemp.stdout }}/{{ __console_config_file }}"
  68. edits:
  69. - key: clusterInfo#consolePublicURL
  70. # Must have a trailing slash
  71. value: "{{ openshift.master.public_console_url }}/"
  72. - key: clusterInfo#masterPublicURL
  73. value: "{{ openshift.master.public_api_url }}"
  74. - key: clusterInfo#logoutPublicURL
  75. value: "{{ openshift.master.logout_url | default('') }}"
  76. - key: features#inactivityTimeoutMinutes
  77. value: "{{ openshift_web_console_inactivity_timeout_minutes | default(0) }}"
  78. - key: extensions#scriptURLs
  79. value: "{{ openshift_web_console_extension_script_urls | default([]) }}"
  80. - key: extensions#stylesheetURLs
  81. value: "{{ openshift_web_console_extension_stylesheet_urls | default([]) }}"
  82. - key: extensions#properties
  83. value: "{{ openshift_web_console_extension_properties | default({}) }}"
  84. separator: '#'
  85. state: present
  86. when: config_to_migrate.assetConfig is not defined
  87. - name: Migrate assetConfig from master-config.yaml
  88. yedit:
  89. src: "{{ mktemp.stdout }}/{{ __console_config_file }}"
  90. edits:
  91. - key: clusterInfo#consolePublicURL
  92. value: "{{ config_to_migrate.assetConfig.publicURL }}"
  93. - key: clusterInfo#masterPublicURL
  94. value: "{{ config_to_migrate.assetConfig.masterPublicURL }}"
  95. - key: clusterInfo#logoutPublicURL
  96. value: "{{ config_to_migrate.assetConfig.logoutURL | default('') }}"
  97. - key: clusterInfo#metricsPublicURL
  98. value: "{{ config_to_migrate.assetConfig.metricsPublicURL | default('') }}"
  99. - key: clusterInfo#loggingPublicURL
  100. value: "{{ config_to_migrate.assetConfig.loggingPublicURL | default('') }}"
  101. - key: servingInfo#maxRequestsInFlight
  102. value: "{{ config_to_migrate.assetConfig.servingInfo.maxRequestsInFlight | default(0) }}"
  103. - key: servingInfo#requestTimeoutSeconds
  104. value: "{{ config_to_migrate.assetConfig.servingInfo.requestTimeoutSeconds | default(0) }}"
  105. separator: '#'
  106. state: present
  107. when: config_to_migrate.assetConfig is defined
  108. - slurp:
  109. src: "{{ mktemp.stdout }}/{{ __console_config_file }}"
  110. register: updated_console_config
  111. - name: Reconcile with the web console RBAC file
  112. shell: >
  113. {{ openshift_client_binary }} process -f "{{ mktemp.stdout }}/{{ __console_rbac_file }}" --config={{ mktemp.stdout }}/admin.kubeconfig
  114. | {{ openshift_client_binary }} auth reconcile --config={{ mktemp.stdout }}/admin.kubeconfig -f -
  115. - name: Apply the web console template file
  116. shell: >
  117. {{ openshift_client_binary }} process -f "{{ mktemp.stdout }}/{{ __console_template_file }}"
  118. --param API_SERVER_CONFIG="{{ updated_console_config['content'] | b64decode }}"
  119. --param IMAGE="{{ openshift_web_console_prefix }}{{ openshift_web_console_image_name }}:{{ openshift_web_console_version }}"
  120. --param NODE_SELECTOR={{ openshift_web_console_nodeselector | to_json | quote }}
  121. --param REPLICA_COUNT="{{ openshift_web_console_replica_count }}"
  122. --config={{ mktemp.stdout }}/admin.kubeconfig
  123. | {{ openshift_client_binary }} apply --config={{ mktemp.stdout }}/admin.kubeconfig -f -
  124. - name: Verify that the web console is running
  125. command: >
  126. curl -k https://webconsole.openshift-web-console.svc/healthz
  127. args:
  128. # Disables the following warning:
  129. # Consider using get_url or uri module rather than running curl
  130. warn: no
  131. register: console_health
  132. until: console_health.stdout == 'ok'
  133. retries: 120
  134. delay: 1
  135. changed_when: false
  136. - name: Remove temp directory
  137. file:
  138. state: absent
  139. name: "{{ mktemp.stdout }}"
  140. changed_when: False