From e0d1c66a591c7b7e66205c870ad624354e981dc1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Han?= Date: Tue, 31 May 2016 18:13:47 +0200 Subject: [PATCH 1/2] rolling-upgrade: cleanup and cosmetic MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit refactoring the current code to apply the default syntax style that is used in the entire playbook. Signed-off-by: Sébastien Han --- rolling_update.yml | 161 ++++++++++++++++++++++++++------------------- 1 file changed, 94 insertions(+), 67 deletions(-) diff --git a/rolling_update.yml b/rolling_update.yml index b0f02573b..18f9ab5de 100644 --- a/rolling_update.yml +++ b/rolling_update.yml @@ -1,6 +1,6 @@ --- # This playbook does a rolling update for all the Ceph services -# Change the value of serial: to adjust the number of server to be updated. +# Change the value of 'serial:' to adjust the number of server to be updated. # # The four roles that apply to the ceph hosts will be applied: ceph-common, # ceph-mon, ceph-osd and ceph-mds. So any changes to configuration, package updates, etc, @@ -9,18 +9,38 @@ # /!\ DO NOT FORGET TO CHANGE THE RELEASE VERSION FIRST! /!\ +- name: confirm whether user really meant to upgrade the cluster + hosts: localhost + + vars_prompt: + - name: ireallymeanit + prompt: Are you sure you want to upgrade the cluster? + default: 'no' + private: no + + tasks: + - name: exit playbook, if user did not mean to upgrade cluster + fail: + msg: > + "Exiting rolling_update.yml playbook, cluster was NOT upgraded. + To upgrade the cluster, either say 'yes' on the prompt or + or use `-e ireallymeanit=yes` on the command line when + invoking the playbook" + when: ireallymeanit != 'yes' + - hosts: all tasks: - debug: msg="gather facts on all hosts for following reference" - hosts: mons serial: 1 - sudo: True + become: True vars: upgrade_ceph_packages: True + mon_group_name: mons pre_tasks: - - name: Compress the store as much as possible + - name: compress the store as much as possible command: ceph tell mon.{{ ansible_hostname }} compact roles: @@ -28,41 +48,45 @@ - ceph-mon post_tasks: - - name: Check if sysvinit - stat: > - path=/etc/rc?.d/S??ceph - follow=yes + - name: check if sysvinit + stat: + path: /etc/rc?.d/S??ceph + follow: yes register: monsysvinit - - name: Check if upstart - stat: > - path=/var/lib/ceph/mon/ceph-{{ ansible_hostname }}/upstart + - name: check if upstart + stat: + path: /var/lib/ceph/mon/ceph-{{ ansible_hostname }}/upstart register: monupstart - - name: Restart the monitor after compaction (Upstart) - service: > - name=ceph-mon - state=restarted - args=id={{ ansible_hostname }} + - name: check if systemd + command: grep -sq systemd /proc/1/comm + register: is_systemd + + - name: restart the monitor after compaction (upstart) + service: + name: ceph-mon + state: restarted + args: id={{ ansible_hostname }} when: monupstart.stat.exists == True - - name: Restart the monitor after compaction (Sysvinit) - service: > - name=ceph - state=restarted + - name: restart the monitor after compaction (sysvinit) + service: + name: ceph + state: restarted when: monsysvinit.stat.exists == True - name: restart monitor(s) - service: > - name=ceph - state=restarted - args=mon + service: + name: ceph + state: restarted + args: mon when: not ansible_os_family == "RedHat" - name: restart monitor(s) - service: > - name=ceph - state=restarted + service: + name: ceph + state: restarted when: ansible_os_family == "RedHat" - name: select a running monitor @@ -70,8 +94,8 @@ with_items: groups.mons when: item != inventory_hostname - - name: Waiting for the monitor to join the quorum... - shell: > + - name: waiting for the monitor to join the quorum... + shell: | ceph -s | grep monmap | sed 's/.*quorum//' | egrep -sq {{ ansible_hostname }} register: result until: result.rc == 0 @@ -82,12 +106,13 @@ - hosts: osds serial: 1 - sudo: True + become: True vars: upgrade_ceph_packages: True + osd_group_name: osds pre_tasks: - - name: Set OSD flags + - name: set osd flags command: ceph osd set {{ item }} with_items: - noout @@ -100,30 +125,30 @@ - ceph-osd post_tasks: - - name: Check if sysvinit + - name: check if sysvinit shell: stat /var/lib/ceph/osd/ceph-*/sysvinit register: osdsysvinit failed_when: false - - name: Check if upstart + - name: check if upstart shell: stat /var/lib/ceph/osd/ceph-*/upstart register: osdupstart failed_when: false - - name: Gracefully stop the OSDs (Upstart) - service: > - name=ceph-osd-all - state=restarted + - name: gracefully stop the oss (upstart) + service: + name: ceph-osd-all + state: restarted when: osdupstart.rc == 0 - - name: Gracefully stop the OSDs (Sysvinit) - service: > - name=ceph - state=restarted + - name: gracefully stop the osds (sysvinit) + service: + name: ceph + state: restarted when: osdsysvinit.rc == 0 - - name: Waiting for clean PGs... - shell: > + - name: waiting for clean pgs... + shell: | test "$(ceph pg stat | sed 's/^.*pgs://;s/active+clean.*//;s/ //')" -eq "$(ceph pg stat | sed 's/pgs.*//;s/^.*://;s/ //')" && ceph health | egrep -sq "HEALTH_OK|HEALTH_WARN" register: result until: result.rc == 0 @@ -131,7 +156,7 @@ delay: 10 delegate_to: "{{ groups.mons[0] }}" - - name: Unset OSD flags + - name: unset osd flags command: ceph osd unset {{ item }} with_items: - noout @@ -142,45 +167,47 @@ - hosts: mdss serial: 1 - sudo: True + become: True vars: upgrade_ceph_packages: True + mds_group_name: mdss roles: - ceph-common - ceph-mds post_tasks: - - name: Check if sysvinit - stat: > - path=/var/lib/ceph/mon/ceph-{{ ansible_hostname }}/sysvinit + - name: check if sysvinit + stat: + path: /var/lib/ceph/mon/ceph-{{ ansible_hostname }}/sysvinit register: mdssysvinit - - name: Check if upstart - stat: > - path=/var/lib/ceph/mon/ceph-{{ ansible_hostname }}/upstart + - name: check if upstart + stat: + path: /var/lib/ceph/mon/ceph-{{ ansible_hostname }}/upstart register: mdsupstart - - name: Restart the metadata server (Upstart) - service: > - name=ceph-mds - state=restarted - args=id={{ ansible_hostname }} + - name: restart the metadata server (upstart) + service: + name: ceph-mds + state: restarted + args: id={{ ansible_hostname }} when: mdsupstart.stat.exists == True - - name: Restart the metadata server (Sysvinit) - service: > - name=ceph - state=restarted - args=mds + - name: restart the metadata server (sysvinit) + service: + name: ceph + state: restarted + args: mds when: mdssysvinit.stat.exists == True - hosts: rgws serial: 1 - sudo: True + become: True vars: upgrade_ceph_packages: True + rgw_group_name: rgws roles: - ceph-common @@ -188,17 +215,17 @@ post_tasks: - name: restart rados gateway server(s) - service: > - name={{ item }} - state=restarted + service: + name: {{ item }} + state: restarted with_items: - radosgw when: radosgw_frontend == 'civetweb' - name: restart rados gateway server(s) - service: > - name={{ item }} - state=restarted + service: + name: {{ item }} + state: restarted with_items: - apache2 - radosgw From 217ce3cad0de4a6be2fc15930b41ec41263f9e76 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Han?= Date: Wed, 15 Jun 2016 17:08:15 +0200 Subject: [PATCH 2/2] rolling update: add systemd support MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Sébastien Han --- rolling_update.yml | 137 +++++++++++++++++++++++---------------------- 1 file changed, 69 insertions(+), 68 deletions(-) diff --git a/rolling_update.yml b/rolling_update.yml index 18f9ab5de..bb0906875 100644 --- a/rolling_update.yml +++ b/rolling_update.yml @@ -28,9 +28,30 @@ invoking the playbook" when: ireallymeanit != 'yes' -- hosts: all +- hosts: + - mons + - osds + - mdss + - rgws + + become: True tasks: - - debug: msg="gather facts on all hosts for following reference" + - debug: msg="gather facts on all Ceph hosts for following reference" + - name: check if sysvinit + stat: + path: /etc/rc?.d/S??ceph + follow: yes + register: is_sysvinit + + - name: check if upstart + stat: + path: /var/lib/ceph/mon/ceph-{{ ansible_hostname }}/upstart + register: is_upstart + + - name: check if systemd + command: grep -sq systemd /proc/1/comm + register: is_systemd + - hosts: mons serial: 1 @@ -48,46 +69,25 @@ - ceph-mon post_tasks: - - name: check if sysvinit - stat: - path: /etc/rc?.d/S??ceph - follow: yes - register: monsysvinit - - - name: check if upstart - stat: - path: /var/lib/ceph/mon/ceph-{{ ansible_hostname }}/upstart - register: monupstart - - - name: check if systemd - command: grep -sq systemd /proc/1/comm - register: is_systemd - - - name: restart the monitor after compaction (upstart) + - name: restart ceph mons with upstart service: name: ceph-mon state: restarted args: id={{ ansible_hostname }} - when: monupstart.stat.exists == True + when: is_upstart.stat.exists == True - - name: restart the monitor after compaction (sysvinit) + - name: restart ceph mons with sysvinit service: name: ceph state: restarted - when: monsysvinit.stat.exists == True + when: is_sysvinit.stat.exists == True - - name: restart monitor(s) + - name: restart ceph mons with systemd service: - name: ceph + name: ceph-mon@{{ ansible_hostname }} state: restarted - args: mon - when: not ansible_os_family == "RedHat" - - - name: restart monitor(s) - service: - name: ceph - state: restarted - when: ansible_os_family == "RedHat" + enabled: yes + when: is_systemd - name: select a running monitor set_fact: mon_host={{ item }} @@ -125,27 +125,30 @@ - ceph-osd post_tasks: - - name: check if sysvinit - shell: stat /var/lib/ceph/osd/ceph-*/sysvinit - register: osdsysvinit - failed_when: false + - name: get osd numbers + shell: "if [ -d /var/lib/ceph/osd ] ; then ls /var/lib/ceph/osd | cut -d '-' -f 2 ; fi" + register: osd_ids + changed_when: false - - name: check if upstart - shell: stat /var/lib/ceph/osd/ceph-*/upstart - register: osdupstart - failed_when: false - - - name: gracefully stop the oss (upstart) + - name: restart ceph osds (upstart) service: name: ceph-osd-all state: restarted - when: osdupstart.rc == 0 + when: is_upstart.stat.exists == True - - name: gracefully stop the osds (sysvinit) + - name: restart ceph osds (sysvinit) service: name: ceph state: restarted - when: osdsysvinit.rc == 0 + when: is_sysvinit.stat.exists == True + + - name: restart ceph osds (systemd) + service: + name: ceph-osd@{{item}} + state: restarted + enabled: yes + with_items: "{{ osd_ids.stdout_lines }}" + when: is_systemd - name: waiting for clean pgs... shell: | @@ -177,30 +180,26 @@ - ceph-mds post_tasks: - - name: check if sysvinit - stat: - path: /var/lib/ceph/mon/ceph-{{ ansible_hostname }}/sysvinit - register: mdssysvinit - - - name: check if upstart - stat: - path: /var/lib/ceph/mon/ceph-{{ ansible_hostname }}/upstart - register: mdsupstart - - - name: restart the metadata server (upstart) + - name: restart ceph mdss with upstart service: name: ceph-mds state: restarted args: id={{ ansible_hostname }} - when: mdsupstart.stat.exists == True + when: is_upstart.stat.exists == True - - name: restart the metadata server (sysvinit) + - name: restart ceph mdss with sysvinit service: name: ceph state: restarted args: mds - when: mdssysvinit.stat.exists == True + when: is_sysvinit.stat.exists == True + - name: restart ceph mdss with systemd + service: + name: ceph-mds@{{ ansible_hostname }} + state: restarted + enabled: yes + when: is_systemd - hosts: rgws serial: 1 @@ -214,19 +213,21 @@ - ceph-rgw post_tasks: - - name: restart rados gateway server(s) + - name: restart ceph rgws with systemd service: - name: {{ item }} + name: ceph-radosgw@rgw.{{ ansible_hostname }} state: restarted - with_items: - - radosgw - when: radosgw_frontend == 'civetweb' + enabled: yes + when: is_systemd + + - name: restart ceph rgws with sysvinit + service: + name: radosgw + state: restarted + when: ansible_os_family != 'RedHat' - name: restart rados gateway server(s) service: - name: {{ item }} + name: ceph-radosgw state: restarted - with_items: - - apache2 - - radosgw - when: radosgw_frontend == 'apache' + when: ansible_os_family != 'RedHat'