2016-09-14 23:53:30 +08:00
---
# This playbook switches from non-containerized to containerized Ceph daemons
- name : confirm whether user really meant to switch from non-containerized to containerized ceph daemons
2019-04-01 23:46:15 +08:00
hosts : localhost
2016-09-14 23:53:30 +08:00
gather_facts : false
vars_prompt :
- name : ireallymeanit
prompt : Are you sure you want to switch from non-containerized to containerized ceph daemons?
default : 'no'
private : no
tasks :
2017-08-22 22:43:01 +08:00
- name : exit playbook, if user did not mean to switch from non-containerized to containerized daemons?
fail :
msg : >
"Exiting switch-from-non-containerized-to-containerized-ceph-daemons.yml playbook,
cluster did not switch from non-containerized to containerized ceph daemons.
To switch from non-containerized to containerized ceph daemons, either say 'yes' on the prompt or
or use `-e ireallymeanit=yes` on the command line when
invoking the playbook"
when : ireallymeanit != 'yes'
2016-09-14 23:53:30 +08:00
2018-11-20 00:13:37 +08:00
- name : gather facts
2016-09-14 23:53:30 +08:00
hosts :
2017-03-08 03:32:57 +08:00
- "{{ mon_group_name|default('mons') }}"
2017-09-05 21:18:01 +08:00
- "{{ mgr_group_name|default('mgrs') }}"
2017-03-08 03:32:57 +08:00
- "{{ osd_group_name|default('osds') }}"
- "{{ mds_group_name|default('mdss') }}"
- "{{ rgw_group_name|default('rgws') }}"
- "{{ rbdmirror_group_name|default('rbdmirrors') }}"
- "{{ nfs_group_name|default('nfss') }}"
2016-09-14 23:53:30 +08:00
become : true
tasks :
2017-08-25 20:36:07 +08:00
- name : gather and delegate facts
setup :
delegate_to : "{{ item }}"
delegate_facts : True
with_items : "{{ groups['all'] }}"
2016-09-14 23:53:30 +08:00
- name : switching from non-containerized to containerized ceph mon
vars :
2017-08-22 22:43:01 +08:00
health_mon_check_retries : 5
health_mon_check_delay : 15
containerized_deployment : true
2019-02-08 15:52:03 +08:00
switch_to_containers : True
2016-11-03 17:16:33 +08:00
mon_group_name : mons
2019-04-01 23:46:15 +08:00
hosts : "{{ mon_group_name|default('mons') }}"
2016-09-14 23:53:30 +08:00
serial : 1
become : true
2018-11-12 20:21:26 +08:00
pre_tasks :
2017-08-22 22:43:01 +08:00
- name : select a running monitor
set_fact : mon_host={{ item }}
with_items : "{{ groups[mon_group_name] }}"
when : item != inventory_hostname
- name : stop non-containerized ceph mon
service :
name : "ceph-mon@{{ ansible_hostname }}"
state : stopped
enabled : no
2019-02-12 17:56:28 +08:00
- name : remove old systemd unit files
file :
path : /usr/lib/systemd/system/{{ item }}
state : absent
with_items :
- ceph-mon@.service
- ceph-mon.target
2018-04-19 16:28:56 +08:00
- name : set_fact ceph_uid for ubuntu
set_fact :
2017-08-22 22:43:01 +08:00
ceph_uid : 64045
2018-10-06 06:56:45 +08:00
when : ceph_docker_image_tag | string is search("ubuntu")
2017-08-22 22:43:01 +08:00
2018-04-19 16:28:56 +08:00
- name : set_fact ceph_uid for red hat
set_fact :
2017-08-22 22:43:01 +08:00
ceph_uid : 167
2018-10-06 06:56:45 +08:00
when : ceph_docker_image_tag | string is match("latest") or ceph_docker_image_tag | string is search("centos") or ceph_docker_image_tag | string is search("fedora")
2018-04-19 16:28:56 +08:00
- name : set_fact ceph_uid for rhel
set_fact :
ceph_uid : 167
2018-10-06 06:53:40 +08:00
when : ceph_docker_image is search("rhceph")
2017-08-22 22:43:01 +08:00
- name : set proper ownership on ceph directories
file :
path : "{{ item }}"
owner : "{{ ceph_uid }}"
recurse : yes
with_items :
- /var/lib/ceph
- /etc/ceph
- name : check for existing old leveldb file extension (ldb)
shell : stat /var/lib/ceph/mon/*/store.db/*.ldb
changed_when : false
failed_when : false
register : ldb_files
- name : rename leveldb extension from ldb to sst
shell : rename -v .ldb .sst /var/lib/ceph/mon/*/store.db/*.ldb
changed_when : false
failed_when : false
when : ldb_files.rc == 0
2018-10-19 23:07:55 +08:00
- name : copy mon initial keyring in /etc/ceph to satisfy fetch config task in ceph-container-common
2018-10-03 19:39:35 +08:00
command : cp /var/lib/ceph/mon/{{ cluster }}-{{ ansible_hostname }}/keyring /etc/ceph/{{ cluster }}.mon.keyring
args :
creates : /etc/ceph/{{ cluster }}.mon.keyring
changed_when : false
failed_when : false
2018-11-12 20:21:26 +08:00
tasks :
2018-10-01 23:43:24 +08:00
- import_role :
name : ceph-defaults
2018-12-10 22:46:32 +08:00
- import_role :
name : ceph-facts
2018-10-01 23:43:24 +08:00
- import_role :
name : ceph-handler
2018-12-10 22:46:32 +08:00
2018-10-01 23:43:24 +08:00
- import_role :
2018-10-19 23:07:55 +08:00
name : ceph-container-common
2018-12-10 22:46:32 +08:00
2018-10-01 23:43:24 +08:00
- import_role :
name : ceph-mon
2018-10-19 23:07:55 +08:00
post_tasks :
2019-02-11 18:20:30 +08:00
- name : waiting for the monitor to join the quorum...
command : "{{ docker_exec_cmd }} ceph --cluster {{ cluster }} -s --format json"
2017-10-16 20:27:57 +08:00
register : ceph_health_raw
until : >
hostvars[mon_host]['ansible_hostname'] in (ceph_health_raw.stdout | from_json)["quorum_names"]
2017-08-22 22:43:01 +08:00
retries : "{{ health_mon_check_retries }}"
delay : "{{ health_mon_check_delay }}"
2016-09-14 23:53:30 +08:00
2017-09-05 21:18:01 +08:00
- name : switching from non-containerized to containerized ceph mgr
2019-04-01 23:46:15 +08:00
hosts : "{{ mgr_group_name|default('mgrs') }}"
2017-09-05 21:18:01 +08:00
vars :
containerized_deployment : true
mgr_group_name : mgrs
serial : 1
become : true
2018-11-12 20:21:26 +08:00
pre_tasks :
2018-01-06 02:37:36 +08:00
# failed_when: false is here because if we're
# working with a jewel cluster then ceph mgr
# will not exist
2017-09-05 21:18:01 +08:00
- name : stop non-containerized ceph mgr(s)
service :
name : "ceph-mgr@{{ ansible_hostname }}"
state : stopped
enabled : no
2018-01-06 02:37:36 +08:00
failed_when : false
2017-09-05 21:18:01 +08:00
2019-02-12 17:56:28 +08:00
- name : remove old systemd unit files
file :
path : /usr/lib/systemd/system/{{ item }}
state : absent
with_items :
- ceph-mgr@.service
- ceph-mgr.target
2017-09-05 21:18:01 +08:00
- set_fact :
ceph_uid : 64045
2018-10-06 06:56:45 +08:00
when : ceph_docker_image_tag | string is match("latest") or ceph_docker_image_tag | string is search("ubuntu")
2017-09-05 21:18:01 +08:00
- set_fact :
ceph_uid : 167
2018-10-06 06:56:45 +08:00
when : ceph_docker_image_tag | string is search("centos") or ceph_docker_image is search("rhceph") or ceph_docker_image_tag | string is search("fedora")
2017-09-05 21:18:01 +08:00
- name : set proper ownership on ceph directories
file :
path : "{{ item }}"
owner : "{{ ceph_uid }}"
recurse : yes
with_items :
- /var/lib/ceph
- /etc/ceph
2018-11-12 20:21:26 +08:00
tasks :
2018-10-01 23:43:24 +08:00
- import_role :
name : ceph-defaults
2018-12-10 22:46:32 +08:00
- import_role :
name : ceph-facts
2018-10-01 23:43:24 +08:00
- import_role :
name : ceph-handler
- import_role :
2018-10-19 23:07:55 +08:00
name : ceph-container-common
2018-10-01 23:43:24 +08:00
- import_role :
name : ceph-mgr
2017-09-05 21:18:01 +08:00
2016-09-14 23:53:30 +08:00
- name : switching from non-containerized to containerized ceph osd
vars :
2017-08-22 22:43:01 +08:00
health_osd_check_retries : 5
health_osd_check_delay : 15
containerized_deployment : true
2016-09-14 23:53:30 +08:00
osd_group_name : osds
2019-04-01 23:46:15 +08:00
hosts : "{{ osd_group_name|default('osds') }}"
2016-09-14 23:53:30 +08:00
serial : 1
become : true
2018-11-12 20:21:26 +08:00
pre_tasks :
2016-09-14 23:53:30 +08:00
2018-11-20 00:13:37 +08:00
- import_role :
name : ceph-defaults
2019-04-12 04:20:41 +08:00
- name : collect running osds
shell : |
systemctl list-units | grep "loaded active" | grep -Eo 'ceph-osd@[0-9]+.service|ceph-volume|ceph\.target'
register : running_osds
changed_when : false
failed_when : false
- name : stop/disable/mask non-containerized ceph osd(s) (if any)
systemd :
name : "{{ item }}"
state : stopped
enabled : no
with_items : "{{ running_osds.stdout_lines | default([])}}"
when : running_osds != []
2018-11-16 23:15:24 +08:00
- name : remove old ceph-osd systemd units
file :
path : "{{ item }}"
state : absent
with_items :
- /usr/lib/systemd/system/ceph-osd.target
- /usr/lib/systemd/system/ceph-osd@.service
- /usr/lib/systemd/system/ceph-volume@.service
2017-08-22 22:43:01 +08:00
- set_fact :
ceph_uid : 64045
2018-10-06 06:56:45 +08:00
when : ceph_docker_image_tag | string is match("latest") or ceph_docker_image_tag | string is search("ubuntu")
2017-08-22 22:43:01 +08:00
2018-04-25 20:20:35 +08:00
- name : set_fact ceph_uid for red hat
set_fact :
2017-08-22 22:43:01 +08:00
ceph_uid : 167
2018-10-06 06:56:45 +08:00
when : ceph_docker_image_tag | string is match("latest") or ceph_docker_image_tag | string is search("centos") or ceph_docker_image_tag | string is search("fedora")
2018-04-25 20:20:35 +08:00
- name : set_fact ceph_uid for rhel
set_fact :
ceph_uid : 167
2018-10-06 06:53:40 +08:00
when : ceph_docker_image is search("rhceph")
2017-08-22 22:43:01 +08:00
- name : set proper ownership on ceph directories
file :
path : "{{ item }}"
owner : "{{ ceph_uid }}"
recurse : yes
with_items :
- /var/lib/ceph
- /etc/ceph
- name : check for existing old leveldb file extension (ldb)
shell : stat /var/lib/ceph/osd/*/current/omap/*.ldb
changed_when : false
failed_when : false
register : ldb_files
- name : rename leveldb extension from ldb to sst
shell : rename -v .ldb .sst /var/lib/ceph/osd/*/current/omap/*.ldb
changed_when : false
failed_when : false
2019-04-01 23:46:15 +08:00
when : ldb_files.rc == 0
2017-08-22 22:43:01 +08:00
- name : check if containerized osds are already running
2018-11-19 21:58:03 +08:00
command : >
2018-11-20 00:13:37 +08:00
{{ container_binary }} ps --filter='name=ceph-osd'
2017-08-22 22:43:01 +08:00
changed_when : false
failed_when : false
register : osd_running
2018-11-19 21:58:03 +08:00
- name : get osd directories
command : >
ls -1 /var/lib/ceph/osd
register : osd_dirs
2018-04-19 20:45:03 +08:00
changed_when : false
2017-08-22 22:43:01 +08:00
- name : unmount all the osd directories
2018-11-19 21:58:03 +08:00
command : >
umount /var/lib/ceph/osd/{{ item }}
2017-08-22 22:43:01 +08:00
changed_when : false
failed_when : false
2019-04-01 23:46:15 +08:00
with_items : "{{ osd_dirs.stdout_lines }}"
when : osd_running.rc != 0
2017-08-22 22:43:01 +08:00
2018-11-12 20:21:26 +08:00
tasks :
2018-10-01 23:43:24 +08:00
- import_role :
name : ceph-defaults
2017-08-22 22:43:01 +08:00
2018-12-10 22:46:32 +08:00
- import_role :
name : ceph-facts
2018-10-01 23:43:24 +08:00
- import_role :
name : ceph-handler
- import_role :
2018-10-19 23:07:55 +08:00
name : ceph-container-common
2018-10-01 23:43:24 +08:00
- import_role :
name : ceph-osd
2018-11-12 20:21:26 +08:00
post_tasks :
2017-10-07 09:42:09 +08:00
- name : get num_pgs
2018-11-20 00:13:37 +08:00
command : >
{{ container_binary }} exec ceph-mon-{{ hostvars[groups[mon_group_name][0]]['ansible_hostname'] }} ceph --cluster {{ cluster }} -s --format json
2017-10-07 09:42:09 +08:00
register : ceph_pgs
delegate_to : "{{ groups[mon_group_name][0] }}"
2017-10-07 01:52:05 +08:00
- name : container - waiting for clean pgs...
2018-11-20 00:13:37 +08:00
command : >
{{ container_binary }} exec ceph-mon-{{ hostvars[groups[mon_group_name][0]]['ansible_hostname'] }} ceph --cluster {{ cluster }} -s --format json
2017-10-07 01:52:05 +08:00
register : ceph_health_post
until : >
2018-10-02 23:31:49 +08:00
(((ceph_health_post.stdout | from_json).pgmap.pgs_by_state | length) > 0)
2017-10-07 01:52:05 +08:00
and
2018-10-02 23:31:49 +08:00
(((ceph_health_post.stdout | from_json).pgmap.pgs_by_state | selectattr('state_name', 'search', '^active\\+clean') | map(attribute='count') | list | sum) == (ceph_pgs.stdout | from_json).pgmap.num_pgs)
2017-10-07 01:52:05 +08:00
delegate_to : "{{ groups[mon_group_name][0] }}"
2017-08-22 22:43:01 +08:00
retries : "{{ health_osd_check_retries }}"
delay : "{{ health_osd_check_delay }}"
2019-04-01 23:46:15 +08:00
when : (ceph_pgs.stdout | from_json).pgmap.num_pgs != 0
2016-09-14 23:53:30 +08:00
- name : switching from non-containerized to containerized ceph mds
2019-04-01 23:46:15 +08:00
hosts : "{{ mds_group_name|default('mdss') }}"
2016-09-14 23:53:30 +08:00
2017-08-25 20:36:07 +08:00
vars :
containerized_deployment : true
mds_group_name : mdss
2016-09-14 23:53:30 +08:00
serial : 1
become : true
2018-11-12 20:21:26 +08:00
pre_tasks :
2016-09-14 23:53:30 +08:00
2017-08-22 22:43:01 +08:00
- name : stop non-containerized ceph mds(s)
service :
name : "ceph-mds@{{ ansible_hostname }}"
state : stopped
enabled : no
2016-09-14 23:53:30 +08:00
2019-02-12 17:56:28 +08:00
- name : remove old systemd unit files
file :
path : /usr/lib/systemd/system/{{ item }}
state : absent
with_items :
- ceph-mds@.service
- ceph-mds.target
2017-08-22 22:43:01 +08:00
- set_fact :
ceph_uid : 64045
2018-10-06 06:56:45 +08:00
when : ceph_docker_image_tag | string is match("latest") or ceph_docker_image_tag | string is search("ubuntu")
2017-08-22 22:43:01 +08:00
- set_fact :
ceph_uid : 167
2018-10-06 06:56:45 +08:00
when : ceph_docker_image_tag | string is search("centos") or ceph_docker_image is search("rhceph") or ceph_docker_image_tag | string is search("fedora")
2017-08-22 22:43:01 +08:00
- name : set proper ownership on ceph directories
file :
path : "{{ item }}"
owner : "{{ ceph_uid }}"
recurse : yes
with_items :
- /var/lib/ceph
- /etc/ceph
2018-11-12 20:21:26 +08:00
tasks :
2018-10-01 23:43:24 +08:00
- import_role :
name : ceph-defaults
2018-12-10 22:46:32 +08:00
- import_role :
name : ceph-facts
2018-10-01 23:43:24 +08:00
- import_role :
name : ceph-handler
- import_role :
2018-10-19 23:07:55 +08:00
name : ceph-container-common
2018-10-01 23:43:24 +08:00
- import_role :
name : ceph-mds
2016-09-14 23:53:30 +08:00
- name : switching from non-containerized to containerized ceph rgw
2019-04-01 23:46:15 +08:00
hosts : "{{ rgw_group_name|default('rgws') }}"
2016-09-14 23:53:30 +08:00
2017-08-25 20:36:07 +08:00
vars :
containerized_deployment : true
rgw_group_name : rgws
2016-09-14 23:53:30 +08:00
serial : 1
become : true
2018-11-12 20:21:26 +08:00
pre_tasks :
2017-08-22 22:43:01 +08:00
- set_fact :
ceph_uid : 64045
2018-10-06 06:56:45 +08:00
when : ceph_docker_image_tag | string is match("latest") or ceph_docker_image_tag | string is search("ubuntu")
2017-08-22 22:43:01 +08:00
- set_fact :
ceph_uid : 167
2018-10-06 06:56:45 +08:00
when : ceph_docker_image_tag | string is search("centos") or ceph_docker_image is search("rhceph") or ceph_docker_image_tag | string is search("fedora")
2017-08-22 22:43:01 +08:00
- name : set proper ownership on ceph directories
file :
path : "{{ item }}"
owner : "{{ ceph_uid }}"
recurse : yes
with_items :
- /var/lib/ceph
- /etc/ceph
2018-11-12 20:21:26 +08:00
tasks :
2018-10-01 23:43:24 +08:00
- import_role :
name : ceph-defaults
2018-12-10 22:46:32 +08:00
- import_role :
name : ceph-facts
2019-02-12 21:03:39 +08:00
- name : stop non-containerized ceph rgw(s)
service :
name : "ceph-radosgw@rgw.{{ ansible_hostname }}.{{ item.instance_name }}"
state : stopped
enabled : no
with_items : "{{ rgw_instances }}"
- name : remove old systemd unit file
file :
path : /usr/lib/systemd/system/ceph-radosgw@.service
state : absent
2018-10-01 23:43:24 +08:00
- import_role :
name : ceph-handler
- import_role :
2018-10-19 23:07:55 +08:00
name : ceph-container-common
2018-10-01 23:43:24 +08:00
- import_role :
name : ceph-rgw
2016-09-14 23:53:30 +08:00
- name : switching from non-containerized to containerized ceph rbd-mirror
2019-04-01 23:46:15 +08:00
hosts : "{{ rbdmirror_group_name|default('rbdmirrors') }}"
2016-09-14 23:53:30 +08:00
2017-08-25 20:36:07 +08:00
vars :
containerized_deployment : true
rbdmirror_group_name : rbdmirrors
2016-09-14 23:53:30 +08:00
serial : 1
become : true
2018-11-12 20:21:26 +08:00
pre_tasks :
2017-08-22 22:43:01 +08:00
- name : stop non-containerized ceph rbd mirror(s)
service :
2017-08-25 20:36:07 +08:00
name : "ceph-rbd-mirror@rbd-mirror.{{ ansible_hostname }}"
2017-08-22 22:43:01 +08:00
state : stopped
enabled : no
2019-02-12 17:56:28 +08:00
- name : remove old systemd unit files
file :
path : /usr/lib/systemd/system/{{ item }}
state : absent
with_items :
- ceph-rbd-mirror@.service
- ceph-rbd-mirror.target
2017-08-22 22:43:01 +08:00
- set_fact :
ceph_uid : 64045
2018-10-06 06:56:45 +08:00
when : ceph_docker_image_tag | string is match("latest") or ceph_docker_image_tag | string is search("ubuntu")
2016-09-14 23:53:30 +08:00
2017-08-22 22:43:01 +08:00
- set_fact :
ceph_uid : 167
2018-10-06 06:56:45 +08:00
when : ceph_docker_image_tag | string is search("centos") or ceph_docker_image is search("rhceph") or ceph_docker_image_tag | string is search("fedora")
2017-08-22 22:43:01 +08:00
- name : set proper ownership on ceph directories
file :
path : "{{ item }}"
owner : "{{ ceph_uid }}"
recurse : yes
with_items :
- /var/lib/ceph
- /etc/ceph
2018-11-12 20:21:26 +08:00
tasks :
2018-10-01 23:43:24 +08:00
- import_role :
name : ceph-defaults
2018-12-10 22:46:32 +08:00
- import_role :
name : ceph-facts
2018-10-01 23:43:24 +08:00
- import_role :
name : ceph-handler
- import_role :
2018-10-19 23:07:55 +08:00
name : ceph-container-common
2018-10-01 23:43:24 +08:00
- import_role :
name : ceph-rbd-mirror
2016-09-14 23:53:30 +08:00
- name : switching from non-containerized to containerized ceph nfs
2019-04-01 23:46:15 +08:00
hosts : "{{ nfs_group_name|default('nfss') }}"
2016-09-14 23:53:30 +08:00
2017-08-25 20:36:07 +08:00
vars :
containerized_deployment : true
nfs_group_name : nfss
2016-09-14 23:53:30 +08:00
serial : 1
become : true
2018-11-12 20:21:26 +08:00
pre_tasks :
2016-09-14 23:53:30 +08:00
2018-01-06 02:42:16 +08:00
# failed_when: false is here because if we're
# working with a jewel cluster then ceph nfs
# will not exist
2017-08-22 22:43:01 +08:00
- name : stop non-containerized ceph nfs(s)
service :
2017-09-09 01:28:52 +08:00
name : nfs-ganesha
2017-08-22 22:43:01 +08:00
state : stopped
enabled : no
2018-01-06 02:42:16 +08:00
failed_when : false
2017-08-22 22:43:01 +08:00
- set_fact :
ceph_uid : 64045
2018-10-06 06:56:45 +08:00
when : ceph_docker_image_tag | string is match("latest") or ceph_docker_image_tag | string is search("ubuntu")
2017-08-22 22:43:01 +08:00
- set_fact :
ceph_uid : 167
2018-10-06 06:56:45 +08:00
when : ceph_docker_image_tag | string is search("centos") or ceph_docker_image is search("rhceph") or ceph_docker_image_tag | string is search("fedora")
2017-08-22 22:43:01 +08:00
- name : set proper ownership on ceph directories
file :
path : "{{ item }}"
owner : "{{ ceph_uid }}"
recurse : yes
with_items :
- /var/lib/ceph
- /etc/ceph
2018-11-12 20:21:26 +08:00
tasks :
2018-10-01 23:43:24 +08:00
- import_role :
name : ceph-defaults
2018-12-10 22:46:32 +08:00
- import_role :
name : ceph-facts
2018-10-01 23:43:24 +08:00
- import_role :
name : ceph-handler
- import_role :
2018-10-19 23:07:55 +08:00
name : ceph-container-common
2018-10-01 23:43:24 +08:00
- import_role :
name : ceph-nfs