|
71 | 71 | - groups[elasticstack_elasticsearch_group_name] | length > 1 |
72 | 72 | block: |
73 | 73 |
|
74 | | - # Usually we should not need this step. It's only there to recover from broken upgrade plays |
75 | | - # Without this step the cluster would never recover and the play would always fail |
76 | | - - name: Enable shard allocation for the cluster |
77 | | - ansible.builtin.uri: |
78 | | - url: "{{ elasticsearch_http_protocol }}://{{ elasticsearch_api_host }}:{{ elasticstack_elasticsearch_http_port }}/_cluster/settings" |
79 | | - method: PUT |
80 | | - body: '{ "persistent": { "cluster.routing.allocation.enable": null }}' |
81 | | - body_format: json |
82 | | - user: elastic |
83 | | - password: "{{ elasticstack_password.stdout }}" |
84 | | - validate_certs: no |
85 | | - register: response |
86 | | - # next line is boolean not string, so no quotes around true |
87 | | - # use python truthiness |
88 | | - until: "response.json.acknowledged == true" |
89 | | - retries: 5 |
90 | | - delay: 30 |
91 | | - |
92 | | - # this step is key!!! Don't restart more nodes |
93 | | - # until all shards have completed recovery |
94 | | - - name: Wait for cluster health to return to green |
95 | | - ansible.builtin.uri: |
96 | | - url: "{{ elasticsearch_http_protocol }}://{{ elasticsearch_api_host }}:{{ elasticstack_elasticsearch_http_port }}/_cluster/health" |
97 | | - method: GET |
98 | | - user: elastic |
99 | | - password: "{{ elasticstack_password.stdout }}" |
100 | | - validate_certs: no |
101 | | - register: response |
102 | | - until: "response.json.status == 'green'" |
103 | | - retries: 50 |
104 | | - delay: 30 |
105 | | - |
106 | | - # Disabling shard allocation right after enabling it seems redundant. Please see above for details. |
107 | | - - name: Disable shard allocation for the cluster |
108 | | - ansible.builtin.uri: |
109 | | - url: "{{ elasticsearch_http_protocol }}://{{ elasticsearch_api_host }}:{{ elasticstack_elasticsearch_http_port }}/_cluster/settings" |
110 | | - method: PUT |
111 | | - body: '{ "persistent": { "cluster.routing.allocation.enable": "none" }}' |
112 | | - body_format: json |
113 | | - user: elastic |
114 | | - password: "{{ elasticstack_password.stdout }}" |
115 | | - validate_certs: no |
116 | | - |
117 | | - - name: Stop non essential indexing to speed up shard recovery |
118 | | - ansible.builtin.uri: |
119 | | - url: "{{ elasticsearch_http_protocol }}://{{ elasticsearch_api_host }}:{{ elasticstack_elasticsearch_http_port }}/_flush" |
120 | | - method: POST |
121 | | - user: elastic |
122 | | - password: "{{ elasticstack_password.stdout }}" |
123 | | - validate_certs: no |
124 | | - failed_when: false |
125 | | - |
126 | | - - name: Shutdown elasticsearch service |
127 | | - ansible.builtin.service: |
128 | | - name: elasticsearch |
129 | | - enabled: yes |
130 | | - state: stopped |
131 | | - when: |
132 | | - - not elasticsearch_unsafe_upgrade_restart | bool |
| 74 | + - name: Include rolling stop |
| 75 | + ansible.builtin.include_tasks: elasticsearch-rolling-stop.yml |
133 | 76 |
|
134 | 77 | - name: Update Elasticsearch - rpm with managed repositories |
135 | 78 | ansible.builtin.package: |
|
147 | 90 | - ansible_os_family == "Debian" or |
148 | 91 | not elasticstack_full_stack | bool |
149 | 92 |
|
150 | | - - name: Start elasticsearch |
151 | | - ansible.builtin.service: |
152 | | - name: elasticsearch |
153 | | - enabled: yes |
154 | | - state: started |
155 | | - when: |
156 | | - - elasticsearch_running.status.ActiveState == "active" |
157 | | - - not elasticsearch_unsafe_upgrade_restart | bool |
158 | | - |
159 | | - - name: Restart elasticsearch (fast, for non-prod) |
160 | | - ansible.builtin.service: |
161 | | - name: elasticsearch |
162 | | - enabled: yes |
163 | | - state: restarted |
164 | | - when: |
165 | | - - elasticsearch_running.status.ActiveState == "active" |
166 | | - - elasticsearch_unsafe_upgrade_restart | bool |
167 | | - |
168 | | - - name: Wait for elasticsearch node to come back up if it was stopped |
169 | | - ansible.builtin.wait_for: |
170 | | - host: "{{ elasticsearch_api_host }}" |
171 | | - port: "{{ elasticstack_elasticsearch_http_port }}" |
172 | | - delay: 30 |
173 | | - |
174 | | - - name: Confirm the node joins the cluster # noqa: risky-shell-pipe |
175 | | - ansible.builtin.shell: > |
176 | | - if test -n "$(ps -p $$ | grep bash)"; then set -o pipefail; fi; |
177 | | - curl |
178 | | - -k |
179 | | - -u elastic:{{ elasticstack_password.stdout }} |
180 | | - -s |
181 | | - -m 2 |
182 | | - '{{ elasticsearch_http_protocol }}://{{ elasticsearch_api_host }}:{{ elasticstack_elasticsearch_http_port }}/_cat/nodes?h=name' |
183 | | - | grep |
184 | | - -E |
185 | | - '^{{ elasticsearch_nodename }}$' |
186 | | - register: result |
187 | | - until: result.rc == 0 |
188 | | - retries: 200 |
189 | | - delay: 3 |
190 | | - changed_when: false |
191 | | - |
192 | | - - name: Enable shard allocation for the cluster |
193 | | - ansible.builtin.uri: |
194 | | - url: "{{ elasticsearch_http_protocol }}://{{ elasticsearch_api_host }}:{{ elasticstack_elasticsearch_http_port }}/_cluster/settings" |
195 | | - method: PUT |
196 | | - body: '{ "persistent": { "cluster.routing.allocation.enable": null }}' |
197 | | - body_format: json |
198 | | - user: elastic |
199 | | - password: "{{ elasticstack_password.stdout }}" |
200 | | - validate_certs: no |
201 | | - register: response |
202 | | - # next line is boolean not string, so no quotes around true |
203 | | - # use python truthiness |
204 | | - until: "response.json.acknowledged == true" |
205 | | - retries: 5 |
206 | | - delay: 30 |
| 93 | + - name: Include rolling start |
| 94 | + ansible.builtin.include_tasks: elasticsearch-rolling-start.yml |
207 | 95 |
|
208 | | - - name: Wait for cluster health to return to yellow or green |
209 | | - ansible.builtin.uri: |
210 | | - url: "{{ elasticsearch_http_protocol }}://{{ elasticsearch_api_host }}:{{ elasticstack_elasticsearch_http_port }}/_cluster/health" |
211 | | - method: GET |
212 | | - user: elastic |
213 | | - password: "{{ elasticstack_password.stdout }}" |
214 | | - validate_certs: no |
215 | | - register: response |
216 | | - until: "response.json.status == 'yellow' or response.json.status == 'green'" |
217 | | - retries: 5 |
218 | | - delay: 30 |
0 commit comments