2014-09-05 03:14:11 +08:00
---
2019-01-30 17:11:26 +08:00
- name : check if monitor initial keyring already exists
2020-10-24 03:19:53 +08:00
ceph_key :
name : mon.
cluster : "{{ cluster }}"
user : mon.
user_key : "/var/lib/ceph/mon/{{ cluster }}-{{ hostvars[groups[mon_group_name][0] if running_mon is undefined else running_mon]['ansible_hostname'] }}/keyring"
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 }}"
2019-01-30 17:11:26 +08:00
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 :
2020-10-24 03:19:53 +08:00
monitor_keyring : "{{ (initial_mon_key.stdout | from_json)[0].key if monitor_keyring.skipped is defined else monitor_keyring.stdout if initial_mon_key.skipped is defined }}"
2020-10-19 17:23:59 +08:00
when : initial_mon_key is not skipped or monitor_keyring is not skipped
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.
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
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"
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 }}"
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
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 }}"
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
secret : "{{ admin_secret }}"
caps : "{{ client_admin_ceph_authtool_cap }}"
import_key : False
cluster : "{{ cluster }}"
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"
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 }}"
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 :
2020-09-26 00:15:02 +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 | bool 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 :
2020-09-26 00:15:02 +08:00
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
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 }}
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
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 }}
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