|
| 1 | +--- |
| 2 | +- name: Gather NodeSet resource information |
| 3 | + kubernetes.core.k8s_info: |
| 4 | + kubeconfig: "{{ cifmw_openshift_kubeconfig }}" |
| 5 | + namespace: "openstack" |
| 6 | + api_key: "{{ cifmw_openshift_token | default(omit) }}" |
| 7 | + context: "{{ cifmw_openshift_context | default(omit) }}" |
| 8 | + kind: "OpenStackDataPlaneNodeSet" |
| 9 | + api_version: "dataplane.openstack.org/v1beta1" |
| 10 | + register: _cifmw_update_osdpns_all_info |
| 11 | + |
| 12 | +- name: Fail if no OSDPNS resources are found |
| 13 | + ansible.builtin.fail: |
| 14 | + msg: "No OSDPNS resources found in the 'openstack' namespace!" |
| 15 | + when: _cifmw_update_osdpns_all_info.resources | length == 0 |
| 16 | + |
| 17 | +- name: Choose the first OSDPNS resource |
| 18 | + ansible.builtin.set_fact: |
| 19 | + _cifmw_update_osdpns_info: "{{ _cifmw_update_osdpns_all_info.resources[0] }}" |
| 20 | + |
| 21 | +- name: Display which osdpns we're using |
| 22 | + ansible.builtin.debug: |
| 23 | + msg: "Found OSDPNS named: '{{ _cifmw_update_osdpns_info.metadata.name }}'" |
| 24 | + |
| 25 | +- name: Determine registry |
| 26 | + ansible.builtin.set_fact: |
| 27 | + cifmw_update_local_registry: >- |
| 28 | + {{ |
| 29 | + (cifmw_ci_gen_kustomize_values_ooi_image.split('/')[0]) |
| 30 | + if cifmw_ci_gen_kustomize_values_ooi_image is defined |
| 31 | + else 'quay.io' |
| 32 | + | trim |
| 33 | + }} |
| 34 | +
|
| 35 | +- name: Check if credentials exist |
| 36 | + ansible.builtin.set_fact: |
| 37 | + brew_username: "{{ login_username }}" |
| 38 | + brew_password: "{{ login_dict[login_username] }}" |
| 39 | + vars: |
| 40 | + login_dict: >- |
| 41 | + {{ |
| 42 | + _cifmw_update_osdpns_info.spec.nodeTemplate.ansible.ansibleVars. |
| 43 | + edpm_container_registry_logins[cifmw_update_local_registry] |
| 44 | + }} |
| 45 | + login_username: "{{ login_dict.keys()|list|first }}" |
| 46 | + when: |
| 47 | + - _cifmw_update_osdpns_info.spec.nodeTemplate.ansible.ansibleVars.edpm_container_registry_logins is defined |
| 48 | + - login_dict is defined |
| 49 | + - login_dict|length > 0 |
| 50 | + - cifmw_update_local_registry != 'quay.io' |
| 51 | + |
| 52 | +- name: Log in to registry when needed |
| 53 | + containers.podman.podman_login: |
| 54 | + # Hardcoded for now |
| 55 | + registry: "registry.redhat.io" |
| 56 | + username: "{{ brew_username }}" |
| 57 | + password: "{{ brew_password }}" |
| 58 | + when: |
| 59 | + - brew_username is defined |
| 60 | + - brew_password is defined |
| 61 | + - cifmw_update_local_registry != 'quay.io' |
| 62 | + |
| 63 | +- name: Retrieve the openstackclient Pod |
| 64 | + kubernetes.core.k8s_info: |
| 65 | + kubeconfig: "{{ cifmw_openshift_kubeconfig }}" |
| 66 | + namespace: "openstack" |
| 67 | + api_key: "{{ cifmw_openshift_token | default(omit) }}" |
| 68 | + context: "{{ cifmw_openshift_context | default(omit) }}" |
| 69 | + kind: "Pod" |
| 70 | + name: "openstackclient" |
| 71 | + register: _cifmw_update_openstackclient_pod |
| 72 | + |
| 73 | +- name: Fail if openstackclient Pod is not found |
| 74 | + ansible.builtin.fail: |
| 75 | + msg: "No openstackclient Pod found in the openstack namespace!" |
| 76 | + when: _cifmw_update_openstackclient_pod.resources | length == 0 |
| 77 | + |
| 78 | +- name: Set the openstackclient image fact |
| 79 | + ansible.builtin.set_fact: |
| 80 | + openstackclient_image: "{{ _cifmw_update_openstackclient_pod.resources[0].spec.containers[0].image }}" |
| 81 | + |
| 82 | +- name: Collect and save OpenStack config files |
| 83 | + ansible.builtin.include_tasks: collect_openstackclient_config.yml |
| 84 | + loop: |
| 85 | + - 'clouds.yaml' |
| 86 | + - 'secure.yaml' |
| 87 | + loop_control: |
| 88 | + label: "{{ item }}" |
| 89 | + |
| 90 | +- name: Create local openstack wrapper script |
| 91 | + ansible.builtin.copy: |
| 92 | + dest: "{{ cifmw_update_artifacts_basedir }}/openstack" |
| 93 | + mode: '0755' |
| 94 | + content: | |
| 95 | + #!/usr/bin/env bash |
| 96 | + set -euo pipefail |
| 97 | + OS_CLOUD=default /usr/bin/openstack --insecure "$@" |
| 98 | +
|
| 99 | +- name: Ensure lopenstackclient container is running |
| 100 | + containers.podman.podman_container: |
| 101 | + name: lopenstackclient |
| 102 | + image: "{{ openstackclient_image }}" |
| 103 | + state: started |
| 104 | + net: host |
| 105 | + volumes: |
| 106 | + - "{{ cifmw_update_artifacts_basedir }}/clouds.yaml:/home/cloud-admin/.config/openstack/clouds.yaml:ro,Z" |
| 107 | + - "{{ cifmw_update_artifacts_basedir }}/secure.yaml:/home/cloud-admin/.config/openstack/secure.yaml:ro,Z" |
| 108 | + - "{{ cifmw_update_artifacts_basedir }}/openstack:/home/cloud-admin/.local/bin/openstack:ro,Z" |
| 109 | + command: ['/usr/bin/sleep', 'infinity'] |
0 commit comments