|
| 1 | +--- |
| 2 | +- name: Kustomize ControlPlane for cinder over NFS |
| 3 | + hosts: "{{ cifmw_target_hook_host | default('localhost') }}" |
| 4 | + gather_facts: false |
| 5 | + vars: |
| 6 | + cifmw_controlplane_kustomizations_path: "{{ cifmw_basedir }}/artifacts/manifests/kustomizations/controlplane" |
| 7 | + _cinder_nfs_secret_files: |
| 8 | + - cinder-volume-nfs-secrets.yaml |
| 9 | + - cinder-volume-nfs-secrets-2.yaml |
| 10 | + tasks: |
| 11 | + - name: Ensure the kustomizations dir exists |
| 12 | + ansible.builtin.file: |
| 13 | + path: "{{ cifmw_controlplane_kustomizations_path }}" |
| 14 | + state: directory |
| 15 | + |
| 16 | + - name: Create the cinder-backup OpenStackControlPlane configuration file |
| 17 | + ansible.builtin.copy: |
| 18 | + dest: "{{ cifmw_controlplane_kustomizations_path }}/cinder-backup.yaml" |
| 19 | + content: | |
| 20 | + apiVersion: core.openstack.org/v1beta1 |
| 21 | + kind: OpenStackControlPlane |
| 22 | + metadata: |
| 23 | + name: openstack |
| 24 | + spec: |
| 25 | + cinder: |
| 26 | + template: |
| 27 | + cinderBackup: |
| 28 | + replicas: 1 |
| 29 | + customServiceConfig: | |
| 30 | + [DEFAULT] |
| 31 | + backup_driver=cinder.backup.drivers.nfs.NFSBackupDriver |
| 32 | + backup_mount_options=nosharecache |
| 33 | + customServiceConfigSecrets: |
| 34 | + - cinder-backup-nfs-secrets |
| 35 | + networkAttachments: |
| 36 | + - storage |
| 37 | +
|
| 38 | + - name: Create the definition of the secrets for the cinder backup |
| 39 | + ansible.builtin.template: |
| 40 | + dest: "{{ cifmw_controlplane_kustomizations_path }}/cinder-backup-nfs-sercrets.yaml" |
| 41 | + src: "cinder-backup-nfs-secrets.yaml.j2" |
| 42 | + mode: '640' |
| 43 | + |
| 44 | + - name: Create the definition of the secrets |
| 45 | + vars: |
| 46 | + share: "{{ cifmw_nfs_shares[indx] }}" |
| 47 | + name: "{{ filename | splitext | first }}" |
| 48 | + ansible.builtin.template: |
| 49 | + dest: "{{ cifmw_controlplane_kustomizations_path }}/{{ filename }}" |
| 50 | + src: "cinder-volume-nfs-secrets.yaml.j2" |
| 51 | + mode: '640' |
| 52 | + loop: "{{ _cinder_nfs_secret_files }}" |
| 53 | + loop_control: |
| 54 | + loop_var: filename |
| 55 | + index_var: indx |
| 56 | + |
| 57 | + - name: Apply the secrets |
| 58 | + environment: |
| 59 | + KUBECONFIG: "{{ cifmw_openshift_kubeconfig }}" |
| 60 | + PATH: "{{ cifmw_path }}" |
| 61 | + ansible.builtin.shell: | |
| 62 | + oc project {{ namespace }} |
| 63 | + oc apply -f {{ cifmw_controlplane_kustomizations_path }}/{{ item }} |
| 64 | + register: apply_result |
| 65 | + changed_when: ('stdout' in apply_result) and ('unchanged' not in apply_result.stdout) |
| 66 | + failed_when: ( apply_result.rc | int ) > 1 |
| 67 | + loop: "{{ _cinder_nfs_secret_files + ['cinder-backup-nfs-sercrets.yaml'] }}" |
| 68 | + |
| 69 | + - name: Create the nfs backend cinderVolume patch |
| 70 | + ansible.builtin.template: |
| 71 | + dest: "{{ cifmw_controlplane_kustomizations_path }}/nfs_backend.yaml" |
| 72 | + src: "nfs_backend.yaml.j2" |
| 73 | + mode: '640' |
| 74 | + |
| 75 | + # FIXME: copy with inline content does not support templating, so this should be reworked |
| 76 | + - name: Create kustomization to really enable NFS shares as backends for cinder and cinder-backup |
| 77 | + ansible.builtin.copy: |
| 78 | + dest: "{{ cifmw_controlplane_kustomizations_path }}/90-cinder-nfs.yaml" |
| 79 | + content: |- |
| 80 | + apiVersion: kustomize.config.k8s.io/v1beta1 |
| 81 | + kind: Kustomization |
| 82 | + resources: |
| 83 | + namespace: {{ namespace }} |
| 84 | + # FIXME: patch the IP address of the NFS share using a better way to identify the exact volume |
| 85 | + patches: |
| 86 | + - target: |
| 87 | + kind: OpenStackControlPlane |
| 88 | + name: .* |
| 89 | + patch: |- |
| 90 | + - op: replace |
| 91 | + path: /metadata/name |
| 92 | + value: openstack |
| 93 | + - target: |
| 94 | + kind: OpenStackControlPlane |
| 95 | + name: .* |
| 96 | + patch: |- |
| 97 | + - op: remove |
| 98 | + path: /metadata/namespace |
| 99 | + - path: {{ cifmw_controlplane_kustomizations_path + '/nfs_backend.yaml'}} |
| 100 | + - path: {{ cifmw_controlplane_kustomizations_path + '/cinder-backup.yaml' }} |
0 commit comments