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') }}"
|
|
|
|
- "{{ 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-22 22:43:01 +08:00
|
|
|
- name: install docker and dependencies for the docker module
|
|
|
|
package:
|
|
|
|
name: "{{ item }}"
|
|
|
|
state: present
|
|
|
|
with_items:
|
|
|
|
- python-docker-py
|
|
|
|
- python-urllib3
|
|
|
|
- docker
|
|
|
|
when: ansible_os_family == 'RedHat'
|
|
|
|
|
|
|
|
- name: install docker-py for the docker module
|
|
|
|
package:
|
|
|
|
name: "{{ item }}"
|
|
|
|
state: present
|
|
|
|
with_items:
|
|
|
|
- docker-py
|
|
|
|
- python-urllib3
|
|
|
|
- docker
|
|
|
|
when: ansible_os_family == 'Debian'
|
|
|
|
|
|
|
|
- name: start docker service
|
|
|
|
service:
|
|
|
|
name: docker
|
|
|
|
state: started
|
|
|
|
enabled: yes
|
|
|
|
|
|
|
|
- name: check if selinux is enabled
|
|
|
|
command: getenforce
|
|
|
|
register: sestatus
|
|
|
|
changed_when: false
|
|
|
|
when: ansible_os_family == 'RedHat'
|
|
|
|
|
|
|
|
- name: set selinux permissions
|
|
|
|
command: chcon -Rt svirt_sandbox_file_t "{{ item }}"
|
|
|
|
with_items:
|
|
|
|
- /etc/ceph
|
|
|
|
- /var/lib/ceph
|
|
|
|
changed_when: false
|
|
|
|
when:
|
|
|
|
- sestatus.stdout != 'Disabled'
|
|
|
|
- ansible_os_family == 'RedHat'
|
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-11-01 19:39:21 +08:00
|
|
|
restapi_group_name: restapis
|
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
|
|
|
|
|
2017-08-22 22:43:01 +08:00
|
|
|
pre_tasks:
|
|
|
|
- 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
|
|
|
|
|
|
|
|
- set_fact:
|
|
|
|
ceph_uid: 64045
|
|
|
|
when: ceph_docker_image_tag | match("latest") or ceph_docker_image_tag | search("ubuntu")
|
|
|
|
|
|
|
|
- set_fact:
|
|
|
|
ceph_uid: 167
|
|
|
|
when: ceph_docker_image_tag | search("centos") or ceph_docker_image | search("rhceph") or ceph_docker_image_tag | search("fedora")
|
|
|
|
|
|
|
|
- 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
|
|
|
|
|
|
|
|
roles:
|
|
|
|
- ceph-defaults
|
|
|
|
- ceph-docker-common
|
|
|
|
- ceph-mon
|
|
|
|
|
|
|
|
post_tasks:
|
|
|
|
- name: waiting for the containerized monitor to join the quorum...
|
|
|
|
shell: |
|
|
|
|
docker exec ceph-mon-{{ hostvars[mon_host]['ansible_hostname'] }} ceph --cluster {{ cluster }} -s -f json | python -c 'import sys, json; print(json.load(sys.stdin)["quorum_names"])'
|
|
|
|
register: result
|
|
|
|
until: "{{ ansible_hostname in result.stdout }}"
|
|
|
|
retries: "{{ health_mon_check_retries }}"
|
|
|
|
delay: "{{ health_mon_check_delay }}"
|
|
|
|
delegate_to: "{{ mon_host }}"
|
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
|
|
|
|
|
|
|
|
|
2017-08-22 22:43:01 +08:00
|
|
|
pre_tasks:
|
|
|
|
- name: collect running osds
|
|
|
|
shell: |
|
|
|
|
systemctl list-units | grep "loaded active" | grep -Eo 'ceph-osd@[0-9]{1,2}.service'
|
|
|
|
register: running_osds
|
|
|
|
changed_when: false
|
|
|
|
|
|
|
|
- name: collect osd devices
|
|
|
|
shell: |
|
|
|
|
blkid | awk '/ceph data/ { sub ("1:", "", $1); print $1 }'
|
2017-07-25 23:54:26 +08:00
|
|
|
register: devices
|
2017-08-22 22:43:01 +08:00
|
|
|
changed_when: false
|
|
|
|
|
|
|
|
- name: stop non-containerized ceph osd(s)
|
|
|
|
service:
|
|
|
|
name: "{{ item }}"
|
|
|
|
state: stopped
|
|
|
|
enabled: no
|
|
|
|
with_items: "{{ running_osds.stdout_lines }}"
|
|
|
|
|
|
|
|
- set_fact:
|
|
|
|
ceph_uid: 64045
|
|
|
|
when: ceph_docker_image_tag | match("latest") or ceph_docker_image_tag | search("ubuntu")
|
|
|
|
|
|
|
|
- set_fact:
|
|
|
|
ceph_uid: 167
|
|
|
|
when: ceph_docker_image_tag | search("centos") or ceph_docker_image | search("rhceph") or ceph_docker_image_tag | search("fedora")
|
|
|
|
|
|
|
|
- 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-07-25 23:54:26 +08:00
|
|
|
with_items: "{{ devices.stdout_lines }}"
|
2017-08-22 22:43:01 +08:00
|
|
|
register: osd_running
|
|
|
|
|
|
|
|
- name: unmount all the osd directories
|
|
|
|
command: umount "{{ item.0 }}"1
|
|
|
|
changed_when: false
|
|
|
|
failed_when: false
|
|
|
|
with_together:
|
2017-07-25 23:54:26 +08:00
|
|
|
- "{{ devices.stdout_lines }}"
|
2017-08-22 22:43:01 +08:00
|
|
|
- "{{ osd_running.results }}"
|
|
|
|
when:
|
|
|
|
- item.1.get("rc", 0) != 0
|
|
|
|
|
2017-07-25 23:54:26 +08:00
|
|
|
- set_fact: devices={{ devices.stdout_lines }}
|
2017-08-22 22:43:01 +08:00
|
|
|
|
|
|
|
roles:
|
|
|
|
- ceph-defaults
|
|
|
|
- ceph-docker-common
|
|
|
|
- ceph-osd
|
|
|
|
|
|
|
|
post_tasks:
|
|
|
|
- name: waiting for clean pgs...
|
|
|
|
shell: |
|
|
|
|
test "[""$(docker exec ceph-mon-{{ hostvars[groups[mon_group_name][0]]['ansible_hostname'] }} ceph --cluster {{ cluster }} -s -f json | python -c 'import sys, json; print(json.load(sys.stdin)["pgmap"]["num_pgs"])')""]" = "$(docker exec ceph-mon-{{ hostvars[groups[mon_group_name][0]]['ansible_hostname'] }} ceph --cluster {{ cluster }} -s -f json | python -c 'import sys, json; print [ i["count"] for i in json.load(sys.stdin)["pgmap"]["pgs_by_state"] if i["state_name"] == "active+clean"]')"
|
|
|
|
register: result
|
|
|
|
until: result.rc == 0
|
|
|
|
retries: "{{ health_osd_check_retries }}"
|
|
|
|
delay: "{{ health_osd_check_delay }}"
|
|
|
|
delegate_to: "{{ groups[mon_group_name][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
|
|
|
|
|
|
|
serial: 1
|
|
|
|
become: true
|
|
|
|
|
2017-08-22 22:43:01 +08:00
|
|
|
pre_tasks:
|
|
|
|
- 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
|
|
|
|
when: ceph_docker_image_tag | match("latest") or ceph_docker_image_tag | search("ubuntu")
|
|
|
|
|
|
|
|
- set_fact:
|
|
|
|
ceph_uid: 167
|
|
|
|
when: ceph_docker_image_tag | search("centos") or ceph_docker_image | search("rhceph") or ceph_docker_image_tag | search("fedora")
|
|
|
|
|
|
|
|
- name: set proper ownership on ceph directories
|
|
|
|
file:
|
|
|
|
path: "{{ item }}"
|
|
|
|
owner: "{{ ceph_uid }}"
|
|
|
|
recurse: yes
|
|
|
|
with_items:
|
|
|
|
- /var/lib/ceph
|
|
|
|
- /etc/ceph
|
|
|
|
|
|
|
|
roles:
|
|
|
|
- ceph-defaults
|
|
|
|
- ceph-docker-common
|
|
|
|
- ceph-mds
|
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
|
|
|
|
|
|
|
serial: 1
|
|
|
|
become: true
|
|
|
|
|
2017-08-22 22:43:01 +08:00
|
|
|
pre_tasks:
|
|
|
|
- name: stop non-containerized ceph rgw(s)
|
|
|
|
service:
|
|
|
|
name: "ceph-rgw@{{ 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
|
|
|
|
when: ceph_docker_image_tag | match("latest") or ceph_docker_image_tag | search("ubuntu")
|
|
|
|
|
|
|
|
- set_fact:
|
|
|
|
ceph_uid: 167
|
|
|
|
when: ceph_docker_image_tag | search("centos") or ceph_docker_image | search("rhceph") or ceph_docker_image_tag | search("fedora")
|
|
|
|
|
|
|
|
- name: set proper ownership on ceph directories
|
|
|
|
file:
|
|
|
|
path: "{{ item }}"
|
|
|
|
owner: "{{ ceph_uid }}"
|
|
|
|
recurse: yes
|
|
|
|
with_items:
|
|
|
|
- /var/lib/ceph
|
|
|
|
- /etc/ceph
|
|
|
|
|
|
|
|
roles:
|
|
|
|
- ceph-defaults
|
|
|
|
- ceph-docker-common
|
|
|
|
- ceph-rgw
|
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
|
|
|
|
|
|
|
serial: 1
|
|
|
|
become: true
|
|
|
|
|
2017-08-22 22:43:01 +08:00
|
|
|
pre_tasks:
|
|
|
|
- name: stop non-containerized ceph rbd mirror(s)
|
|
|
|
service:
|
|
|
|
name: "ceph-rbd-mirror@{{ ansible_hostname }}"
|
|
|
|
state: stopped
|
|
|
|
enabled: no
|
|
|
|
|
|
|
|
- set_fact:
|
|
|
|
ceph_uid: 64045
|
|
|
|
when: ceph_docker_image_tag | match("latest") or ceph_docker_image_tag | search("ubuntu")
|
2016-09-14 23:53:30 +08:00
|
|
|
|
2017-08-22 22:43:01 +08:00
|
|
|
- set_fact:
|
|
|
|
ceph_uid: 167
|
|
|
|
when: ceph_docker_image_tag | search("centos") or ceph_docker_image | search("rhceph") or ceph_docker_image_tag | search("fedora")
|
|
|
|
|
|
|
|
- name: set proper ownership on ceph directories
|
|
|
|
file:
|
|
|
|
path: "{{ item }}"
|
|
|
|
owner: "{{ ceph_uid }}"
|
|
|
|
recurse: yes
|
|
|
|
with_items:
|
|
|
|
- /var/lib/ceph
|
|
|
|
- /etc/ceph
|
|
|
|
|
|
|
|
roles:
|
|
|
|
- ceph-defaults
|
|
|
|
- ceph-docker-common
|
|
|
|
- ceph-rbd-mirror
|
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
|
|
|
|
|
|
|
serial: 1
|
|
|
|
become: true
|
|
|
|
|
2017-08-22 22:43:01 +08:00
|
|
|
pre_tasks:
|
|
|
|
- name: stop non-containerized ceph nfs(s)
|
|
|
|
service:
|
|
|
|
name: "ceph-nfs@{{ ansible_hostname }}"
|
|
|
|
state: stopped
|
|
|
|
enabled: no
|
|
|
|
|
|
|
|
- set_fact:
|
|
|
|
ceph_uid: 64045
|
|
|
|
when: ceph_docker_image_tag | match("latest") or ceph_docker_image_tag | search("ubuntu")
|
|
|
|
|
|
|
|
- set_fact:
|
|
|
|
ceph_uid: 167
|
|
|
|
when: ceph_docker_image_tag | search("centos") or ceph_docker_image | search("rhceph") or ceph_docker_image_tag | search("fedora")
|
|
|
|
|
|
|
|
- name: set proper ownership on ceph directories
|
|
|
|
file:
|
|
|
|
path: "{{ item }}"
|
|
|
|
owner: "{{ ceph_uid }}"
|
|
|
|
recurse: yes
|
|
|
|
with_items:
|
|
|
|
- /var/lib/ceph
|
|
|
|
- /etc/ceph
|
|
|
|
|
|
|
|
roles:
|
|
|
|
- ceph-defaults
|
|
|
|
- ceph-docker-common
|
|
|
|
- ceph-nfs
|