2014-09-05 03:14:11 +08:00
|
|
|
---
|
2024-02-14 18:14:02 +08:00
|
|
|
- name: Cephx related tasks
|
2021-01-13 18:07:50 +08:00
|
|
|
when: cephx | bool
|
|
|
|
block:
|
2024-02-14 18:14:02 +08:00
|
|
|
- name: Check if monitor initial keyring already exists
|
2021-01-13 18:07:50 +08:00
|
|
|
ceph_key:
|
|
|
|
name: mon.
|
|
|
|
cluster: "{{ cluster }}"
|
|
|
|
user: mon.
|
2021-03-03 22:43:50 +08:00
|
|
|
user_key: "/var/lib/ceph/mon/{{ cluster }}-{{ hostvars[running_mon]['ansible_facts']['hostname'] }}/keyring"
|
2021-01-13 18:07:50 +08:00
|
|
|
output_format: json
|
|
|
|
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: initial_mon_key
|
2024-02-14 18:14:02 +08:00
|
|
|
run_once: true
|
2021-01-13 18:07:50 +08:00
|
|
|
delegate_to: "{{ running_mon }}"
|
2021-06-07 20:51:43 +08:00
|
|
|
failed_when: initial_mon_key.rc not in [0, 2]
|
2021-08-09 20:57:33 +08:00
|
|
|
no_log: "{{ no_log_on_ceph_key_tasks }}"
|
2021-01-13 18:07:50 +08:00
|
|
|
when: running_mon is defined
|
2019-01-30 17:11:26 +08:00
|
|
|
|
2024-02-14 18:14:02 +08:00
|
|
|
- name: Generate monitor initial keyring
|
2021-01-13 18:07:50 +08:00
|
|
|
ceph_key:
|
|
|
|
state: generate_secret
|
|
|
|
register: monitor_keyring
|
|
|
|
delegate_to: localhost
|
|
|
|
become: false
|
|
|
|
run_once: true
|
2021-08-09 20:57:33 +08:00
|
|
|
no_log: "{{ no_log_on_ceph_key_tasks }}"
|
2021-06-07 20:51:43 +08:00
|
|
|
when:
|
|
|
|
- initial_mon_key is skipped
|
|
|
|
or
|
|
|
|
initial_mon_key is not succeeded
|
|
|
|
|
2024-02-14 18:14:02 +08:00
|
|
|
- name: Set_fact _initial_mon_key_success
|
|
|
|
ansible.builtin.set_fact: # when initial_mon_key is registered above, `rc: 2` is considered success.
|
2021-06-07 20:51:43 +08:00
|
|
|
_initial_mon_key_success: "{{ initial_mon_key is not skipped and initial_mon_key.rc == 0 }}"
|
2015-07-17 00:42:12 +08:00
|
|
|
|
2024-02-14 18:14:02 +08:00
|
|
|
- name: Get initial keyring when it already exists
|
|
|
|
ansible.builtin.set_fact:
|
2021-06-07 20:51:43 +08:00
|
|
|
monitor_keyring: "{{ (initial_mon_key.stdout | from_json)[0]['key'] if _initial_mon_key_success | bool else monitor_keyring.stdout }}"
|
2020-10-19 17:23:59 +08:00
|
|
|
when: initial_mon_key.stdout|default('')|length > 0 or monitor_keyring is not skipped
|
2021-08-12 04:01:08 +08:00
|
|
|
no_log: "{{ no_log_on_ceph_key_tasks }}"
|
2015-07-17 00:42:12 +08:00
|
|
|
|
2024-02-14 18:14:02 +08:00
|
|
|
- name: Create monitor initial keyring
|
2021-01-13 18:07:50 +08:00
|
|
|
ceph_key:
|
|
|
|
name: mon.
|
|
|
|
dest: "/var/lib/ceph/tmp/"
|
|
|
|
secret: "{{ monitor_keyring }}"
|
|
|
|
cluster: "{{ cluster }}"
|
|
|
|
caps:
|
|
|
|
mon: allow *
|
2024-02-14 18:14:02 +08:00
|
|
|
import_key: false
|
2021-01-13 18:07:50 +08:00
|
|
|
owner: "{{ ceph_uid if containerized_deployment | bool else 'ceph' }}"
|
|
|
|
group: "{{ ceph_uid if containerized_deployment | bool else 'ceph' }}"
|
|
|
|
mode: "0400"
|
2021-08-09 20:57:33 +08:00
|
|
|
no_log: "{{ no_log_on_ceph_key_tasks }}"
|
2021-01-13 18:07:50 +08:00
|
|
|
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 }}"
|
2014-09-05 03:14:11 +08:00
|
|
|
|
2024-02-14 18:14:02 +08:00
|
|
|
- name: Copy the initial key in /etc/ceph (for containers)
|
|
|
|
ansible.builtin.copy:
|
2021-01-13 18:07:50 +08:00
|
|
|
src: /var/lib/ceph/tmp/{{ cluster }}.mon..keyring
|
|
|
|
dest: /etc/ceph/{{ cluster }}.mon.keyring
|
|
|
|
remote_src: true
|
2024-02-14 18:14:02 +08:00
|
|
|
mode: "0640"
|
2021-01-13 18:07:50 +08:00
|
|
|
when: containerized_deployment | bool
|
2015-11-17 23:10:02 +08:00
|
|
|
|
2024-02-14 18:14:02 +08:00
|
|
|
- name: Create monitor directory
|
|
|
|
ansible.builtin.file:
|
2016-03-29 21:37:31 +08:00
|
|
|
path: /var/lib/ceph/mon/{{ cluster }}-{{ monitor_name }}
|
2015-11-17 23:10:02 +08:00
|
|
|
state: directory
|
2020-09-26 00:15:02 +08:00
|
|
|
owner: "{{ ceph_uid if containerized_deployment | bool else 'ceph' }}"
|
|
|
|
group: "{{ ceph_uid if containerized_deployment | bool else 'ceph' }}"
|
2020-01-21 22:30:16 +08:00
|
|
|
mode: "{{ ceph_directories_mode }}"
|
2020-10-28 23:09:58 +08:00
|
|
|
|
|
|
|
# We don't do the recursion in the task above to avoid setting `mode` (which
|
|
|
|
# defaults to 0755) on files.
|
|
|
|
#
|
|
|
|
# This is only needed when upgrading from older versions of Ceph that used to
|
|
|
|
# run as `root` (https://github.com/ceph/ceph-ansible/issues/1635).
|
2024-02-14 18:14:02 +08:00
|
|
|
- name: Recursively fix ownership of monitor directory
|
|
|
|
ansible.builtin.file:
|
2020-10-28 23:09:58 +08:00
|
|
|
path: /var/lib/ceph/mon/{{ cluster }}-{{ monitor_name }}
|
|
|
|
state: directory
|
|
|
|
owner: "{{ ceph_uid if containerized_deployment | bool else 'ceph' }}"
|
|
|
|
group: "{{ ceph_uid if containerized_deployment | bool else 'ceph' }}"
|
2017-06-30 16:17:23 +08:00
|
|
|
recurse: true
|
2015-11-17 23:10:02 +08:00
|
|
|
|
2024-02-14 18:14:02 +08:00
|
|
|
- name: Create admin keyring
|
2023-08-04 15:53:40 +08:00
|
|
|
ceph_authtool:
|
2018-04-04 22:22:36 +08:00
|
|
|
name: client.admin
|
2023-08-04 15:53:40 +08:00
|
|
|
path: /etc/ceph/ceph.client.admin.keyring
|
2020-09-26 00:15:02 +08:00
|
|
|
owner: "{{ ceph_uid if containerized_deployment | bool else 'ceph' }}"
|
|
|
|
group: "{{ ceph_uid if containerized_deployment | bool else 'ceph' }}"
|
2018-11-16 17:50:38 +08:00
|
|
|
mode: "0400"
|
2023-08-04 15:53:40 +08:00
|
|
|
caps:
|
|
|
|
mon: allow *
|
|
|
|
mgr: allow *
|
|
|
|
osd: allow *
|
|
|
|
mds: allow *
|
2024-02-14 18:14:02 +08:00
|
|
|
create_keyring: true
|
2023-08-04 15:53:40 +08:00
|
|
|
gen_key: "{{ True if admin_secret == 'admin_secret' else omit }}"
|
|
|
|
add_key: "{{ admin_secret if admin_secret != 'admin_secret' else omit }}"
|
|
|
|
delegate_to: "{{ groups[mon_group_name][0] }}"
|
|
|
|
run_once: true
|
2018-11-16 17:50:38 +08:00
|
|
|
environment:
|
2020-09-26 00:15:02 +08:00
|
|
|
CEPH_CONTAINER_IMAGE: "{{ ceph_docker_registry + '/' + ceph_docker_image + ':' + ceph_docker_image_tag if containerized_deployment | bool else None }}"
|
2018-11-16 17:50:38 +08:00
|
|
|
CEPH_CONTAINER_BINARY: "{{ container_binary }}"
|
2021-08-09 20:57:33 +08:00
|
|
|
no_log: "{{ no_log_on_ceph_key_tasks }}"
|
2017-07-05 17:07:00 +08:00
|
|
|
when:
|
2019-05-22 16:02:42 +08:00
|
|
|
- cephx | bool
|
2017-07-05 17:07:00 +08:00
|
|
|
|
2023-08-04 15:53:40 +08:00
|
|
|
|
2024-02-14 18:14:02 +08:00
|
|
|
- name: Slurp admin keyring
|
|
|
|
ansible.builtin.slurp:
|
2023-08-04 15:53:40 +08:00
|
|
|
src: "/etc/ceph/{{ cluster }}.client.admin.keyring"
|
|
|
|
delegate_to: "{{ groups[mon_group_name][0] }}"
|
2024-02-14 18:14:02 +08:00
|
|
|
run_once: true
|
2023-08-04 15:53:40 +08:00
|
|
|
register: admin_keyring
|
|
|
|
|
2024-02-14 18:14:02 +08:00
|
|
|
- name: Copy admin keyring over to mons
|
|
|
|
ansible.builtin.copy:
|
2023-08-04 15:53:40 +08:00
|
|
|
dest: "{{ admin_keyring.source }}"
|
|
|
|
content: "{{ admin_keyring.content | b64decode }}"
|
|
|
|
owner: "{{ ceph_uid }}"
|
|
|
|
group: "{{ ceph_uid }}"
|
|
|
|
mode: "0600"
|
|
|
|
delegate_to: "{{ item }}"
|
|
|
|
loop: "{{ groups[mon_group_name] }}"
|
2024-03-08 05:41:58 +08:00
|
|
|
no_log: "{{ no_log_on_ceph_key_tasks }}"
|
2017-07-05 17:07:00 +08:00
|
|
|
|
2024-02-14 18:14:02 +08:00
|
|
|
- name: Import admin keyring into mon keyring
|
2023-08-04 15:53:40 +08:00
|
|
|
ceph_authtool:
|
|
|
|
path: "/var/lib/ceph/tmp/{{ cluster }}.mon..keyring"
|
|
|
|
owner: "{{ ceph_uid if containerized_deployment | bool else 'ceph' }}"
|
|
|
|
group: "{{ ceph_uid if containerized_deployment | bool else 'ceph' }}"
|
|
|
|
mode: "0400"
|
|
|
|
import_keyring: /etc/ceph/ceph.client.admin.keyring
|
|
|
|
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-03-08 05:41:58 +08:00
|
|
|
no_log: "{{ no_log_on_ceph_key_tasks }}"
|
2017-07-05 17:07:00 +08:00
|
|
|
when:
|
2019-05-22 16:02:42 +08:00
|
|
|
- cephx | bool
|
2017-07-05 17:07:00 +08:00
|
|
|
|
2024-02-14 18:14:02 +08:00
|
|
|
- name: Set_fact ceph-mon container command
|
|
|
|
ansible.builtin.set_fact:
|
|
|
|
ceph_mon_cmd: "{{ container_binary + ' run --rm --net=host -v /var/lib/ceph/:/var/lib/ceph:z -v /etc/ceph/:/etc/ceph/:z --entrypoint=ceph-mon ' + ceph_client_docker_registry + '/' + ceph_client_docker_image + ':' + ceph_client_docker_image_tag if containerized_deployment | bool else 'ceph-mon' }}"
|
2018-11-16 17:50:38 +08:00
|
|
|
|
2024-02-14 18:14:02 +08:00
|
|
|
- name: Set_fact monmaptool container command
|
|
|
|
ansible.builtin.set_fact:
|
|
|
|
ceph_monmaptool_cmd: "{{ container_binary + ' run --rm --net=host -v /var/lib/ceph/:/var/lib/ceph:z -v /etc/ceph/:/etc/ceph/:z --entrypoint=monmaptool ' + ceph_client_docker_registry + '/' + ceph_client_docker_image + ':' + ceph_client_docker_image_tag if containerized_deployment | bool else 'monmaptool' }}"
|
2023-08-04 15:53:40 +08:00
|
|
|
|
2024-02-14 18:14:02 +08:00
|
|
|
- name: Generate initial monmap
|
|
|
|
ansible.builtin.command: >
|
2023-08-04 15:53:40 +08:00
|
|
|
{{ ceph_monmaptool_cmd }}
|
|
|
|
--create
|
2024-02-16 21:20:22 +08:00
|
|
|
{% for name, addr in _monitor_addresses.items() -%}
|
2023-08-04 15:53:40 +08:00
|
|
|
--addv
|
2024-02-16 21:20:22 +08:00
|
|
|
{{ hostvars[name]['ansible_facts']['hostname'] }}
|
2023-08-04 15:53:40 +08:00
|
|
|
{% if mon_host_v1.enabled | bool %}
|
2024-02-16 21:20:22 +08:00
|
|
|
{% set _v1 = ',v1:' + addr + mon_host_v1.suffix %}
|
2023-08-04 15:53:40 +08:00
|
|
|
{% endif %}
|
2024-02-16 21:20:22 +08:00
|
|
|
[{{ "v2:" + addr + mon_host_v2.suffix }}{{ _v1 | default('') }}]
|
2023-08-04 15:53:40 +08:00
|
|
|
{# {%- if not loop.last -%},{%- endif %} #}
|
|
|
|
{%- endfor %}
|
|
|
|
--enable-all-features
|
|
|
|
--clobber /etc/ceph/monmap
|
|
|
|
args:
|
|
|
|
creates: /etc/ceph/monmap
|
|
|
|
|
2024-02-14 18:14:02 +08:00
|
|
|
- name: Ceph monitor mkfs with keyring
|
|
|
|
ansible.builtin.command: >
|
2018-11-16 17:50:38 +08:00
|
|
|
{{ ceph_mon_cmd }}
|
|
|
|
--cluster {{ cluster }}
|
2020-09-26 00:15:02 +08:00
|
|
|
--setuser "{{ ceph_uid if containerized_deployment | bool else 'ceph' }}"
|
|
|
|
--setgroup "{{ ceph_uid if containerized_deployment | bool else 'ceph' }}"
|
2018-11-16 17:50:38 +08:00
|
|
|
--mkfs
|
|
|
|
-i {{ monitor_name }}
|
|
|
|
--fsid {{ fsid }}
|
|
|
|
--keyring /var/lib/ceph/tmp/{{ cluster }}.mon..keyring
|
2023-08-04 15:53:40 +08:00
|
|
|
--monmap /etc/ceph/monmap
|
2015-11-17 23:10:02 +08:00
|
|
|
args:
|
2016-03-29 21:37:31 +08:00
|
|
|
creates: /var/lib/ceph/mon/{{ cluster }}-{{ monitor_name }}/keyring
|
2019-05-22 16:02:42 +08:00
|
|
|
when: cephx | bool
|
2014-09-05 03:14:11 +08:00
|
|
|
|
2024-02-14 18:14:02 +08:00
|
|
|
- name: Ceph monitor mkfs without keyring
|
|
|
|
ansible.builtin.command: >
|
2018-11-16 17:50:38 +08:00
|
|
|
{{ ceph_mon_cmd }}
|
|
|
|
--cluster {{ cluster }}
|
2020-09-26 00:15:02 +08:00
|
|
|
--setuser "{{ ceph_uid if containerized_deployment | bool else 'ceph' }}"
|
|
|
|
--setgroup "{{ ceph_uid if containerized_deployment | bool else 'ceph' }}"
|
2018-11-16 17:50:38 +08:00
|
|
|
--mkfs
|
|
|
|
-i {{ monitor_name }}
|
|
|
|
--fsid {{ fsid }}
|
2016-02-25 21:57:50 +08:00
|
|
|
args:
|
2016-03-29 21:37:31 +08:00
|
|
|
creates: /var/lib/ceph/mon/{{ cluster }}-{{ monitor_name }}/store.db
|
2019-05-22 16:02:42 +08:00
|
|
|
when: not cephx | bool
|