diff --git a/automation-roles/50-install-cloud-pak/cp4d/cp4d-cartridge-install/tasks/cp4d-install-cartridges-olm-utils.yml b/automation-roles/50-install-cloud-pak/cp4d/cp4d-cartridge-install/tasks/cp4d-install-cartridges-olm-utils.yml index f62c0b611..a9889558e 100644 --- a/automation-roles/50-install-cloud-pak/cp4d/cp4d-cartridge-install/tasks/cp4d-install-cartridges-olm-utils.yml +++ b/automation-roles/50-install-cloud-pak/cp4d/cp4d-cartridge-install/tasks/cp4d-install-cartridges-olm-utils.yml @@ -69,9 +69,12 @@ when: - _install_cartridges_result.rc!=0 - - name: Wait for cartridges to finish installation - include_tasks: cp4d-wait-cartridges-ready.yml + - name: Run post-processing scripts + include_tasks: cp4d-install-cr-post-processing.yml loop: "{{ _apply_cr_cartridges | default([]) }}" loop_control: loop_var: _current_cp4d_cartridge + when: + - _install_cartridges_result.rc==0 + when: not cpd_dry_run \ No newline at end of file diff --git a/automation-roles/50-install-cloud-pak/cp4d/cp4d-cartridge-install/tasks/cp4d-install-separate-cr.yml b/automation-roles/50-install-cloud-pak/cp4d/cp4d-cartridge-install/tasks/cp4d-install-separate-cr.yml index d59f61261..7eebe3568 100644 --- a/automation-roles/50-install-cloud-pak/cp4d/cp4d-cartridge-install/tasks/cp4d-install-separate-cr.yml +++ b/automation-roles/50-install-cloud-pak/cp4d/cp4d-cartridge-install/tasks/cp4d-install-separate-cr.yml @@ -16,5 +16,10 @@ - include_tasks: "cp4d-install-cr-{{ _current_cp4d_cartridge.olm_utils_name }}.yml" when: _install_cr_script.stat.exists + - name: Run post-processing scripts + include_tasks: cp4d-install-cr-post-processing.yml + when: + - _install_cartridges_result.rc==0 + when: - (_current_cp4d_cartridge.separate_install | default(False) | bool) \ No newline at end of file diff --git a/automation-roles/50-install-cloud-pak/cp4d/cp4d-cartridge-install/tasks/cp4d-wait-cartridges-ready.yml b/automation-roles/50-install-cloud-pak/cp4d/cp4d-cartridge-install/tasks/cp4d-wait-cartridges-ready.yml deleted file mode 100644 index eabd81266..000000000 --- a/automation-roles/50-install-cloud-pak/cp4d/cp4d-cartridge-install/tasks/cp4d-wait-cartridges-ready.yml +++ /dev/null @@ -1,43 +0,0 @@ ---- -- block: - - name: Write status of cartridges to {{ status_dir }}/log/{{ _p_current_cp4d_cluster.project }}-cartridges-status.csv - shell: | - get-cr-status --cpd_instance_ns={{ _p_current_cp4d_cluster.project }} > {{ status_dir }}/log/{{ _p_current_cp4d_cluster.project }}-cartridges-status.csv - - - name: Write cartridge information to file {{ status_dir }}/log/{{ _p_current_cp4d_cluster.project }}-cartridges.json - copy: - content: "{{ _cartridges_to_install | default([]) | to_json }}" - dest: "{{ status_dir }}/log/{{ _p_current_cp4d_cluster.project }}-cartridges.json" - - - name: Wait until cartridge {{ _current_cp4d_cartridge.name }} has been installed, check logs in {{ status_dir }}/log/{{ _p_current_cp4d_cluster.project }}-cartridges.log - script: | - check-services-installed.sh \ - {{ status_dir }} \ - {{ _p_current_cp4d_cluster.project }} \ - {{ _current_cp4d_cartridge.name }} - - register: _wait_cartridges_result - until: _wait_cartridges_result.rc!=0 or _wait_cartridges_result.stdout.find('cartridge installation successfully completed') != -1 - retries: "{{ _v_cartrige_install_wait_retries }}" - failed_when: False - delay: 120 - vars: - ansible_callback_diy_runner_retry_msg: >- - {%- set result = ansible_callback_diy.result.output -%} - {%- set retries_left = result.retries - result.attempts -%} - Retrying: {{ ansible_callback_diy.task.name }} ({{ retries_left }} Retries left) ... - - - set_fact: - _cp4d_cartridges_installed_successfully: False - when: _wait_cartridges_result.rc!=0 or _wait_cartridges_result.stdout.find('cartridge installation successfully completed') == -1 - - - name: Fail if there was an error waiting for the cartridge(s) to be installed - fail: - msg: "{{ _wait_cartridges_result }}" - when: - - not _cp4d_cartridges_installed_successfully - - not (cpd_test_cartridges | default(False) | bool) - - when: - - not _current_cp4d_cartridge.name in ['cpfs','cp-foundation','cpd_platform','lite','scheduler'] - - not (_current_cp4d_cartridge.cr_internal | default(False) | bool) \ No newline at end of file diff --git a/automation-roles/50-install-cloud-pak/cp4d/cp4d-cartridge-install/tasks/main.yml b/automation-roles/50-install-cloud-pak/cp4d/cp4d-cartridge-install/tasks/main.yml index be759e206..4e7d8aac7 100644 --- a/automation-roles/50-install-cloud-pak/cp4d/cp4d-cartridge-install/tasks/main.yml +++ b/automation-roles/50-install-cloud-pak/cp4d/cp4d-cartridge-install/tasks/main.yml @@ -2,6 +2,44 @@ - include_role: name: cp4d-variables +# Set fact which is handled when testing install of all cartridges +- set_fact: + _cp4d_cartridges_installed_successfully: True + +- set_fact: + _apply_olm_cartridges_list: >- + {{ _cartridges_to_install + | map(attribute='olm_utils_name') + | difference(_v_cp4d_control_plane_cartridges) + | list + | join(',')}} + +- set_fact: + _apply_cr_cartridges: >- + {{ _cartridges_to_install | + selectattr('separate_install','undefined') | + union(_cartridges_to_install | selectattr('separate_install','defined') | selectattr('separate_install','!=',True)) }} + +- set_fact: + _apply_cr_cartridges_list: >- + {{ _apply_cr_cartridges + | map(attribute='olm_utils_name') + | difference(_v_cp4d_control_plane_cartridges) + | list + | join(',')}} + +- name: Create catalog sources for Cloud Pak for Data cartridges in project {{ _p_current_cp4d_cluster.project }} + include_role: + name: cp4d-catalog-source + vars: + _p_catsrc_scope: cartridges + +- name: Create subscriptions for Cloud Pak for Data cartridges in project {{ _p_current_cp4d_cluster.project }} + include_role: + name: cp4d-subscriptions + vars: + _p_subscription_scope: cartridges + - name: Populate {{ status_dir }}/cp4d/{{ _p_current_cp4d_cluster.project }}-install-options.yml lineinfile: path: "{{ status_dir }}/cp4d/{{ _p_current_cp4d_cluster.project }}-install-options.yml" @@ -25,43 +63,16 @@ var: _patch_db2u when: not cpd_dry_run -# Set fact which is handled when testing install of all cartridges -- set_fact: - _cp4d_cartridges_installed_successfully: True - -- set_fact: - _apply_cr_cartridges: >- - {{ _cartridges_to_install | - rejectattr('olm_utils_name','==','scheduler') | - rejectattr('olm_utils_name','==','cpd_platform') | - rejectattr('olm_utils_name','==','cpfs') | - selectattr('separate_install','undefined') | - union(_cartridges_to_install | selectattr('separate_install','defined') | selectattr('separate_install','!=',True)) }} +- include_tasks: cp4d-install-cartridges-olm-utils.yml + when: _apply_cr_cartridges_list != '' - set_fact: - _apply_cr_cartridges_list: >- - {{ _apply_cr_cartridges | - map(attribute='olm_utils_name') | - join(',')}} - -- include_tasks: cp4d-install-cartridges-olm-utils.yml - when: _apply_cr_cartridges != [] + _apply_cr_cartridges_separate: >- + {{ _cartridges_to_install + | selectattr('separate_install','defined') | selectattr('separate_install','==',True) }} - name: Install separate cartridges include_tasks: cp4d-install-separate-cr.yml - loop: "{{ _cartridges_to_install | default([]) }}" - loop_control: - loop_var: _current_cp4d_cartridge - -- name: Run post-processing scripts - include_tasks: cp4d-install-cr-post-processing.yml - loop: "{{ _cartridges_to_install | default([]) }}" - loop_control: - loop_var: _current_cp4d_cartridge - -- name: Wait for cartridges to finish installation - include_tasks: cp4d-wait-cartridges-ready.yml - loop: "{{ _cartridges_to_install | default([]) }}" + loop: "{{ _apply_cr_cartridges_separate | default([]) }}" loop_control: - loop_var: _current_cp4d_cartridge - when: not cpd_dry_run \ No newline at end of file + loop_var: _current_cp4d_cartridge \ No newline at end of file diff --git a/automation-roles/50-install-cloud-pak/cp4d/cp4d-cartridge-remove/tasks/cp4d-check-remove-cr.yml b/automation-roles/50-install-cloud-pak/cp4d/cp4d-cartridge-remove/tasks/cp4d-check-remove-cr.yml deleted file mode 100644 index 2fdc94316..000000000 --- a/automation-roles/50-install-cloud-pak/cp4d/cp4d-cartridge-remove/tasks/cp4d-check-remove-cr.yml +++ /dev/null @@ -1,21 +0,0 @@ ---- -- set_fact: - _configured_cartridge: "{{ _all_cartridges | json_query(query) | first | default({}) }}" - vars: - query: >- - [?name=='{{ _current_cartridge_cr.name }}'] - -- debug: - msg: "{{ _configured_cartridge }}" - -- name: Check if cartridge {{ _current_cartridge_cr.name }} is currently installed - shell: | - oc get {{ _current_cartridge_cr.cr_cr }} {{ _current_cartridge_cr.cr_name }} --namespace {{ _p_current_cp4d_cluster.project }} - failed_when: False - register: _cartridge_installed - -- include_tasks: cp4d-remove-cr.yml - when: - - _cartridge_installed.rc == 0 - - _surviving_cartridges | selectattr('CR_Kind','equalto',(_configured_cartridge.CR_Kind | default(''))) | list | count == 0 - - _configured_cartridge == {} or ((_configured_cartridge.state | default('installed')) == 'removed' ) \ No newline at end of file diff --git a/automation-roles/50-install-cloud-pak/cp4d/cp4d-cartridge-remove/tasks/cp4d-remove-cr.yml b/automation-roles/50-install-cloud-pak/cp4d/cp4d-cartridge-remove/tasks/cp4d-remove-cr.yml index ceec1d52d..4a29530bb 100644 --- a/automation-roles/50-install-cloud-pak/cp4d/cp4d-cartridge-remove/tasks/cp4d-remove-cr.yml +++ b/automation-roles/50-install-cloud-pak/cp4d/cp4d-cartridge-remove/tasks/cp4d-remove-cr.yml @@ -1,17 +1,32 @@ --- -- name: Fail if destroy was not confirmed - fail: - msg: "Will not delete cartridge {{ _current_cartridge_cr.name }}. Destroy was not confirmed with --confirm-destroy parameter or global_config confirm_destroy property" - when: - - (_confirm_destroy | default(False) | bool) != True - - not cpd_dry_run - -- name: Delete instances of {{ _current_cartridge_cr.name }} +- name: Delete instances of {{ _obsolete_cartridge.Component }} include_tasks: cp4d-delete-cr-instances.yml +- name: Generate delete-cr command to delete cartridge {{ _obsolete_cartridge.Component }} from project {{ _p_current_cp4d_cluster.project }} + set_fact: + _delete_cr_command: "{{ lookup('template', 'delete-cr.j2') }}" + - include_role: name: run-command vars: - _p_command_description: Remove cartridge {{ _current_cartridge_cr.name }} in namespace {{ _p_current_cp4d_cluster.project }} - _p_command: "oc delete {{ _current_cartridge_cr.cr_cr }} --namespace {{ _p_current_cp4d_cluster.project }} --all" - _p_command_log_file: "{{ status_dir }}/log/{{ _p_current_cp4d_cluster.project }}-delete-cartridge.log" \ No newline at end of file + _p_command_description: Remove cartridge {{ _obsolete_cartridge.Component }} in namespace {{ _p_current_cp4d_cluster.project }} + _p_command: "{{ _delete_cr_command }}" + _p_command_log_file: "{{ status_dir }}/log/{{ _p_current_cp4d_cluster.project }}-delete-cartridge.log" + _p_command_failed_when: False + +- block: + - set_fact: + _delete_cartridge_result: "{{ _run_command_result }}" + + - name: Fail if there was an error deleting the cartridge {{ _obsolete_cartridge.Component }} using delete-cr + fail: + msg: "{{ _delete_cartridge_result }}" + when: + - _delete_cartridge_result.rc!=0 + - not (cpd_test_cartridges | default(False) | bool) + + - set_fact: + _cp4d_cartridges_installed_successfully: False + when: + - _delete_cartridge_result.rc!=0 + when: not cpd_dry_run \ No newline at end of file diff --git a/automation-roles/50-install-cloud-pak/cp4d/cp4d-cartridge-remove/tasks/main.yml b/automation-roles/50-install-cloud-pak/cp4d/cp4d-cartridge-remove/tasks/main.yml index 42e2d4375..1e529dbce 100644 --- a/automation-roles/50-install-cloud-pak/cp4d/cp4d-cartridge-remove/tasks/main.yml +++ b/automation-roles/50-install-cloud-pak/cp4d/cp4d-cartridge-remove/tasks/main.yml @@ -2,17 +2,21 @@ - include_role: name: cp4d-variables +- name: Fail if there are cartridges to remove and destroy was not confirmed + fail: + msg: | + Will not delete cartridges. Destroy was not confirmed with --confirm-destroy parameter or global_config confirm_destroy property. + Cartridges that would be destroyed are: {{ _obsolete_cartridges_names }} + when: + - _obsolete_cartridges_names | length != 0 + - (_confirm_destroy | default(False) | bool) != True + - not cpd_dry_run + - name: Remove obsolete cartridges from CP4D cluster {{ _p_current_cp4d_cluster.project }} debug: msg: "Remove obsolete cartridges from CP4D cluster {{ _p_current_cp4d_cluster.project }}" -- name: Check which obsolete cartridges are still installed - include_tasks: cp4d-check-remove-cr.yml - loop: "{{ _all_cartridges }}" +- include_tasks: cp4d-remove-cr.yml + loop: "{{ _obsolete_cartridges }}" loop_control: - loop_var: _current_cartridge_cr - when: - - (_current_cartridge_cr.cr_cr | default('')) != '' - - not (_current_cartridge_cr.embedded | default(False) | bool) - - not (_current_cartridge_cr.cr_internal | default(False) | bool) - - not _current_cartridge_cr.name in ['cpfs','cp-foundation','cpd_platform','lite','scheduler'] \ No newline at end of file + loop_var: _obsolete_cartridge \ No newline at end of file diff --git a/automation-roles/50-install-cloud-pak/cp4d/cp4d-cartridge-remove/templates/delete-cr.j2 b/automation-roles/50-install-cloud-pak/cp4d/cp4d-cartridge-remove/templates/delete-cr.j2 new file mode 100644 index 000000000..02ade85e9 --- /dev/null +++ b/automation-roles/50-install-cloud-pak/cp4d/cp4d-cartridge-remove/templates/delete-cr.j2 @@ -0,0 +1,3 @@ +delete-cr \ + --cpd_instance_ns={{ _p_current_cp4d_cluster.project }} \ + --components={{ _obsolete_cartridge.Component }} \ No newline at end of file diff --git a/automation-roles/50-install-cloud-pak/cp4d/cp4d-catalog-source/tasks/create-catalog-source-olm-utils.yml b/automation-roles/50-install-cloud-pak/cp4d/cp4d-catalog-source/tasks/create-catalog-source-olm-utils.yml index f125a4ef1..2f2f7bda8 100644 --- a/automation-roles/50-install-cloud-pak/cp4d/cp4d-catalog-source/tasks/create-catalog-source-olm-utils.yml +++ b/automation-roles/50-install-cloud-pak/cp4d/cp4d-catalog-source/tasks/create-catalog-source-olm-utils.yml @@ -91,7 +91,7 @@ vars: _p_command_description: Create catalog sources for {{ _p_catsrc_scope }} _p_command: "{{ _apply_olm_command }}" - _p_command_log_file: "{{ status_dir }}/log/apply-olm-create-catsrc{{ _p_catsrc_scope }}.log" + _p_command_log_file: "{{ status_dir }}/log/apply-olm-create-catsrc-{{ _p_catsrc_scope }}.log" - name: If not air-gapped, copy case files from /tmp/work/offline to {{ status_dir }}/cp4d/offline copy: diff --git a/automation-roles/50-install-cloud-pak/cp4d/cp4d-catalog-source/tasks/main.yml b/automation-roles/50-install-cloud-pak/cp4d/cp4d-catalog-source/tasks/main.yml index 99b24c80f..5df55de86 100644 --- a/automation-roles/50-install-cloud-pak/cp4d/cp4d-catalog-source/tasks/main.yml +++ b/automation-roles/50-install-cloud-pak/cp4d/cp4d-catalog-source/tasks/main.yml @@ -1,12 +1,10 @@ --- - set_fact: - _catsrc_cartridges_to_install_list: "{{ _cartridges_to_install_list }}" + _catsrc_cartridges_to_install_list: "{{ _apply_olm_cartridges_list }}" - set_fact: _catsrc_cartridges_to_install_list: "cpfs,cpd_platform" when: _p_catsrc_scope == 'platform' - include_tasks: create-catalog-source-olm-utils.yml - -- include_tasks: wait-catalog-sources-ready.yml - when: not cpd_dry_run \ No newline at end of file + when: _catsrc_cartridges_to_install_list != '' \ No newline at end of file diff --git a/automation-roles/50-install-cloud-pak/cp4d/cp4d-cluster/tasks/cp4d-cartridge-test.yml b/automation-roles/50-install-cloud-pak/cp4d/cp4d-cluster/tasks/cp4d-cartridge-test.yml index c30fb8f0a..b853e0763 100644 --- a/automation-roles/50-install-cloud-pak/cp4d/cp4d-cluster/tasks/cp4d-cartridge-test.yml +++ b/automation-roles/50-install-cloud-pak/cp4d/cp4d-cluster/tasks/cp4d-cartridge-test.yml @@ -21,6 +21,12 @@ debug: var: _test_current_cp4d_cluster + - name: Login to the OpenShift cluster {{ _test_current_cp4d_cluster.openshift_cluster_name }} + include_role: + name: openshift-login + vars: + _p_openshift_cluster_name: "{{ _test_current_cp4d_cluster.openshift_cluster_name }}" + - name: CPD TEST CARTRIDGES - Remove obsolete cartridges include_role: name: cp4d-cartridge-remove diff --git a/automation-roles/50-install-cloud-pak/cp4d/cp4d-cluster/tasks/install-cp4d-prepare.yml b/automation-roles/50-install-cloud-pak/cp4d/cp4d-cluster/tasks/install-cp4d-prepare.yml index 0f8c9e8d9..f76fe7406 100644 --- a/automation-roles/50-install-cloud-pak/cp4d/cp4d-cluster/tasks/install-cp4d-prepare.yml +++ b/automation-roles/50-install-cloud-pak/cp4d/cp4d-cluster/tasks/install-cp4d-prepare.yml @@ -10,16 +10,6 @@ vars: _p_current_cp4d_cluster: "{{ current_cp4d_cluster }}" -- set_fact: - _cpd_accept_licenses: "False" - -- set_fact: - _cpd_accept_licenses: "True" - when: (cpd_accept_licenses | default(False) | bool) or (current_cp4d_cluster.accept_licenses | default(False) | bool) - -- debug: - var: _cpd_accept_licenses - - name: Fail if licenses were not accepted fail: msg: "You must accept the licenses, either in the cp4d object with accept_licenses: True, or by specifying --accept-all-licenses at the command line" @@ -71,7 +61,4 @@ name: cp4d-prepare-openshift vars: _p_openshift_cluster_name: "{{ current_cp4d_cluster.openshift_cluster_name }}" - when: ( current_cp4d_cluster.change_node_settings | default(True) | bool ) - -- include_tasks: install-cp4d.yml - when: not (cpd_skip_cp_install | bool) + when: ( current_cp4d_cluster.change_node_settings | default(True) | bool ) \ No newline at end of file diff --git a/automation-roles/50-install-cloud-pak/cp4d/cp4d-cluster/tasks/install-cp4d.yml b/automation-roles/50-install-cloud-pak/cp4d/cp4d-cluster/tasks/install-cp4d.yml index cbbc3c644..5725b9f35 100644 --- a/automation-roles/50-install-cloud-pak/cp4d/cp4d-cluster/tasks/install-cp4d.yml +++ b/automation-roles/50-install-cloud-pak/cp4d/cp4d-cluster/tasks/install-cp4d.yml @@ -44,9 +44,6 @@ _p_preview: False when: current_cp4d_cluster.cp4d_version >= "4.7.0" -- name: Prepare KNative for OpenShift - include_tasks: openshift-install-knative.yml - - name: Prepare OpenShift project {{ current_cp4d_cluster.project }} for Cloud Pak for Data include_tasks: openshift-prepare-project.yml @@ -93,26 +90,4 @@ name: cp4d-apply-entitlement vars: _p_cp4d_entitlement: "{{ current_cp4d_cluster.cp4d_entitlement | default([]) }}" - _p_cp4d_production_license: "{{ current_cp4d_cluster.cp4d_production_license | default(True) }}" - -- name: Create catalog sources for Cloud Pak for Data cartridges in project {{ current_cp4d_cluster.project }} - include_role: - name: cp4d-catalog-source - vars: - _p_current_cp4d_cluster: "{{ current_cp4d_cluster }}" - _p_catsrc_scope: cartridges - -- name: Create subscriptions for Cloud Pak for Data cartridges in project {{ current_cp4d_cluster.project }} - include_role: - name: cp4d-subscriptions - vars: - _p_current_cp4d_cluster: "{{ current_cp4d_cluster }}" - _p_subscription_scope: cartridges - -# Install selected cartridges -- include_tasks: cp4d-cartridges.yml - when: not (cpd_test_cartridges | default(False) | bool) - -# Install all cartridges one by one -- include_tasks: cp4d-cartridges-test-all.yml - when: (cpd_test_cartridges | default(False) | bool) + _p_cp4d_production_license: "{{ current_cp4d_cluster.cp4d_production_license | default(True) }}" \ No newline at end of file diff --git a/automation-roles/50-install-cloud-pak/cp4d/cp4d-cluster/tasks/main.yml b/automation-roles/50-install-cloud-pak/cp4d/cp4d-cluster/tasks/main.yml index be8608702..e80fd13bc 100644 --- a/automation-roles/50-install-cloud-pak/cp4d/cp4d-cluster/tasks/main.yml +++ b/automation-roles/50-install-cloud-pak/cp4d/cp4d-cluster/tasks/main.yml @@ -11,5 +11,20 @@ - include_tasks: install-cp4d-prepare.yml when: current_cp4d_cluster.state=='installed' +- include_tasks: install-cp4d.yml + when: current_cp4d_cluster.state=='installed' + +# Install selected cartridges +- include_tasks: cp4d-cartridges.yml + when: + - current_cp4d_cluster.state=='installed' + - not (cpd_test_cartridges | default(False) | bool) + +# Install all cartridges one by one +- include_tasks: cp4d-cartridges-test-all.yml + when: + - current_cp4d_cluster.state=='installed' + - (cpd_test_cartridges | default(False) | bool) + - include_tasks: delete-cp4d.yml when: current_cp4d_cluster.state=='removed' \ No newline at end of file diff --git a/automation-roles/50-install-cloud-pak/cp4d/cp4d-cluster/tasks/openshift-install-knative.yml b/automation-roles/50-install-cloud-pak/cp4d/cp4d-cluster/tasks/openshift-install-knative.yml deleted file mode 100644 index 17c600b76..000000000 --- a/automation-roles/50-install-cloud-pak/cp4d/cp4d-cluster/tasks/openshift-install-knative.yml +++ /dev/null @@ -1,48 +0,0 @@ ---- -# Prepare CP4D for versions >= 4.8.0 -- block: - - - name: Create the catalog source for IBM Events operator when in air-gapped environment. deploy-knative-eventing doesn't manage local case files - block: - - name: Get the cpfs case version - shell: yq ".release_components_meta.cpfs.case_version" /opt/ansible/ansible-play/config-vars/release-{{ current_cp4d_cluster.cp4d_version }}.yml - register: _cpfs_case_version - - - name: Unpack case file {{ status_dir }}/work/offline/{{ current_cp4d_cluster.cp4d_version }}/.ibm-pak/data/cases/ibm-cp-common-services/{{ _cpfs_case_version.stdout }}/ibm-cp-common-services-{{ _cpfs_case_version }}.tgz to /tmp - unarchive: - src: "{{ status_dir }}/work/offline/{{ current_cp4d_cluster.cp4d_version }}/.ibm-pak/data/cases/ibm-cp-common-services/{{ _cpfs_case_version.stdout }}/ibm-cp-common-services-{{ _cpfs_case_version.stdout }}.tgz" - dest: /tmp - remote_src: True - - - name: Create OpenShift Project ibm-knative-events - shell: - oc new-project ibm-knative-events || true - - - name: Create catalog source - shell: | - oc patch --filename=/tmp/ibm-cp-common-services/inventory/ibmCommonServiceOperatorSetup/files/op-olm/catalog_source.yaml \ - --type=merge \ - -o yaml \ - --patch='{"metadata": {"namespace": "ibm-knative-events"}}' \ - --dry-run=client | oc apply -n ibm-knative-events -f - - - when: - - cpd_airgap | bool - - not cpd_dry_run - - - name: Generate deploy KNative eventing command - set_fact: - _deploy_knative_eventing_command: "{{ lookup('template','deploy-knative-eventing.j2') }}" - - - include_role: - name: run-command - vars: - _p_command_description: Deploy KNative eventing - _p_command: "{{ _deploy_knative_eventing_command }}" - _p_command_log_file: "{{ status_dir }}/log/{{ current_cp4d_cluster.project }}-deploy-knative-eventing.log" - _p_command_retries: 10 - _p_command_delay: 15 - - when: - - current_cp4d_cluster.cp4d_version >= '4.8.0' - - (_knative_eventing_dependency | default(False)) \ No newline at end of file diff --git a/automation-roles/50-install-cloud-pak/cp4d/cp4d-prepare-openshift/tasks/cp4d-install-knative.yml b/automation-roles/50-install-cloud-pak/cp4d/cp4d-prepare-openshift/tasks/cp4d-install-knative.yml new file mode 100644 index 000000000..f6d2f5bfe --- /dev/null +++ b/automation-roles/50-install-cloud-pak/cp4d/cp4d-prepare-openshift/tasks/cp4d-install-knative.yml @@ -0,0 +1,41 @@ +--- +- name: Create the catalog source for IBM Events operator when in air-gapped environment. deploy-knative-eventing doesn't manage local case files + block: + - name: Get the cpfs case version + shell: yq ".release_components_meta.cpfs.case_version" /opt/ansible/ansible-play/config-vars/release-{{ current_cp4d_cluster.cp4d_version }}.yml + register: _cpfs_case_version + + - name: Unpack case file {{ status_dir }}/work/offline/{{ current_cp4d_cluster.cp4d_version }}/.ibm-pak/data/cases/ibm-cp-common-services/{{ _cpfs_case_version.stdout }}/ibm-cp-common-services-{{ _cpfs_case_version }}.tgz to /tmp + unarchive: + src: "{{ status_dir }}/work/offline/{{ current_cp4d_cluster.cp4d_version }}/.ibm-pak/data/cases/ibm-cp-common-services/{{ _cpfs_case_version.stdout }}/ibm-cp-common-services-{{ _cpfs_case_version.stdout }}.tgz" + dest: /tmp + remote_src: True + + - name: Create OpenShift Project ibm-knative-events + shell: + oc new-project ibm-knative-events || true + + - name: Create catalog source + shell: | + oc patch --filename=/tmp/ibm-cp-common-services/inventory/ibmCommonServiceOperatorSetup/files/op-olm/catalog_source.yaml \ + --type=merge \ + -o yaml \ + --patch='{"metadata": {"namespace": "ibm-knative-events"}}' \ + --dry-run=client | oc apply -n ibm-knative-events -f - + + when: + - cpd_airgap | bool + - not cpd_dry_run + +- name: Generate deploy KNative eventing command + set_fact: + _deploy_knative_eventing_command: "{{ lookup('template','deploy-knative-eventing.j2') }}" + +- include_role: + name: run-command + vars: + _p_command_description: Deploy KNative eventing + _p_command: "{{ _deploy_knative_eventing_command }}" + _p_command_log_file: "{{ status_dir }}/log/{{ current_cp4d_cluster.project }}-deploy-knative-eventing.log" + _p_command_retries: 10 + _p_command_delay: 15 \ No newline at end of file diff --git a/automation-roles/50-install-cloud-pak/cp4d/cp4d-prepare-openshift/tasks/main.yml b/automation-roles/50-install-cloud-pak/cp4d/cp4d-prepare-openshift/tasks/main.yml index 803b4d516..7ef16a8d2 100644 --- a/automation-roles/50-install-cloud-pak/cp4d/cp4d-prepare-openshift/tasks/main.yml +++ b/automation-roles/50-install-cloud-pak/cp4d/cp4d-prepare-openshift/tasks/main.yml @@ -27,7 +27,12 @@ - include_tasks: cp4d-install-openshift-ai.yml when: - (_current_openshift_cluster.openshift_ai.install | default('') | lower) == 'auto' - - _opernshift_ai_required + - _openshift_ai_required + +- include_tasks: cp4d-install-knative.yml + when: + - current_cp4d_cluster.cp4d_version >= '4.8.0' + - (_knative_eventing_dependency | default(False)) - name: Prepare Cloud Pak for Data cluster-wide configuration on cluster {{ current_cp4d_cluster.openshift_cluster_name }} include_tasks: cp4d-prepare-openshift.yml \ No newline at end of file diff --git a/automation-roles/50-install-cloud-pak/cp4d/cp4d-subscriptions/tasks/cp4d-create-subscriptions-olm-utils.yml b/automation-roles/50-install-cloud-pak/cp4d/cp4d-subscriptions/tasks/cp4d-create-subscriptions-olm-utils.yml index e41fb6da3..405dbe871 100644 --- a/automation-roles/50-install-cloud-pak/cp4d/cp4d-subscriptions/tasks/cp4d-create-subscriptions-olm-utils.yml +++ b/automation-roles/50-install-cloud-pak/cp4d/cp4d-subscriptions/tasks/cp4d-create-subscriptions-olm-utils.yml @@ -1,20 +1,4 @@ --- -- set_fact: - _apply_olm_cartridges: "{{ _cartridges_to_install | rejectattr('olm_utils_name','==','watsonx_orchestrate') }}" - -- set_fact: - _apply_olm_cartridges_list: >- - {{ _apply_olm_cartridges | - map(attribute='olm_utils_name') | - join(',')}} - -- set_fact: - _subscription_cartridges_to_install_list: "{{ _apply_olm_cartridges_list }}" - -- set_fact: - _subscription_cartridges_to_install_list: "cpfs,cpd_platform" - when: _p_subscription_scope == 'platform' - - block: - name: Generate preview script to create subscriptions for Cloud Pak for Data {{ _p_subscription_scope }} set_fact: diff --git a/automation-roles/50-install-cloud-pak/cp4d/cp4d-subscriptions/tasks/main.yml b/automation-roles/50-install-cloud-pak/cp4d/cp4d-subscriptions/tasks/main.yml index 6dbab08d2..174d4acdf 100644 --- a/automation-roles/50-install-cloud-pak/cp4d/cp4d-subscriptions/tasks/main.yml +++ b/automation-roles/50-install-cloud-pak/cp4d/cp4d-subscriptions/tasks/main.yml @@ -1,2 +1,10 @@ --- -- include_tasks: cp4d-create-subscriptions-olm-utils.yml \ No newline at end of file +- set_fact: + _subscription_cartridges_to_install_list: "{{ _apply_olm_cartridges_list }}" + +- set_fact: + _subscription_cartridges_to_install_list: "cpfs,cpd_platform" + when: _p_subscription_scope == 'platform' + +- include_tasks: cp4d-create-subscriptions-olm-utils.yml + when: _subscription_cartridges_to_install_list != '' \ No newline at end of file diff --git a/automation-roles/50-install-cloud-pak/cp4d/cp4d-variables/tasks/check-gpu-openshift-ai.yml b/automation-roles/50-install-cloud-pak/cp4d/cp4d-variables/tasks/check-gpu-openshift-ai.yml index 961ca3af2..72f474ca6 100644 --- a/automation-roles/50-install-cloud-pak/cp4d/cp4d-variables/tasks/check-gpu-openshift-ai.yml +++ b/automation-roles/50-install-cloud-pak/cp4d/cp4d-variables/tasks/check-gpu-openshift-ai.yml @@ -2,7 +2,7 @@ # Determine if any cartridges with a Knative dependency are installed - set_fact: _nfd_gpu_required: False - _opernshift_ai_required: False + _openshift_ai_required: False - name: Determine if any of the cartridges has a dependency on the Node Feature Discovery or NVIDIA GPU operators set_fact: @@ -15,9 +15,18 @@ - name: Determine if any of the cartridges has a dependency on the OpenShift AI operator set_fact: - _opernshift_ai_required: "{{ _nfd_gpu_required or (item.nfd_gpu_required | default(False)) }}" + _openshift_ai_required: "{{ _openshift_ai_required or (item.openshift_ai_required | default(False)) }}" loop: "{{ _cartridges_to_install }}" -- name: Show if there is a dependency on theOpenShift AI operator +- set_fact: + _nfd_gpu_required: True + _openshift_ai_required: True + when: (cpd_test_cartridges | default(False) | bool) + +- name: Show if there is a dependency on the Node Feature Discovery or NVIDIA GPU operators + debug: + var: _nfd_gpu_required + +- name: Show if there is a dependency on the OpenShift AI operator debug: - var: _opernshift_ai_required + var: _openshift_ai_required diff --git a/automation-roles/50-install-cloud-pak/cp4d/cp4d-variables/tasks/check-knative-eventing.yml b/automation-roles/50-install-cloud-pak/cp4d/cp4d-variables/tasks/check-knative-eventing.yml index fff295e3e..a09643db0 100644 --- a/automation-roles/50-install-cloud-pak/cp4d/cp4d-variables/tasks/check-knative-eventing.yml +++ b/automation-roles/50-install-cloud-pak/cp4d/cp4d-variables/tasks/check-knative-eventing.yml @@ -8,6 +8,10 @@ _knative_eventing_dependency: "{{ _knative_eventing_dependency or (item.knative_eventing_dependency | default(False)) }}" loop: "{{ _cartridges_to_install }}" +- set_fact: + _knative_eventing_dependency: True + when: (cpd_test_cartridges | default(False) | bool) + - name: Show if there is a Knative eventing dependency debug: var: _knative_eventing_dependency diff --git a/automation-roles/50-install-cloud-pak/cp4d/cp4d-variables/tasks/get-cr-status.yml b/automation-roles/50-install-cloud-pak/cp4d/cp4d-variables/tasks/get-cr-status.yml new file mode 100644 index 000000000..ffacc2397 --- /dev/null +++ b/automation-roles/50-install-cloud-pak/cp4d/cp4d-variables/tasks/get-cr-status.yml @@ -0,0 +1,83 @@ +--- +- name: Clean up any old /tmp/work/status.csv file + file: + path: /tmp/work/status.csv + state: absent + +- name: Generate get-cr-status command to get CR status for CP4D project {{ _p_current_cp4d_cluster.project }} + set_fact: + _get_cr_status_command: "{{ lookup('template', 'get-cr-status.j2') }}" + +- name: Run get-cr-status command + shell: | + {{ _get_cr_status_command }} + +- set_fact: + _cp4d_get_cr_status_file: "{{ status_dir }}/cp4d/{{ _p_current_cp4d_cluster.project }}-cr-status.csv" + _cp4d_get_cr_status_no_header_file: "{{ status_dir }}/cp4d/{{ _p_current_cp4d_cluster.project }}-cr-status-no-header.csv" + +- name: Check if CR status file exists + stat: + path: /tmp/work/status.csv + register: _cr_status_file + +- name: Create header line if CR status does not exist + lineinfile: + path: /tmp/work/status.csv + line: "Component,CR Kind,CR Name,Creation Timestamp,Namespace,Expected Version,Reconciled Version,Operator Information,Progress,Progress Message,Reconcile History,Status" + insertbefore: "BOF" + state: present + create: True + when: not _cr_status_file.stat.exists + +# Try to copy the get-cr-status file. In certain situations (Windows, SELinux), the command may fail and has to be re-run without remote_src +- block: + - name: Copy file to {{ _cp4d_get_cr_status_file }} + copy: + src: /tmp/work/status.csv + dest: "{{ _cp4d_get_cr_status_file }}" + remote_src: True + force: True + mode: u+rwx,g+rwx,o+rwx + rescue: + - name: Rescue copy file to {{ _cp4d_get_cr_status_file }} + copy: + src: /tmp/work/status.csv + dest: "{{ _cp4d_get_cr_status_file }}" + +- name: Get column headers + shell: | + head -1 {{ _cp4d_get_cr_status_file }} + register: _csv_column_headers_output + +- set_fact: + _csv_column_headers: "{{ _csv_column_headers_output.stdout }}" + +# Try to copy the get-cr-status output file. In certain situations (Windows, SELinux), the command may fail and has to be re-run without remote_src +- block: + - name: Copy file to {{ _cp4d_get_cr_status_no_header_file }} + copy: + src: "{{ _cp4d_get_cr_status_file }}" + dest: "{{ _cp4d_get_cr_status_no_header_file }}" + remote_src: True + rescue: + - name: Copy file to {{ _cp4d_get_cr_status_no_header_file }} + copy: + src: "{{ _cp4d_get_cr_status_file }}" + dest: "{{ _cp4d_get_cr_status_no_header_file }}" + +- name: Remove first line from file + lineinfile: + path: "{{ _cp4d_get_cr_status_no_header_file }}" + regexp: "^Component" + state: absent + +- name: Try to convert to json + read_csv: + path: "{{ _cp4d_get_cr_status_no_header_file }}" + fieldnames: "{{ _csv_column_headers | replace(' ','_') }}" + skipinitialspace: True + register: _get_cr_status_json + +- debug: + var: _get_cr_status_json \ No newline at end of file diff --git a/automation-roles/50-install-cloud-pak/cp4d/cp4d-variables/tasks/main.yml b/automation-roles/50-install-cloud-pak/cp4d/cp4d-variables/tasks/main.yml index ae398483a..984243f6d 100644 --- a/automation-roles/50-install-cloud-pak/cp4d/cp4d-variables/tasks/main.yml +++ b/automation-roles/50-install-cloud-pak/cp4d/cp4d-variables/tasks/main.yml @@ -12,6 +12,20 @@ - name: Include variables for Cloud Pak for Data include_vars: vars-cp4d-installation.yml +- set_fact: + _confirm_destroy: True + when: (cpd_test_cartridges | default(False) | bool) + +- set_fact: + _cpd_accept_licenses: "False" + +- set_fact: + _cpd_accept_licenses: "True" + when: (cpd_accept_licenses | default(False) | bool) or (_p_current_cp4d_cluster.accept_licenses | default(False) | bool) + +- debug: + var: _cpd_accept_licenses + - set_fact: foundational_services_project: "{{ _p_current_cp4d_cluster.operators_project }}" when: _p_current_cp4d_cluster.cp4d_version >= "4.7.0" @@ -30,6 +44,8 @@ include_tasks: list-components-olm-utils.yml when: _list_components_json is not defined +- include_tasks: get-cr-status.yml + - name: Get cartridges with CR details set_fact: _cartridges_with_olm_utils_name: >- @@ -62,11 +78,11 @@ msg: "Not all cartridges in the configuration are valid: {{ _undefined_cartridges }}" when: _undefined_cartridges!=[] -- name: Add versions details from olm-utils +- name: Add versions details from olm-utils and installed version from get-cr-status set_fact: _all_cartridges: >- {{ _all_cartridges | default([]) - + [ item | combine(_list_components_json_item) ] + + [ item | combine(_list_components_json_item) | combine(_get_cr_status_json_item) ] }} vars: _list_components_json_item: >- @@ -76,6 +92,13 @@ | first | default([]) }} + _get_cr_status_json_item: >- + {{ _get_cr_status_json.list + | selectattr('Component','equalto',item['olm_utils_name']) + | list + | first + | default([]) + }} loop: "{{ _cartridges_with_olm_utils_name }}" # Remove any cartridges without a defined Component_name @@ -86,27 +109,27 @@ _all_cartridges: "{{ _tmp_cartridges }}" # Make sure that the dp cartridge is placed at the end -- set_fact: - _dp_cartridge: >- - {{ _all_cartridges | selectattr('Component_name','match','dp') | default({}) }} +# - set_fact: +# _dp_cartridge: >- +# {{ _all_cartridges | selectattr('Component_name','match','dp') | default({}) }} -- set_fact: - _tmp_cartridges: "{{ _all_cartridges | rejectattr('Component_name','match','dp') }}" +# - set_fact: +# _tmp_cartridges: "{{ _all_cartridges | rejectattr('Component_name','match','dp') }}" -- set_fact: - _all_cartridges: >- - {{ _tmp_cartridges + _dp_cartridge }} +# - set_fact: +# _all_cartridges: >- +# {{ _tmp_cartridges + _dp_cartridge }} -- set_fact: - _cartridges_to_install: "{{ _all_cartridges }}" - when: (cpd_test_cartridges | default(False) | bool) +# - set_fact: +# _cartridges_to_install: "{{ _all_cartridges }}" +# when: (cpd_test_cartridges | default(False) | bool) - set_fact: _cartridges_to_install: >- {{ _all_cartridges | selectattr('state','undefined') | union(_all_cartridges | selectattr('state','defined') | selectattr('state','==','installed')) }} - when: not(cpd_test_cartridges | default(False) | bool) + # when: not(cpd_test_cartridges | default(False) | bool) - set_fact: _cartridges_to_install_list: >- @@ -182,30 +205,43 @@ vars: jmes_query: "[?state=='installed'].olm_utils_name" -- name: Make sure that ikc_standard is added to dependencies if ikc_premium is installed +- name: Add control plane cartridges to the surviving cartridges + set_fact: + _surviving_cartridges_names: "{{ _surviving_cartridges_names }} + ['cpd_platform','zen','cpfs']" + +- name: Make sure that ikc_standard is added to the surviving cartridges if ikc_premium is installed set_fact: _surviving_cartridges_names: "{{ _surviving_cartridges_names | union(['ikc_standard']) }}" when: '"ikc_premium" in _surviving_cartridges_names' +- name: Obtain surviving cartridge CRs + set_fact: + _surviving_cartridges_crs: "{{ _cartridges_to_install | json_query(jmes_query) }}" + vars: + jmes_query: "[?state=='installed'].CR_Kind" + - debug: var: _surviving_cartridges_names -- name: Determine the surviving cartridges - set_fact: - _surviving_cartridges: >- - {{ _surviving_cartridges | union(_cartridges_to_install_item) }} - vars: - _cartridges_to_install_item: >- - {{ _all_cartridges - | selectattr('olm_utils_name','equalto',item) - }} - loop: "{{ _surviving_cartridges_names }}" +- debug: + var: _surviving_cartridges_crs - set_fact: - _surviving_cartridges: "{{ _surviving_cartridges | default([]) | rejectattr('CR_Kind','undefined') }}" + _obsolete_cartridges: >- + {{ _get_cr_status_json.list + | rejectattr('Component','in',_surviving_cartridges_names) + | rejectattr('CR_Kind','in',_surviving_cartridges_crs) }} + +- set_fact: + _obsolete_cartridges_names: >- + {{ _obsolete_cartridges + | map(attribute='Component') }} + +- debug: + var: _obsolete_cartridges - debug: - var: _surviving_cartridges + var: _obsolete_cartridges_names - name: Write cartridge to install information to file {{ status_dir }}/log/{{ _p_current_cp4d_cluster.project }}-cartridges.json copy: diff --git a/automation-roles/50-install-cloud-pak/cp4d/cp4d-variables/templates/get-cr-status.j2 b/automation-roles/50-install-cloud-pak/cp4d/cp4d-variables/templates/get-cr-status.j2 new file mode 100644 index 000000000..7f9efc4be --- /dev/null +++ b/automation-roles/50-install-cloud-pak/cp4d/cp4d-variables/templates/get-cr-status.j2 @@ -0,0 +1,2 @@ +get-cr-status \ + --cpd_instance_ns={{ _p_current_cp4d_cluster.project }} \ No newline at end of file diff --git a/automation-roles/50-install-cloud-pak/cp4d/cp4d-variables/vars/vars-cp4d-installation.yml b/automation-roles/50-install-cloud-pak/cp4d/cp4d-variables/vars/vars-cp4d-installation.yml index 760c23eb1..8ee6a00a3 100644 --- a/automation-roles/50-install-cloud-pak/cp4d/cp4d-variables/vars/vars-cp4d-installation.yml +++ b/automation-roles/50-install-cloud-pak/cp4d/cp4d-variables/vars/vars-cp4d-installation.yml @@ -16,6 +16,10 @@ scheduling_service_project: ibm-cpd-scheduler cert_manager_project: ibm-cert-manager cs_control_project: cs-control +_v_cp4d_control_plane_cartridges: + - cpfs + - cpd_platform + cartridge_cr: - name: lite olm_utils_name: cpd_platform diff --git a/automation-roles/60-configure-cloud-pak/cp4d/cp4d-cluster-configure/tasks/cp4d-cluster-configure.yml b/automation-roles/60-configure-cloud-pak/cp4d/cp4d-cluster-configure/tasks/cp4d-cluster-configure.yml index 5b8cac283..f172fcabc 100644 --- a/automation-roles/60-configure-cloud-pak/cp4d/cp4d-cluster-configure/tasks/cp4d-cluster-configure.yml +++ b/automation-roles/60-configure-cloud-pak/cp4d/cp4d-cluster-configure/tasks/cp4d-cluster-configure.yml @@ -14,13 +14,6 @@ query: >- [?name=='{{ current_cp4d_cluster.openshift_cluster_name }}'] -- set_fact: - _cpd_accept_licenses: "False" - -- set_fact: - _cpd_accept_licenses: "True" - when: (cpd_accept_licenses | default(False) | bool) or (current_cp4d_cluster.accept_licenses | default(False) | bool) - - fail: msg: "The Cloud Pak for Data license must be accepted to perform configuration tasks on the platform. \ Ensure the 'accept_licenses' of the 'cp4d' configuration yaml is set to true or run the deployer with the --accept-all-licenses flag" diff --git a/automation-roles/60-configure-cloud-pak/cp4d/cp4d-instance-dmc/tasks/main.yml b/automation-roles/60-configure-cloud-pak/cp4d/cp4d-instance-dmc/tasks/main.yml index e6f63c291..4fbef2730 100644 --- a/automation-roles/60-configure-cloud-pak/cp4d/cp4d-instance-dmc/tasks/main.yml +++ b/automation-roles/60-configure-cloud-pak/cp4d/cp4d-instance-dmc/tasks/main.yml @@ -35,7 +35,7 @@ - include_tasks: delete_dmc_instances.yml when: - (_p_wait_instances | default(False)) == False - - _surviving_cartridges | selectattr('CR_Kind','equalto',(_dmc_cartridge.CR_Kind | default(''))) | list | count == 0 + - "'dmc' not in _surviving_cartridges_names" - include_tasks: wait_dmc_instances.yml when: diff --git a/automation-roles/60-configure-cloud-pak/cp4d/cp4d-instance-openpages/tasks/main.yml b/automation-roles/60-configure-cloud-pak/cp4d/cp4d-instance-openpages/tasks/main.yml index 22fcab8ae..69752afab 100644 --- a/automation-roles/60-configure-cloud-pak/cp4d/cp4d-instance-openpages/tasks/main.yml +++ b/automation-roles/60-configure-cloud-pak/cp4d/cp4d-instance-openpages/tasks/main.yml @@ -34,7 +34,7 @@ - include_tasks: delete_openpages_instances.yml when: - (_p_wait_instances | default(False)) == False - - _surviving_cartridges | selectattr('CR_Kind','equalto',(_openpages_cartridge.CR_Kind | default(''))) | list | count == 0 + - "'openpages' not in _surviving_cartridges_names" - include_tasks: wait_openpages_instances.yml when: diff --git a/docker-scripts/env-command.sh b/docker-scripts/env-command.sh index 342f70a6e..e6a23dc09 100755 --- a/docker-scripts/env-command.sh +++ b/docker-scripts/env-command.sh @@ -6,49 +6,51 @@ echo "Entering Cloud Pak Deployer command line in a container." echo 'Use the "exit" command to leave the container and return to the hosting server.' echo "-------------------------------------------------------------------------------" -export PS1='\[\e]0;\w\a\]\n[\#] \[\e[32m\u@Cloud Pak Deployer:\[\e[33m\]\w \e[m\$ '; +# export PS1='\[\e]0;\w\a\]\n[\#] \[\e[32m\u@Cloud Pak Deployer:\[\e[33m\]\w \e[m\$ '; +export PS1="[\#] \e[0;32m[\u@Cloud Pak Deployer: \W] \e[m " # Get the public and private keys if existing -echo "Getting SSH keys from vault, if existing..." -TEMP_DIR=$(mktemp -d) -$SCRIPT_DIR/../cp-deploy.sh vault get -vs ocp-ssh-private-key -vsf $TEMP_DIR/id_rsa > /dev/null -$SCRIPT_DIR/../cp-deploy.sh vault get -vs ocp-ssh-pub-key -vsf $TEMP_DIR/id_rsa.pub > /dev/null - - -mkdir -p ~/.ssh -chmod 700 ~/.ssh - -if [[ ! -z $(grep '[^[:space:]]' $TEMP_DIR/id_rsa) ]];then - echo "Writing SSH keys to ~/.ssh..." - rm -f ~/.ssh/id_rsa - cp $TEMP_DIR/id_rsa ~/.ssh/id_rsa - chmod 600 ~/.ssh/id_rsa -fi +if grep -q ocp-ssh $STATUS_DIR/vault/* 2>&1;then + echo "Getting SSH keys from vault ..." + TEMP_DIR=$(mktemp -d) + $SCRIPT_DIR/../cp-deploy.sh vault get -vs ocp-ssh-private-key -vsf $TEMP_DIR/id_rsa > /dev/null + $SCRIPT_DIR/../cp-deploy.sh vault get -vs ocp-ssh-pub-key -vsf $TEMP_DIR/id_rsa.pub > /dev/null + + mkdir -p ~/.ssh + chmod 700 ~/.ssh + + if [[ ! -z $(grep '[^[:space:]]' $TEMP_DIR/id_rsa) ]];then + echo "Writing SSH keys to ~/.ssh..." + rm -f ~/.ssh/id_rsa + cp $TEMP_DIR/id_rsa ~/.ssh/id_rsa + chmod 600 ~/.ssh/id_rsa + fi -if [[ ! -z $(grep '[^[:space:]]' $TEMP_DIR/id_rsa.pub) ]];then - rm -f ~/.ssh/id_rsa.pub - cp $TEMP_DIR/id_rsa ~/.ssh/id_rsa.pub - chmod 600 ~/.ssh/id_rsa.pub + if [[ ! -z $(grep '[^[:space:]]' $TEMP_DIR/id_rsa.pub) ]];then + rm -f ~/.ssh/id_rsa.pub + cp $TEMP_DIR/id_rsa ~/.ssh/id_rsa.pub + chmod 600 ~/.ssh/id_rsa.pub + fi fi -oc_zip=$(find $STATUS_DIR/downloads/ -name "openshift-client*" | tail -1) -if [ "$oc_zip" != "" ];then - echo "Installing OpenShift client..." - tar xvzf $oc_zip -C /usr/local/bin --exclude='README.md' > /dev/null - if [ -e $STATUS_DIR/openshift/kubeconfig ];then - # Use a copy of the kubeconfig file so that the command line doesn't conflict with an active deployer - cp -f $STATUS_DIR/openshift/kubeconfig /tmp/kubeconfig - export KUBECONFIG=/tmp/kubeconfig - # Show the current context - oc_context=$(oc config current-context) - echo "Current OpenShift context: $oc_context" - else - echo "No existing OpenShift configuration found, you will need to login to OpenShift first." - fi +if [ -e $STATUS_DIR/openshift/kubeconfig ];then + # Copy the kubeconfig file to the one in use by olm utils + cp -f $STATUS_DIR/openshift/kubeconfig /opt/ansible/.kubeconfig + chmod 777 /opt/ansible/.kubeconfig + # Show the current context + oc_context=$(oc config current-context) + oc_api_endpoint=$(oc whoami --show-server) + oc_console_endpoint=$(oc whoami --show-console) + echo "Current OpenShift context : $oc_context" + echo "Current OpenShift API endpoint: $oc_api_endpoint" + echo "Current OpenShift console URL: $oc_console_endpoint" + echo else - echo "Warning: OpenShift client not found under $STATUS_DIR/downloads, oc command will not be available." + echo "No existing OpenShift configuration found, you will need to login to OpenShift first." fi +export PATH=${PATH}:/cloud-pak-deployer + /bin/bash exit 0 \ No newline at end of file