|
48 | 48 | hosts: ceph_replication_targets |
49 | 49 | become: true |
50 | 50 | vars: |
51 | | - # Host filesystem paths (what Ansible sees) |
52 | | - bootstrap_token_path_host: /tmp/bootstrap_token_site |
53 | | - token_tmp_path: /tmp/rbd_mirror_bootstrap_token |
54 | | - # Container filesystem paths (what cephadm container sees) |
55 | | - bootstrap_token_path_container: /rootfs/tmp/bootstrap_token_site |
56 | | - # Configurable pool name |
| 51 | + # Pool configuration |
57 | 52 | replication_pool: "{{ cifmw_replication_pool | default('volumes') }}" |
| 53 | + |
| 54 | + # Derived paths using cifmw variables directly |
| 55 | + primary_conf_path: "{{ cifmw_replication_ceph_conf_dir | default('/etc/ceph') }}/{{ cifmw_replication_primary_cluster }}.conf" |
| 56 | + primary_keyring_path: "{{ cifmw_replication_ceph_conf_dir | default('/etc/ceph') }}/{{ cifmw_replication_primary_cluster }}.client.{{ cifmw_replication_client_name | default('openstack') }}.keyring" |
| 57 | + secondary_conf_path: "{{ cifmw_replication_ceph_conf_dir | default('/etc/ceph') }}/{{ cifmw_replication_secondary_cluster }}.conf" |
| 58 | + secondary_keyring_path: "{{ cifmw_replication_ceph_conf_dir | default('/etc/ceph') }}/{{ cifmw_replication_secondary_cluster }}.client.{{ cifmw_replication_client_name | default('openstack') }}.keyring" |
58 | 59 | tasks: |
59 | 60 | # Add validation that cephadm is available |
60 | 61 | - name: Verify cephadm is available |
|
78 | 79 |
|
79 | 80 | - name: Create bootstrap token (only on primary) |
80 | 81 | ansible.builtin.shell: |
81 | | - cmd: cephadm shell -- sh -c "rbd mirror pool peer bootstrap create --site-name {{ ceph_fsid }} {{ replication_pool }}" > {{ bootstrap_token_path_host }} |
| 82 | + cmd: cephadm shell -- sh -c "rbd mirror pool peer bootstrap create --site-name {{ ceph_fsid }} {{ replication_pool }}" > /tmp/bootstrap_token_site |
82 | 83 | when: site_role == "primary" |
83 | 84 | register: create_token_result |
84 | 85 |
|
85 | 86 | - name: Verify token file was created on primary |
86 | 87 | ansible.builtin.stat: |
87 | | - path: "{{ bootstrap_token_path_host }}" |
| 88 | + path: "/tmp/bootstrap_token_site" |
88 | 89 | register: token_file_stat |
89 | 90 | when: site_role == "primary" |
90 | 91 |
|
|
97 | 98 |
|
98 | 99 | - name: Fetch token from primary |
99 | 100 | ansible.builtin.fetch: |
100 | | - src: "{{ bootstrap_token_path_host }}" |
101 | | - dest: "{{ token_tmp_path }}" |
| 101 | + src: "/tmp/bootstrap_token_site" |
| 102 | + dest: "/tmp/rbd_mirror_bootstrap_token" |
102 | 103 | flat: true |
103 | 104 | when: site_role == "primary" |
104 | 105 |
|
105 | 106 | - name: Verify token file exists on controller (debug) |
106 | 107 | ansible.builtin.stat: |
107 | | - path: "{{ token_tmp_path }}" |
| 108 | + path: "/tmp/rbd_mirror_bootstrap_token" |
108 | 109 | register: controller_token_stat |
109 | 110 | delegate_to: localhost |
110 | 111 | when: site_role == "secondary" |
111 | 112 |
|
112 | 113 | - name: Fail if token not available on controller |
113 | 114 | ansible.builtin.fail: |
114 | | - msg: "Bootstrap token file not found on controller at {{ token_tmp_path }}" |
| 115 | + msg: "Bootstrap token file not found on controller at /tmp/rbd_mirror_bootstrap_token" |
115 | 116 | when: |
116 | 117 | - site_role == "secondary" |
117 | 118 | - not controller_token_stat.stat.exists |
118 | 119 |
|
119 | 120 | - name: Copy token to secondary |
120 | 121 | ansible.builtin.copy: |
121 | | - src: "{{ token_tmp_path }}" |
122 | | - dest: "{{ bootstrap_token_path_host }}" |
123 | | - mode: '0600' |
124 | | - owner: root |
125 | | - group: root |
| 122 | + src: "/tmp/rbd_mirror_bootstrap_token" |
| 123 | + dest: "/tmp/bootstrap_token_site" |
| 124 | + mode: "0600" |
| 125 | + owner: "root" |
| 126 | + group: "root" |
126 | 127 | when: site_role == "secondary" |
127 | 128 |
|
128 | 129 | - name: Verify token file was copied to secondary |
129 | 130 | ansible.builtin.stat: |
130 | | - path: "{{ bootstrap_token_path_host }}" |
| 131 | + path: "/tmp/bootstrap_token_site" |
131 | 132 | register: secondary_token_stat |
132 | 133 | when: site_role == "secondary" |
133 | 134 |
|
134 | 135 | - name: Fail if token copy failed |
135 | 136 | ansible.builtin.fail: |
136 | | - msg: "Bootstrap token file was not copied to secondary at {{ bootstrap_token_path_host }}" |
| 137 | + msg: "Bootstrap token file was not copied to secondary at /tmp/bootstrap_token_site" |
137 | 138 | when: |
138 | 139 | - site_role == "secondary" |
139 | 140 | - not secondary_token_stat.stat.exists |
140 | 141 |
|
141 | 142 | - name: Import token (only on secondary) - using container path |
142 | 143 | ansible.builtin.command: |
143 | | - cmd: cephadm shell -- rbd mirror pool peer bootstrap import --site-name {{ ceph_fsid }} {{ replication_pool }} {{ bootstrap_token_path_container }} |
| 144 | + cmd: cephadm shell -- rbd mirror pool peer bootstrap import --site-name {{ ceph_fsid }} {{ replication_pool }} /rootfs/tmp/bootstrap_token_site |
144 | 145 | when: site_role == "secondary" |
145 | 146 | register: import_token_result |
146 | 147 | failed_when: import_token_result.rc != 0 |
147 | 148 |
|
| 149 | + # Copy configuration files from secondary to primary |
| 150 | + - name: Fetch secondary cluster conf from secondary |
| 151 | + ansible.builtin.fetch: |
| 152 | + src: "{{ secondary_conf_path }}" |
| 153 | + dest: "/tmp/{{ cifmw_replication_secondary_cluster }}.conf" |
| 154 | + flat: true |
| 155 | + when: site_role == "secondary" |
| 156 | + |
| 157 | + - name: Fetch secondary cluster keyring from secondary |
| 158 | + ansible.builtin.fetch: |
| 159 | + src: "{{ secondary_keyring_path }}" |
| 160 | + dest: "/tmp/{{ cifmw_replication_secondary_cluster }}.client.{{ cifmw_replication_client_name | default('openstack') }}.keyring" |
| 161 | + flat: true |
| 162 | + when: site_role == "secondary" |
| 163 | + |
| 164 | + - name: Copy secondary cluster conf to primary |
| 165 | + ansible.builtin.copy: |
| 166 | + src: "/tmp/{{ cifmw_replication_secondary_cluster }}.conf" |
| 167 | + dest: "{{ secondary_conf_path }}" |
| 168 | + mode: "0644" |
| 169 | + owner: "root" |
| 170 | + group: "root" |
| 171 | + when: site_role == "primary" |
| 172 | + |
| 173 | + - name: Copy secondary cluster keyring to primary |
| 174 | + ansible.builtin.copy: |
| 175 | + src: "/tmp/{{ cifmw_replication_secondary_cluster }}.client.{{ cifmw_replication_client_name | default('openstack') }}.keyring" |
| 176 | + dest: "{{ secondary_keyring_path }}" |
| 177 | + mode: "0600" |
| 178 | + owner: "ceph" |
| 179 | + group: "ceph" |
| 180 | + when: site_role == "primary" |
| 181 | + |
| 182 | + - name: Add client configuration to secondary cluster conf on primary |
| 183 | + ansible.builtin.blockinfile: |
| 184 | + path: "{{ secondary_conf_path }}" |
| 185 | + block: | |
| 186 | + [client.{{ cifmw_replication_client_name | default('openstack') }}] |
| 187 | + keyring = {{ secondary_keyring_path }} |
| 188 | + marker: "# {mark} ANSIBLE MANAGED BLOCK - client.{{ cifmw_replication_client_name | default('openstack') }}" |
| 189 | + create: false |
| 190 | + when: site_role == "primary" |
| 191 | + |
148 | 192 | # Cleanup files |
| 193 | + - name: Clean up temporary secondary cluster conf on controller |
| 194 | + ansible.builtin.file: |
| 195 | + path: "/tmp/{{ cifmw_replication_secondary_cluster }}.conf" |
| 196 | + state: absent |
| 197 | + delegate_to: localhost |
| 198 | + run_once: true |
| 199 | + |
| 200 | + - name: Clean up temporary secondary cluster keyring on controller |
| 201 | + ansible.builtin.file: |
| 202 | + path: "/tmp/{{ cifmw_replication_secondary_cluster }}.client.{{ cifmw_replication_client_name | default('openstack') }}.keyring" |
| 203 | + state: absent |
| 204 | + delegate_to: localhost |
| 205 | + run_once: true |
| 206 | + |
149 | 207 | - name: Clean up token file on remote hosts |
150 | 208 | ansible.builtin.file: |
151 | | - path: "{{ bootstrap_token_path_host }}" |
| 209 | + path: "/tmp/bootstrap_token_site" |
152 | 210 | state: absent |
153 | 211 | when: site_role in ['primary', 'secondary'] |
154 | 212 |
|
155 | 213 | - name: Clean up controller file |
156 | 214 | ansible.builtin.file: |
157 | | - path: "{{ token_tmp_path }}" |
| 215 | + path: "/tmp/rbd_mirror_bootstrap_token" |
158 | 216 | state: absent |
159 | 217 | delegate_to: localhost |
160 | 218 | run_once: true |
0 commit comments