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
hosts :
- localhost
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
- name : make sure docker is present and started
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
2016-11-03 17:16:33 +08:00
mon_group_name : mons
2016-09-14 23:53:30 +08:00
hosts :
2017-03-08 03:32:57 +08:00
- "{{ mon_group_name|default('mons') }}"
2016-09-14 23:53:30 +08:00
serial : 1
become : true
2018-10-01 23:43:24 +08:00
tasks :
# pre-tasks for following import -
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
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-10-01 23:43:24 +08:00
- import_role :
name : ceph-defaults
private : false
- import_role :
name : ceph-handler
private : false
- import_role :
2018-10-19 23:07:55 +08:00
name : ceph-container-common
2018-10-01 23:43:24 +08:00
private : false
- import_role :
name : ceph-mon
private : false
# post-tasks for preceding import -
2018-10-19 23:07:55 +08:00
post_tasks :
2017-08-25 20:36:07 +08:00
# We don't do a container test by running 'docker exec ...' since not all the monitors have switched to containers yet.
# Thus, we continue to use the 'ceph' binary from the host, there is no issue with that.
2017-10-16 20:27:57 +08:00
- name : non container | waiting for the monitor to join the quorum...
command : ceph --cluster "{{ cluster }}" -s --format json
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 }}"
delegate_to : "{{ mon_host }}"
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
hosts :
- "{{ mgr_group_name|default('mgrs') }}"
vars :
containerized_deployment : true
mgr_group_name : mgrs
serial : 1
become : true
2018-10-01 23:43:24 +08:00
tasks :
# pre-tasks for following import -
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
- 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-10-01 23:43:24 +08:00
- import_role :
name : ceph-defaults
private : false
- import_role :
name : ceph-handler
private : false
- import_role :
2018-10-19 23:07:55 +08:00
name : ceph-container-common
2018-10-01 23:43:24 +08:00
private : false
- import_role :
name : ceph-mgr
private : false
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
hosts :
2017-03-08 03:32:57 +08:00
- "{{ osd_group_name|default('osds') }}"
2016-09-14 23:53:30 +08:00
serial : 1
become : true
2018-10-01 23:43:24 +08:00
tasks :
2016-09-14 23:53:30 +08:00
2018-10-01 23:43:24 +08:00
# pre-tasks for following importing
2018-05-16 23:37:10 +08:00
- name : collect running osds and ceph-disk unit(s)
2017-08-22 22:43:01 +08:00
shell : |
2018-09-26 20:24:26 +08:00
systemctl list-units | grep "loaded active" | grep -Eo 'ceph-osd@[0-9]+.service|ceph-disk@dev-[a-z]{3,4}[0-9]{1}.service'
2017-08-22 22:43:01 +08:00
register : running_osds
changed_when : false
2017-09-08 17:30:45 +08:00
failed_when : false
2017-08-22 22:43:01 +08:00
- name : collect osd devices
shell : |
blkid | awk '/ceph data/ { sub ("1:", "", $1); print $1 }'
2017-09-07 15:16:31 +08:00
register : collect_devices
2017-08-22 22:43:01 +08:00
changed_when : false
2017-09-07 15:16:31 +08:00
when :
- devices is not defined or (devices is defined and devices == [])
- name : set devices
set_fact :
devices : "{{ collect_devices.stdout_lines | list }}"
when :
- collect_devices is defined
- not collect_devices.get("skipped")
- collect_devices != []
2017-08-22 22:43:01 +08:00
2018-05-16 23:37:10 +08:00
- name : stop/disable/mask non-containerized ceph osd(s) and ceph-disk units (if any)
2017-08-25 20:36:07 +08:00
systemd :
2017-08-22 22:43:01 +08:00
name : "{{ item }}"
state : stopped
enabled : no
2017-08-25 20:36:07 +08:00
masked : yes
2017-09-08 17:30:45 +08:00
with_items : "{{ running_osds.stdout_lines | default([])}}"
when : running_osds != []
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
when :
- ldb_files.rc == 0
- name : check if containerized osds are already running
shell : |
docker ps | grep -sq {{ item | regex_replace('/', '') }}
changed_when : false
failed_when : false
2017-09-07 15:16:31 +08:00
with_items : "{{ devices }}"
2017-08-22 22:43:01 +08:00
register : osd_running
2018-04-19 20:45:03 +08:00
- name : resolve device(s) path(s)
command : readlink -f {{ item }}
changed_when : false
with_items : "{{ devices }}"
register : devices_canonicalize
2017-08-22 22:43:01 +08:00
- name : unmount all the osd directories
2018-04-19 20:45:03 +08:00
command : umount "{{ item.0.stdout }}"1
2017-08-22 22:43:01 +08:00
changed_when : false
failed_when : false
with_together :
2018-04-19 20:45:03 +08:00
- "{{ devices_canonicalize.results }}"
2017-08-22 22:43:01 +08:00
- "{{ osd_running.results }}"
when :
- item.1.get("rc", 0) != 0
2018-10-01 23:43:24 +08:00
- import_role :
name : ceph-defaults
private : false
2017-08-22 22:43:01 +08:00
2018-10-01 23:43:24 +08:00
- import_role :
name : ceph-handler
private : false
- import_role :
2018-10-19 23:07:55 +08:00
name : ceph-container-common
2018-10-01 23:43:24 +08:00
private : false
- import_role :
name : ceph-osd
private : false
# post-task for preceding import -
2017-10-07 09:42:09 +08:00
- name : get num_pgs
command : docker exec ceph-mon-{{ hostvars[groups[mon_group_name][0]]['ansible_hostname'] }} ceph --cluster "{{ cluster }}" -s --format json
register : ceph_pgs
delegate_to : "{{ groups[mon_group_name][0] }}"
2017-10-07 01:52:05 +08:00
- name : container - waiting for clean pgs...
command : "docker exec ceph-mon-{{ hostvars[groups[mon_group_name][0]]['ansible_hostname'] }} ceph --cluster {{ cluster }} -s --format json"
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 }}"
2017-10-07 09:42:09 +08:00
when :
2017-10-08 20:45:48 +08:00
- (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
hosts :
2017-03-08 03:32:57 +08:00
- "{{ 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-10-01 23:43:24 +08:00
tasks :
2016-09-14 23:53:30 +08:00
2018-10-01 23:43:24 +08:00
# pre-tasks for following inmport
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
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-10-01 23:43:24 +08:00
- import_role :
name : ceph-defaults
private : false
- import_role :
name : ceph-handler
private : false
- import_role :
2018-10-19 23:07:55 +08:00
name : ceph-container-common
2018-10-01 23:43:24 +08:00
private : false
- import_role :
name : ceph-mds
private : false
2016-09-14 23:53:30 +08:00
- name : switching from non-containerized to containerized ceph rgw
hosts :
2017-03-08 03:32:57 +08:00
- "{{ 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-10-01 23:43:24 +08:00
tasks :
2016-09-14 23:53:30 +08:00
2018-10-01 23:43:24 +08:00
# pre-tasks for following import -
2017-08-22 22:43:01 +08:00
- name : stop non-containerized ceph rgw(s)
service :
2017-08-25 20:36:07 +08:00
name : "ceph-radosgw@rgw.{{ ansible_hostname }}"
2017-08-22 22:43:01 +08:00
state : stopped
enabled : no
2016-09-14 23:53:30 +08:00
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-10-01 23:43:24 +08:00
- import_role :
name : ceph-defaults
private : false
- import_role :
name : ceph-handler
private : false
- import_role :
2018-10-19 23:07:55 +08:00
name : ceph-container-common
2018-10-01 23:43:24 +08:00
private : false
- import_role :
name : ceph-rgw
private : false
2016-09-14 23:53:30 +08:00
- name : switching from non-containerized to containerized ceph rbd-mirror
hosts :
2017-03-08 03:32:57 +08:00
- "{{ 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-10-01 23:43:24 +08:00
tasks :
# pre-tasks for following import -
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
- 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-10-01 23:43:24 +08:00
- import_role :
name : ceph-defaults
private : false
- import_role :
name : ceph-handler
private : false
- import_role :
2018-10-19 23:07:55 +08:00
name : ceph-container-common
2018-10-01 23:43:24 +08:00
private : false
- import_role :
name : ceph-rbd-mirror
private : false
2016-09-14 23:53:30 +08:00
- name : switching from non-containerized to containerized ceph nfs
hosts :
2017-03-08 03:32:57 +08:00
- "{{ 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-10-01 23:43:24 +08:00
tasks :
2016-09-14 23:53:30 +08:00
2018-10-01 23:43:24 +08:00
# pre-tasks for following import -
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-10-01 23:43:24 +08:00
- import_role :
name : ceph-defaults
private : false
- import_role :
name : ceph-handler
private : false
- import_role :
2018-10-19 23:07:55 +08:00
name : ceph-container-common
2018-10-01 23:43:24 +08:00
private : false
- import_role :
name : ceph-nfs
private : false