-
Notifications
You must be signed in to change notification settings - Fork 2
/
rolling-master.yml
111 lines (96 loc) · 4.25 KB
/
rolling-master.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
---
# This playbook restarts the masters one by one and waits for each to come up before moving to the next.
- name: Rolling restart of masters
hosts: moosefs_master
serial: 1
become: true
vars_files:
- "vars/moosefs-settings.yml"
- "vars/upgrade-settings.yml"
pre_tasks:
- name: Get MooseFS version
shell: "mfsmaster -v | cut -d' ' -f 2 | cut -d'-' -f 1"
register: moosefs_master_version
check_mode: false
changed_when: false
- name: Set MooseFS version
set_fact:
moosefs_version: "{{ moosefs_master_version.stdout }}"
- name: Check the list of connected master servers using mfscli
command: mfscli -SIM -H {{ moosefs_master_host }} -p -s ' '
register: moosefs_master_status_list
check_mode: false
changed_when: false
- name: Determine the current state of the master
set_fact:
moosefs_master_connected: "{{ moosefs_master_status_list.stdout_lines | select('search', ansible_default_ipv4.address) | length != 0 }}"
moosefs_master_version_match: "{{ moosefs_master_status_list.stdout_lines | select('search', ansible_default_ipv4.address) | select('search', moosefs_version) | length != 0 }}"
moosefs_master_upgrade_needed: "{{ moosefs_master_status_list.stdout_lines | select('search', ansible_default_ipv4.address) | select('search', moosefs_version) | length == 0 }}"
- name: Print the current state of the master
debug:
msg:
- "Connected? {{ moosefs_master_connected }}"
- "Version matches target? {{ moosefs_master_version_match }}"
- "Upgrade needed? {{ moosefs_master_upgrade_needed }}"
tasks:
- name: Restart master service
service:
name: moosefs-master
state: restarted
when:
- moosefs_restart_masters
- moosefs_master_upgrade_needed or moosefs_restart_masters_force
- not moosefs_pro
- name: Stop CE master service (PRO)
service:
name: moosefs-master
state: stopped
when:
- moosefs_restart_masters
- moosefs_master_upgrade_needed or moosefs_restart_masters_force
- moosefs_ce_to_pro_upgrade | default('false') | bool
- moosefs_pro
- name: Restart master service (PRO)
service:
name: moosefs-pro-master
state: restarted
when:
- moosefs_restart_masters
- moosefs_master_upgrade_needed or moosefs_restart_masters_force
- moosefs_pro
- name: Promote first master (PRO)
command:
cmd: "mfssupervisor -H {{ moosefs_master_host }} -f"
when:
- moosefs_ce_to_pro_upgrade | default('false') | bool
- moosefs_pro
post_tasks:
- name: Wait until this master is connected
command: mfscli -SIM -H {{ moosefs_master_host }} -p -s ' '
register: moosefs_master_status
check_mode: false
changed_when: false
retries: 1800
until: moosefs_master_status.stdout_lines | select('search', ansible_default_ipv4.address) | length != 0
- name: Check the list of connected master servers using mfscli
command: mfscli -SIM -H {{ moosefs_master_host }} -p -s ' '
register: moosefs_master_status_list
check_mode: false
changed_when: false
- name: Determine the current state of the master
set_fact:
moosefs_master_connected: "{{ moosefs_master_status_list.stdout_lines | select('search', ansible_default_ipv4.address) | length != 0 }}"
moosefs_master_version_match: "{{ moosefs_master_status_list.stdout_lines | select('search', ansible_default_ipv4.address) | select('search', moosefs_version) | length != 0 }}"
moosefs_master_upgrade_needed: "{{ moosefs_master_status_list.stdout_lines | select('search', ansible_default_ipv4.address) | select('search', moosefs_version) | length == 0 }}"
- name: Print the current state of the master
debug:
msg:
- "Connected? {{ moosefs_master_connected }}"
- "Version matches target? {{ moosefs_master_version_match }}"
- "Upgrade needed? {{ moosefs_master_upgrade_needed }}"
- name: Prevent moving on if there was an issue
assert:
that:
- moosefs_master_connected
- moosefs_master_version_match
- not moosefs_master_upgrade_needed