2016-04-04 06:35:09 +08:00
|
|
|
---
|
2024-02-14 18:14:02 +08:00
|
|
|
- name: Cephx tasks
|
2022-05-12 23:22:54 +08:00
|
|
|
when:
|
|
|
|
- cephx | bool
|
|
|
|
block:
|
2024-02-14 18:14:02 +08:00
|
|
|
- name: Get client.bootstrap-rbd-mirror from ceph monitor
|
2022-05-12 23:22:54 +08:00
|
|
|
ceph_key:
|
|
|
|
name: client.bootstrap-rbd-mirror
|
|
|
|
cluster: "{{ cluster }}"
|
|
|
|
output_format: plain
|
|
|
|
state: info
|
|
|
|
environment:
|
|
|
|
CEPH_CONTAINER_IMAGE: "{{ ceph_docker_registry + '/' + ceph_docker_image + ':' + ceph_docker_image_tag if containerized_deployment | bool else None }}"
|
|
|
|
CEPH_CONTAINER_BINARY: "{{ container_binary }}"
|
|
|
|
register: _bootstrap_rbd_mirror_key
|
|
|
|
delegate_to: "{{ groups.get(mon_group_name)[0] }}"
|
|
|
|
run_once: true
|
|
|
|
no_log: "{{ no_log_on_ceph_key_tasks }}"
|
|
|
|
|
2024-02-14 18:14:02 +08:00
|
|
|
- name: Ensure /var/lib/ceph/bootstrap-rbd-mirror exists
|
|
|
|
ansible.builtin.file:
|
2022-08-02 02:18:50 +08:00
|
|
|
path: /var/lib/ceph/bootstrap-rbd-mirror
|
|
|
|
state: directory
|
|
|
|
owner: "{{ ceph_uid if containerized_deployment | bool else 'ceph' }}"
|
|
|
|
group: "{{ ceph_uid if containerized_deployment | bool else 'ceph' }}"
|
2024-02-14 18:14:02 +08:00
|
|
|
mode: "0750"
|
2022-08-02 02:18:50 +08:00
|
|
|
|
2024-02-14 18:14:02 +08:00
|
|
|
- name: Copy ceph key(s)
|
|
|
|
ansible.builtin.copy:
|
2022-05-12 23:22:54 +08:00
|
|
|
dest: "/var/lib/ceph/bootstrap-rbd-mirror/{{ cluster }}.keyring"
|
|
|
|
content: "{{ _bootstrap_rbd_mirror_key.stdout + '\n' }}"
|
|
|
|
owner: "{{ ceph_uid if containerized_deployment | bool else 'ceph' }}"
|
|
|
|
group: "{{ ceph_uid if containerized_deployment | bool else 'ceph' }}"
|
|
|
|
mode: "{{ ceph_keyring_permissions }}"
|
|
|
|
no_log: "{{ no_log_on_ceph_key_tasks }}"
|
|
|
|
|
2024-02-14 18:14:02 +08:00
|
|
|
- name: Create rbd-mirror keyrings
|
2022-05-12 23:22:54 +08:00
|
|
|
ceph_key:
|
|
|
|
name: "{{ item.name }}"
|
|
|
|
cluster: "{{ cluster }}"
|
|
|
|
user: client.admin
|
|
|
|
user_key: "/etc/ceph/{{ cluster }}.client.admin.keyring"
|
|
|
|
caps:
|
|
|
|
mon: "profile rbd-mirror"
|
|
|
|
osd: "profile rbd"
|
|
|
|
dest: "{{ item.dest }}"
|
|
|
|
secret: "{{ item.secret | default(omit) }}"
|
|
|
|
import_key: true
|
|
|
|
owner: "{{ ceph_uid if containerized_deployment | bool else 'ceph' }}"
|
|
|
|
group: "{{ ceph_uid if containerized_deployment | bool else 'ceph' }}"
|
|
|
|
mode: "{{ ceph_keyring_permissions }}"
|
|
|
|
no_log: "{{ no_log_on_ceph_key_tasks }}"
|
|
|
|
environment:
|
|
|
|
CEPH_CONTAINER_IMAGE: "{{ ceph_docker_registry + '/' + ceph_docker_image + ':' + ceph_docker_image_tag if containerized_deployment | bool else None }}"
|
|
|
|
CEPH_CONTAINER_BINARY: "{{ container_binary }}"
|
|
|
|
delegate_to: "{{ groups.get(mon_group_name)[0] }}"
|
|
|
|
loop:
|
|
|
|
- { name: "client.rbd-mirror.{{ ansible_facts['hostname'] }}",
|
|
|
|
dest: "/etc/ceph/{{ cluster }}.client.rbd-mirror.{{ ansible_facts['hostname'] }}.keyring" }
|
|
|
|
- { name: "{{ ceph_rbd_mirror_local_user }}",
|
|
|
|
dest: "/etc/ceph/{{ cluster }}.{{ ceph_rbd_mirror_local_user }}.keyring",
|
|
|
|
secret: "{{ ceph_rbd_mirror_local_user_secret | default('') }}" }
|
|
|
|
|
2024-02-14 18:14:02 +08:00
|
|
|
- name: Get client.rbd-mirror keyring from ceph monitor
|
2022-05-12 23:22:54 +08:00
|
|
|
ceph_key:
|
|
|
|
name: "client.rbd-mirror.{{ ansible_facts['hostname'] }}"
|
|
|
|
cluster: "{{ cluster }}"
|
|
|
|
output_format: plain
|
|
|
|
state: info
|
|
|
|
environment:
|
|
|
|
CEPH_CONTAINER_IMAGE: "{{ ceph_docker_registry + '/' + ceph_docker_image + ':' + ceph_docker_image_tag if containerized_deployment | bool else None }}"
|
|
|
|
CEPH_CONTAINER_BINARY: "{{ container_binary }}"
|
|
|
|
register: _rbd_mirror_key
|
|
|
|
delegate_to: "{{ groups.get(mon_group_name)[0] }}"
|
|
|
|
no_log: "{{ no_log_on_ceph_key_tasks }}"
|
|
|
|
|
2024-02-14 18:14:02 +08:00
|
|
|
- name: Copy ceph key
|
|
|
|
ansible.builtin.copy:
|
2022-05-12 23:22:54 +08:00
|
|
|
dest: "/etc/ceph/{{ cluster }}.client.rbd-mirror.{{ ansible_facts['hostname'] }}.keyring"
|
|
|
|
content: "{{ _rbd_mirror_key.stdout + '\n' }}"
|
|
|
|
owner: "{{ ceph_uid if containerized_deployment | bool else 'ceph' }}"
|
|
|
|
group: "{{ ceph_uid if containerized_deployment | bool else 'ceph' }}"
|
|
|
|
mode: "{{ ceph_keyring_permissions }}"
|
|
|
|
no_log: false
|
|
|
|
|
2024-02-14 18:14:02 +08:00
|
|
|
- name: Start and add the rbd-mirror service instance
|
|
|
|
ansible.builtin.service:
|
2022-05-12 23:22:54 +08:00
|
|
|
name: "ceph-rbd-mirror@rbd-mirror.{{ ansible_facts['hostname'] }}"
|
|
|
|
state: started
|
2024-02-14 18:14:02 +08:00
|
|
|
enabled: true
|
|
|
|
masked: false
|
2022-05-12 23:22:54 +08:00
|
|
|
changed_when: false
|
|
|
|
when:
|
|
|
|
- not containerized_deployment | bool
|
|
|
|
- ceph_rbd_mirror_remote_user is defined
|
|
|
|
|
2024-02-14 18:14:02 +08:00
|
|
|
- name: Set_fact ceph_rbd_mirror_pools
|
|
|
|
ansible.builtin.set_fact:
|
2022-05-12 23:22:54 +08:00
|
|
|
ceph_rbd_mirror_pools:
|
|
|
|
- name: "{{ ceph_rbd_mirror_pool }}"
|
|
|
|
when: ceph_rbd_mirror_pools is undefined
|
|
|
|
|
2024-02-14 18:14:02 +08:00
|
|
|
- name: Create pool if it doesn't exist
|
2022-05-12 23:22:54 +08:00
|
|
|
ceph_pool:
|
|
|
|
name: "{{ item.name }}"
|
|
|
|
cluster: "{{ cluster }}"
|
|
|
|
pg_num: "{{ item.pg_num | default(omit) }}"
|
|
|
|
pgp_num: "{{ item.pgp_num | default(omit) }}"
|
|
|
|
size: "{{ item.size | default(omit) }}"
|
|
|
|
min_size: "{{ item.min_size | default(omit) }}"
|
|
|
|
pool_type: "{{ item.type | default('replicated') }}"
|
|
|
|
rule_name: "{{ item.rule_name | default(omit) }}"
|
|
|
|
erasure_profile: "{{ item.erasure_profile | default(omit) }}"
|
|
|
|
pg_autoscale_mode: "{{ item.pg_autoscale_mode | default(omit) }}"
|
|
|
|
target_size_ratio: "{{ item.target_size_ratio | default(omit) }}"
|
|
|
|
application: "{{ item.application | default('rbd') }}"
|
|
|
|
delegate_to: "{{ groups[mon_group_name][0] }}"
|
|
|
|
loop: "{{ ceph_rbd_mirror_pools }}"
|
|
|
|
environment:
|
|
|
|
CEPH_CONTAINER_IMAGE: "{{ ceph_docker_registry + '/' + ceph_docker_image + ':' + ceph_docker_image_tag if containerized_deployment | bool else None }}"
|
|
|
|
CEPH_CONTAINER_BINARY: "{{ container_binary }}"
|
|
|
|
|
2024-02-14 18:14:02 +08:00
|
|
|
- name: Enable mirroring on the pool
|
|
|
|
ansible.builtin.command: "{{ rbd_cmd }} --cluster {{ cluster }} mirror pool enable {{ item.name }} {{ ceph_rbd_mirror_mode }}"
|
2021-04-13 04:29:50 +08:00
|
|
|
register: result
|
2018-10-30 22:51:32 +08:00
|
|
|
changed_when: false
|
2022-05-12 23:22:54 +08:00
|
|
|
retries: 60
|
2021-04-13 04:29:50 +08:00
|
|
|
delay: 1
|
|
|
|
until: result is succeeded
|
2022-05-12 23:22:54 +08:00
|
|
|
loop: "{{ ceph_rbd_mirror_pools }}"
|
|
|
|
delegate_to: "{{ groups[mon_group_name][0] }}"
|
2019-09-05 02:35:20 +08:00
|
|
|
|
2024-02-14 18:14:02 +08:00
|
|
|
- name: Add mirroring peer
|
2022-05-12 23:22:54 +08:00
|
|
|
when: ceph_rbd_mirror_remote_user is defined
|
|
|
|
block:
|
2024-02-14 18:14:02 +08:00
|
|
|
- name: List mirroring peer
|
|
|
|
ansible.builtin.command: "{{ rbd_cmd }} --cluster {{ cluster }} mirror pool info {{ item.name }}"
|
2022-05-12 23:22:54 +08:00
|
|
|
changed_when: false
|
|
|
|
register: mirror_peer
|
|
|
|
loop: "{{ ceph_rbd_mirror_pools }}"
|
|
|
|
delegate_to: "{{ groups[mon_group_name][0] }}"
|
2019-10-15 23:32:40 +08:00
|
|
|
|
2024-02-14 18:14:02 +08:00
|
|
|
- name: Create a temporary file
|
|
|
|
ansible.builtin.tempfile:
|
2022-05-12 23:22:54 +08:00
|
|
|
path: /etc/ceph
|
|
|
|
state: file
|
|
|
|
suffix: _ceph-ansible
|
|
|
|
register: tmp_file
|
|
|
|
delegate_to: "{{ groups[mon_group_name][0] }}"
|
|
|
|
|
2024-02-14 18:14:02 +08:00
|
|
|
- name: Write secret to temporary file
|
|
|
|
ansible.builtin.copy:
|
2022-05-12 23:22:54 +08:00
|
|
|
dest: "{{ tmp_file.path }}"
|
|
|
|
content: "{{ ceph_rbd_mirror_remote_key }}"
|
2024-02-14 18:14:02 +08:00
|
|
|
mode: "0644"
|
2022-05-12 23:22:54 +08:00
|
|
|
delegate_to: "{{ groups[mon_group_name][0] }}"
|
|
|
|
|
2024-02-14 18:14:02 +08:00
|
|
|
- name: Add a mirroring peer
|
|
|
|
ansible.builtin.command: "{{ rbd_cmd }} --cluster {{ cluster }} mirror pool peer add {{ item.item.name }} {{ ceph_rbd_mirror_remote_user }}@{{ ceph_rbd_mirror_remote_cluster }} --remote-mon-host {{ ceph_rbd_mirror_remote_mon_hosts }} --remote-key-file {{ tmp_file.path }}"
|
2022-05-12 23:22:54 +08:00
|
|
|
changed_when: false
|
|
|
|
delegate_to: "{{ groups[mon_group_name][0] }}"
|
|
|
|
loop: "{{ mirror_peer.results }}"
|
2022-09-13 22:54:22 +08:00
|
|
|
run_once: true
|
2022-05-12 23:22:54 +08:00
|
|
|
when: ceph_rbd_mirror_remote_user not in item.stdout
|
|
|
|
|
2024-02-14 18:14:02 +08:00
|
|
|
- name: Rm temporary file
|
|
|
|
ansible.builtin.file:
|
2022-05-12 23:22:54 +08:00
|
|
|
path: "{{ tmp_file.path }}"
|
|
|
|
state: absent
|
|
|
|
delegate_to: "{{ groups[mon_group_name][0] }}"
|