Skip to content

Commit 275dea3

Browse files
Add option to stop ML jobs and set cluster allocation mode. Update docs
1 parent 5adc31b commit 275dea3

File tree

5 files changed

+34
-3
lines changed

5 files changed

+34
-3
lines changed

docs/role-elasticsearch.md

+6
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@ If you use the role to set up security you, can use its CA to create certificate
99

1010
Please note that setting `elasticsearch_bootstrap_pw` as variable will only take effect when initialising Elasticsearch. Changes after starting elasticsearch for the first time will not change the bootstrap password for the instance and will lead to breaking tests.
1111

12+
The role can perform a rolling upgrade of an elasticsearch cluster. Nodes will be upgraded in inventory order. If you are using data tires, you're ansible inventory should be sorted acording to data tiers. Set `any_errors_fatal: true` in your playbook to abort if any errors occur during the upgrade.
13+
14+
1215
Role Variables
1316
--------------
1417

@@ -54,6 +57,9 @@ This variable activates a workaround to start on systems that have certain harde
5457
* *elasticsearch_seed_hosts*: Set elasticsearch seed hosts
5558
* *elasticsearch_security_enrollment*: Controls enrollment (of nodes and Kibana) to a local node that’s been autoconfigured for security.
5659

60+
*elasticsearch_upgrade_routing_mode*: Set `cluster.routing.allocation.enable` during rolling upgrade. (default: `none`)
61+
*elasticsearch_upgrade_stop_ml*: Stop the tasks associated with active machine learning jobs and datafeeds during rolling upgrade. (default: `false`)
62+
5763
The following variable was only integrated to speed up upgrades of non-production clusters. Use with caution and at your own risk:
5864

5965
* *elasticsearch_unsafe_upgrade_restart*: This will still perform rolling upgrades, but will first update the package and then restart the service. In contrast the default behaviour is to stop the service, do the upgrade and then start again. (default: `false`)

roles/elasticsearch/defaults/main.yml

+4
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,10 @@ elasticsearch_cert_expiration_buffer: 30
3737
elasticsearch_cert_will_expire_soon: false
3838
elasticsearch_ssl_verification_mode: full
3939

40+
# Upgrade options
41+
elasticsearch_upgrade_routing_mode: "none"
42+
elasticsearch_upgrade_stop_ml: false
43+
4044
# use this only for non-prod environments and at your own risk!
4145
elasticsearch_unsafe_upgrade_restart: false
4246

roles/elasticsearch/tasks/elasticsearch-rolling-start.yml

+11
Original file line numberDiff line numberDiff line change
@@ -55,3 +55,14 @@
5555
# Don't continue the play unless cluster health is OK
5656
- name: Cluster health check
5757
ansible.builtin.include_tasks: elasticsearch-wait-for-cluster-health.yml
58+
59+
- name: Restart ML jobs
60+
ansible.builtin.uri:
61+
url: "{{ elasticsearch_http_protocol }}://{{ elasticsearch_api_host }}:{{ elasticstack_elasticsearch_http_port }}/_ml/set_upgrade_mode?enabled=false"
62+
method: POST
63+
user: elastic
64+
password: "{{ elasticstack_password.stdout }}"
65+
validate_certs: no
66+
failed_when: false
67+
when:
68+
- elasticsearch_upgrade_stop_ml | bool

roles/elasticsearch/tasks/elasticsearch-rolling-stop.yml

+13-2
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,23 @@
2121
ansible.builtin.include_tasks: elasticsearch-wait-for-cluster-health.yml
2222

2323

24-
# Disabling shard allocation right after enabling it seems redundant. Please see above for details.
24+
- name: Stop ML jobs while upgrading
25+
ansible.builtin.uri:
26+
url: "{{ elasticsearch_http_protocol }}://{{ elasticsearch_api_host }}:{{ elasticstack_elasticsearch_http_port }}/_ml/set_upgrade_mode?enabled=true"
27+
method: POST
28+
user: elastic
29+
password: "{{ elasticstack_password.stdout }}"
30+
validate_certs: no
31+
failed_when: false
32+
run_once: true
33+
when:
34+
- elasticsearch_upgrade_stop_ml | bool
35+
2536
- name: Disable shard allocation for the cluster
2637
ansible.builtin.uri:
2738
url: "{{ elasticsearch_http_protocol }}://{{ elasticsearch_api_host }}:{{ elasticstack_elasticsearch_http_port }}/_cluster/settings"
2839
method: PUT
29-
body: '{ "persistent": { "cluster.routing.allocation.enable": "none" }}'
40+
body: "{ \"persistent\": { \"cluster.routing.allocation.enable\": \"{{ elasticsearch_upgrade_routing_mode }}\" } }"
3041
body_format: json
3142
user: elastic
3243
password: "{{ elasticstack_password.stdout }}"

roles/elasticsearch/tasks/elasticsearch-rolling-upgrade.yml

-1
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,6 @@
6464
notify:
6565
- Restart Elasticsearch
6666

67-
6867
- name: Be careful about upgrade when Elasticsearch is running
6968
when:
7069
- elasticsearch_running.status.ActiveState == "active"

0 commit comments

Comments
 (0)