2014-09-05 03:14:11 +08:00
|
|
|
---
|
2019-01-30 17:11:26 +08:00
|
|
|
- name: check if monitor initial keyring already exists
|
|
|
|
command: >
|
2020-01-09 23:46:34 +08:00
|
|
|
{{ _container_exec_cmd | default('') }} ceph --cluster {{ cluster }} --name mon. -k
|
|
|
|
/var/lib/ceph/mon/{{ cluster }}-{{ hostvars[groups[mon_group_name][0] if running_mon is undefined else running_mon]['ansible_hostname'] }}/keyring
|
2019-01-30 17:11:26 +08:00
|
|
|
auth get-key mon.
|
|
|
|
register: initial_mon_key
|
|
|
|
run_once: True
|
2020-01-09 23:46:34 +08:00
|
|
|
delegate_to: "{{ groups[mon_group_name][0] if running_mon is undefined else running_mon }}"
|
2019-01-30 17:11:26 +08:00
|
|
|
when: ceph_current_status.fsid is defined
|
|
|
|
|
2015-07-17 00:42:12 +08:00
|
|
|
- name: generate monitor initial keyring
|
2019-08-14 17:10:12 +08:00
|
|
|
command: >
|
2020-01-09 23:46:34 +08:00
|
|
|
{{ hostvars[groups[mon_group_name][0] if running_mon is undefined else running_mon]['discovered_interpreter_python'] }} -c "import os ; import struct ;
|
2018-11-01 19:50:31 +08:00
|
|
|
import time; import base64 ; key = os.urandom(16) ;
|
|
|
|
header = struct.pack('<hiih',1,int(time.time()),0,len(key)) ;
|
2018-11-16 17:50:38 +08:00
|
|
|
print(base64.b64encode(header + key).decode())"
|
2015-07-17 20:06:25 +08:00
|
|
|
register: monitor_keyring
|
2019-01-30 17:11:26 +08:00
|
|
|
run_once: True
|
2020-01-09 23:46:34 +08:00
|
|
|
delegate_to: "{{ groups[mon_group_name][0] if running_mon is undefined else running_mon }}"
|
2019-01-30 17:11:26 +08:00
|
|
|
when:
|
|
|
|
- initial_mon_key.skipped is defined
|
|
|
|
- ceph_current_status.fsid is undefined
|
2015-07-17 00:42:12 +08:00
|
|
|
|
2019-01-30 17:11:26 +08:00
|
|
|
- name: get initial keyring when it already exists
|
|
|
|
set_fact:
|
|
|
|
monitor_keyring: "{{ initial_mon_key.stdout if monitor_keyring.skipped is defined else monitor_keyring.stdout if initial_mon_key.skipped is defined }}"
|
2015-07-17 00:42:12 +08:00
|
|
|
|
2015-05-16 00:27:41 +08:00
|
|
|
- name: create monitor initial keyring
|
2018-04-04 22:22:36 +08:00
|
|
|
ceph_key:
|
|
|
|
name: mon.
|
|
|
|
state: present
|
|
|
|
dest: "/var/lib/ceph/tmp/"
|
2019-01-30 17:11:26 +08:00
|
|
|
secret: "{{ monitor_keyring }}"
|
2018-04-04 22:22:36 +08:00
|
|
|
cluster: "{{ cluster }}"
|
|
|
|
caps:
|
|
|
|
mon: allow *
|
|
|
|
import_key: False
|
2018-11-16 17:50:38 +08:00
|
|
|
owner: "{{ ceph_uid if containerized_deployment else 'ceph' }}"
|
|
|
|
group: "{{ ceph_uid if containerized_deployment else 'ceph' }}"
|
|
|
|
mode: "0400"
|
|
|
|
environment:
|
|
|
|
CEPH_CONTAINER_IMAGE: "{{ ceph_docker_registry + '/' + ceph_docker_image + ':' + ceph_docker_image_tag if containerized_deployment else None }}"
|
|
|
|
CEPH_CONTAINER_BINARY: "{{ container_binary }}"
|
2014-09-05 03:14:11 +08:00
|
|
|
|
2018-11-16 17:50:38 +08:00
|
|
|
- name: copy the initial key in /etc/ceph (for containers)
|
|
|
|
command: >
|
2019-01-30 17:11:26 +08:00
|
|
|
cp /var/lib/ceph/tmp/{{ cluster }}.mon..keyring
|
|
|
|
/etc/ceph/{{ cluster }}.mon.keyring
|
2018-11-16 17:50:38 +08:00
|
|
|
changed_when: false
|
2019-05-22 16:02:42 +08:00
|
|
|
when: containerized_deployment | bool
|
2015-11-17 23:10:02 +08:00
|
|
|
|
2017-06-30 16:17:23 +08:00
|
|
|
- name: create (and fix ownership of) monitor directory
|
2015-11-17 23:10:02 +08:00
|
|
|
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
|
2018-11-16 17:50:38 +08:00
|
|
|
owner: "{{ ceph_uid if containerized_deployment else 'ceph' }}"
|
|
|
|
group: "{{ ceph_uid if containerized_deployment else 'ceph' }}"
|
2018-08-01 20:37:40 +08:00
|
|
|
mode: "{{ ceph_directories_mode | default('0755') }}"
|
2017-06-30 16:17:23 +08:00
|
|
|
recurse: true
|
2015-11-17 23:10:02 +08:00
|
|
|
|
2017-07-05 17:07:00 +08:00
|
|
|
- name: create custom admin keyring
|
2018-04-04 22:22:36 +08:00
|
|
|
ceph_key:
|
|
|
|
name: client.admin
|
|
|
|
state: present
|
|
|
|
secret: "{{ admin_secret }}"
|
|
|
|
caps: "{{ client_admin_ceph_authtool_cap }}"
|
|
|
|
import_key: False
|
|
|
|
cluster: "{{ cluster }}"
|
2018-11-16 17:50:38 +08:00
|
|
|
owner: "{{ ceph_uid if containerized_deployment else 'ceph' }}"
|
|
|
|
group: "{{ ceph_uid if containerized_deployment else 'ceph' }}"
|
|
|
|
mode: "0400"
|
|
|
|
environment:
|
|
|
|
CEPH_CONTAINER_IMAGE: "{{ ceph_docker_registry + '/' + ceph_docker_image + ':' + ceph_docker_image_tag if containerized_deployment else None }}"
|
|
|
|
CEPH_CONTAINER_BINARY: "{{ container_binary }}"
|
2017-07-05 17:07:00 +08:00
|
|
|
register: create_custom_admin_secret
|
|
|
|
when:
|
2019-05-22 16:02:42 +08:00
|
|
|
- cephx | bool
|
2017-07-05 17:07:00 +08:00
|
|
|
- admin_secret != 'admin_secret'
|
|
|
|
|
2018-11-16 17:50:38 +08:00
|
|
|
- name: set_fact ceph-authtool container command
|
|
|
|
set_fact:
|
2019-02-01 05:17:20 +08:00
|
|
|
ceph_authtool_cmd: "{{ container_binary + ' run --net=host --rm -v /var/lib/ceph:/var/lib/ceph:z -v /etc/ceph/:/etc/ceph/:z --entrypoint=ceph-authtool ' + ceph_client_docker_registry + '/' + ceph_client_docker_image + ':' + ceph_client_docker_image_tag if containerized_deployment else 'ceph-authtool' }}"
|
2017-07-05 17:07:00 +08:00
|
|
|
|
|
|
|
- name: import admin keyring into mon keyring
|
2018-11-16 17:50:38 +08:00
|
|
|
command: >
|
|
|
|
{{ ceph_authtool_cmd }}
|
2019-01-16 17:27:23 +08:00
|
|
|
/var/lib/ceph/tmp/{{ cluster }}.mon..keyring --import-keyring /etc/ceph/{{ cluster }}.client.admin.keyring
|
2017-07-05 17:07:00 +08:00
|
|
|
when:
|
2017-08-22 20:10:10 +08:00
|
|
|
- not create_custom_admin_secret.get('skipped')
|
2019-05-22 16:02:42 +08:00
|
|
|
- cephx | bool
|
2017-07-05 17:07:00 +08:00
|
|
|
- admin_secret != 'admin_secret'
|
|
|
|
|
2018-11-16 17:50:38 +08:00
|
|
|
- name: set_fact ceph-mon container command
|
|
|
|
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 else 'ceph-mon' }}"
|
|
|
|
|
2017-01-20 17:14:35 +08:00
|
|
|
- name: ceph monitor mkfs with keyring
|
2018-11-16 17:50:38 +08:00
|
|
|
command: >
|
|
|
|
{{ ceph_mon_cmd }}
|
|
|
|
--cluster {{ cluster }}
|
2019-02-08 23:05:20 +08:00
|
|
|
--setuser "{{ ceph_uid if containerized_deployment else 'ceph' }}"
|
|
|
|
--setgroup "{{ ceph_uid if containerized_deployment else 'ceph' }}"
|
2018-11-16 17:50:38 +08:00
|
|
|
--mkfs
|
|
|
|
-i {{ monitor_name }}
|
|
|
|
--fsid {{ fsid }}
|
|
|
|
--keyring /var/lib/ceph/tmp/{{ cluster }}.mon..keyring
|
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
|
|
|
|
2017-01-20 17:14:35 +08:00
|
|
|
- name: ceph monitor mkfs without keyring
|
2018-11-16 17:50:38 +08:00
|
|
|
command: >
|
|
|
|
{{ ceph_mon_cmd }}
|
|
|
|
--cluster {{ cluster }}
|
2019-02-08 23:05:20 +08:00
|
|
|
--setuser "{{ ceph_uid if containerized_deployment else 'ceph' }}"
|
|
|
|
--setgroup "{{ ceph_uid if containerized_deployment 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
|