Skip to content

Commit 1638776

Browse files
lkuchlanevallesp
authored andcommitted
[cinder] Add Ceph client config for RBD mirroring
Ensure the primary cluster includes the required Ceph client configuration to access the secondary cluster. This is necessary for successful RBD mirroring operations.
1 parent 9292182 commit 1638776

File tree

1 file changed

+80
-22
lines changed

1 file changed

+80
-22
lines changed

hooks/playbooks/enable_rbd_mirror_replication.yml

Lines changed: 80 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -48,13 +48,14 @@
4848
hosts: ceph_replication_targets
4949
become: true
5050
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
5752
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"
5859
tasks:
5960
# Add validation that cephadm is available
6061
- name: Verify cephadm is available
@@ -78,13 +79,13 @@
7879

7980
- name: Create bootstrap token (only on primary)
8081
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
8283
when: site_role == "primary"
8384
register: create_token_result
8485

8586
- name: Verify token file was created on primary
8687
ansible.builtin.stat:
87-
path: "{{ bootstrap_token_path_host }}"
88+
path: "/tmp/bootstrap_token_site"
8889
register: token_file_stat
8990
when: site_role == "primary"
9091

@@ -97,64 +98,121 @@
9798

9899
- name: Fetch token from primary
99100
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"
102103
flat: true
103104
when: site_role == "primary"
104105

105106
- name: Verify token file exists on controller (debug)
106107
ansible.builtin.stat:
107-
path: "{{ token_tmp_path }}"
108+
path: "/tmp/rbd_mirror_bootstrap_token"
108109
register: controller_token_stat
109110
delegate_to: localhost
110111
when: site_role == "secondary"
111112

112113
- name: Fail if token not available on controller
113114
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"
115116
when:
116117
- site_role == "secondary"
117118
- not controller_token_stat.stat.exists
118119

119120
- name: Copy token to secondary
120121
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"
126127
when: site_role == "secondary"
127128

128129
- name: Verify token file was copied to secondary
129130
ansible.builtin.stat:
130-
path: "{{ bootstrap_token_path_host }}"
131+
path: "/tmp/bootstrap_token_site"
131132
register: secondary_token_stat
132133
when: site_role == "secondary"
133134

134135
- name: Fail if token copy failed
135136
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"
137138
when:
138139
- site_role == "secondary"
139140
- not secondary_token_stat.stat.exists
140141

141142
- name: Import token (only on secondary) - using container path
142143
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
144145
when: site_role == "secondary"
145146
register: import_token_result
146147
failed_when: import_token_result.rc != 0
147148

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+
148192
# 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+
149207
- name: Clean up token file on remote hosts
150208
ansible.builtin.file:
151-
path: "{{ bootstrap_token_path_host }}"
209+
path: "/tmp/bootstrap_token_site"
152210
state: absent
153211
when: site_role in ['primary', 'secondary']
154212

155213
- name: Clean up controller file
156214
ansible.builtin.file:
157-
path: "{{ token_tmp_path }}"
215+
path: "/tmp/rbd_mirror_bootstrap_token"
158216
state: absent
159217
delegate_to: localhost
160218
run_once: true

0 commit comments

Comments
 (0)