|
| 1 | +--- |
| 2 | + # Copyright 2025 Red Hat, Inc. |
| 3 | + # All Rights Reserved. |
| 4 | + # |
| 5 | + # Licensed under the Apache License, Version 2.0 (the "License"); you may |
| 6 | + # not use this file except in compliance with the License. You may obtain |
| 7 | + # a copy of the License at |
| 8 | + # |
| 9 | + # http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | + # |
| 11 | + # Unless required by applicable law or agreed to in writing, software |
| 12 | + # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT |
| 13 | + # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the |
| 14 | + # License for the specific language governing permissions and limitations |
| 15 | + # under the License. |
| 16 | + |
| 17 | +- name: Create glance S3 RGW user and fetch object-store endpoint |
| 18 | + when: cifmw_edpm_deploy_hci | default('false') | bool |
| 19 | + block: |
| 20 | + - name: Refresh ceph_cli |
| 21 | + ansible.builtin.include_tasks: ceph_cli.yml |
| 22 | + vars: |
| 23 | + ceph_command: "radosgw-admin" |
| 24 | + |
| 25 | + - name: Wait for RGW daemons to be running |
| 26 | + ansible.builtin.command: |
| 27 | + cmd: "{{ cifmw_cephadm_ceph_cli }} orch ps --daemon-type rgw --format json" |
| 28 | + register: rgw_daemon_status |
| 29 | + become: true |
| 30 | + changed_when: false |
| 31 | + failed_when: false |
| 32 | + until: > |
| 33 | + rgw_daemon_status.rc == 0 and |
| 34 | + (rgw_daemon_status.stdout | default('[]') | from_json | default([], true)) | |
| 35 | + selectattr('status_desc', 'equalto', 'running') | |
| 36 | + list | length > 0 |
| 37 | + retries: 30 |
| 38 | + delay: 10 |
| 39 | + |
| 40 | + - name: Check if Ceph S3 glance user exists |
| 41 | + ansible.builtin.command: |
| 42 | + cmd: >- |
| 43 | + {{ cifmw_cephadm_ceph_cli }} user info --uid glance |
| 44 | + no_log: true |
| 45 | + become: true |
| 46 | + ignore_errors: true |
| 47 | + changed_when: false |
| 48 | + register: cifmw_ceph_s3_glance_user_check |
| 49 | + when: cifmw_cephadm_ceph_cli is defined |
| 50 | + |
| 51 | + - name: Create Ceph S3 glance user |
| 52 | + ansible.builtin.command: |
| 53 | + cmd: >- |
| 54 | + {{ cifmw_cephadm_ceph_cli }} user create |
| 55 | + --uid="glance" |
| 56 | + --display-name="Glance S3 User" |
| 57 | + become: true |
| 58 | + when: |
| 59 | + - cifmw_ceph_s3_glance_user_check is not skipped |
| 60 | + - cifmw_ceph_s3_glance_user_check.rc != 0 |
| 61 | + register: glance_rgw_user_create |
| 62 | + retries: 3 |
| 63 | + delay: 5 |
| 64 | + until: glance_rgw_user_create.rc == 0 |
| 65 | + |
| 66 | + - name: Get RGW glance user info |
| 67 | + ansible.builtin.command: |
| 68 | + cmd: >- |
| 69 | + {{ cifmw_cephadm_ceph_cli }} user info --uid="glance" |
| 70 | + become: true |
| 71 | + no_log: true |
| 72 | + changed_when: false |
| 73 | + register: ceph_rgw_glance_user_info |
| 74 | + |
| 75 | + - name: Show RGW daemon status on failure |
| 76 | + when: ceph_rgw_glance_user_info.rc != 0 |
| 77 | + block: |
| 78 | + - name: Get RGW daemon status for debugging |
| 79 | + ansible.builtin.command: |
| 80 | + cmd: "{{ cifmw_cephadm_ceph_cli }} orch ps --daemon-type rgw" |
| 81 | + become: true |
| 82 | + register: rgw_debug_status |
| 83 | + changed_when: false |
| 84 | + |
| 85 | + - name: Display RGW status |
| 86 | + ansible.builtin.debug: |
| 87 | + msg: "RGW daemon status: {{ rgw_debug_status.stdout }}" |
| 88 | + |
| 89 | + - name: Fail with context |
| 90 | + ansible.builtin.fail: |
| 91 | + msg: | |
| 92 | + Failed to fetch glance user info after creation. |
| 93 | + User creation result: {{ glance_rgw_user_create | default('not attempted') }} |
| 94 | + RGW daemon status shown above. |
| 95 | +
|
| 96 | + - name: Set facts RGW glance user |
| 97 | + ansible.builtin.set_fact: |
| 98 | + cifmw_ceph_s3_glance_user: "{{ ceph_rgw_glance_user_info.stdout | from_json }}" |
| 99 | + when: |
| 100 | + - ceph_rgw_glance_user_info is defined |
| 101 | + - ceph_rgw_glance_user_info.rc == 0 |
| 102 | + no_log: true |
| 103 | + |
| 104 | + - name: Get OpenStack internal object-store endpoints |
| 105 | + cifmw.general.ci_script: |
| 106 | + extra_args: |
| 107 | + KUBECONFIG: "{{ cifmw_openshift_kubeconfig }}" |
| 108 | + output_dir: "{{ cifmw_cephadm_basedir }}/artifacts" |
| 109 | + script: |- |
| 110 | + oc -n {{ cifmw_cephadm_ns }} rsh openstackclient openstack endpoint list --service object-store --interface internal -f value -c URL |
| 111 | + delegate_to: localhost |
| 112 | + register: object_store_endpoint_raw |
| 113 | + when: |
| 114 | + - cifmw_openshift_kubeconfig is defined |
| 115 | + - cifmw_cephadm_basedir is defined |
| 116 | + - cifmw_cephadm_rgw_s3_glance |
| 117 | + |
| 118 | + - name: Extract base URL without path |
| 119 | + ansible.builtin.set_fact: |
| 120 | + rgw_internal_url: >- |
| 121 | + {{ |
| 122 | + object_store_endpoint_raw.stdout |
| 123 | + | regex_replace('(/swift.*)$', '') |
| 124 | + }} |
0 commit comments