-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathplaybook.yml
50 lines (38 loc) · 2.37 KB
/
playbook.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
---
- hosts: all
serial: 1
vars:
CLUSTER_STATUS_TIMEOUT: 600000000
CLUSTER_STATUS_REQUEST: 'http://localhost:9200/_cluster/health?wait_for_status=green&timeout={{ CLUSTER_STATUS_TIMEOUT }}'
DISABLE_ALLOCATION_REQUEST: '{"transient":{"cluster.routing.allocation.disable_allocation":"true", "cluster.routing.allocation.enable":"none"}}'
ENABLE_ALLOCATION_REQUEST: '{"transient":{"cluster.routing.allocation.disable_allocation":"false", "cluster.routing.allocation.enable":"all"}}'
tasks:
- name: Ensure prerequisites are installed
yum: name={{ item }} state=present
with_items:
- python-httplib2
- name: Disable allocation in elasticsearch
uri: url=http://localhost:9200/_cluster/settings return_content=yes method=PUT body='{{DISABLE_ALLOCATION_REQUEST}}'
register: disable_response
- fail: msg=Cluster failed to acknowledge allocation disable request
when: "'{{disable_response.json.acknowledged}}' != 'True'"
- fail: msg=Settings change did not take effect
when: "'{{disable_response.json.transient.cluster.routing.allocation.enable}}' != 'none' or '{{disable_response.json.transient.cluster.routing.allocation.disable_allocation}}' != 'true'"
- name: Restart elasticsearch
service: name=elasticsearch state=restarted
- name: Wait for elasticsearch to come back up
wait_for: port=9200 delay=5
- name: Enable allocation in elasticsearch
uri: url=http://localhost:9200/_cluster/settings return_content=yes method=PUT body='{{ENABLE_ALLOCATION_REQUEST}}'
register: enable_response
- fail: msg=Cluster failed to acknowledge allocation enable request
when: "'{{enable_response.json.acknowledged}}' != 'True'"
- fail: msg=Settings change did not take effect
when: "'{{enable_response.json.transient.cluster.routing.allocation.enable}}' != 'all' or '{{enable_response.json.transient.cluster.routing.allocation.disable_allocation}}' != 'false'"
- name: Wait for Cluster status green
uri: url="{{ CLUSTER_STATUS_REQUEST }}" timeout=10000000000
register: status_response
- fail: msg=Cluster failed to return to status green within defined time limit
when: "'{{status_response.json.timed_out}}' != 'False'"
- fail: msg=Cluster responded with status not equal green
when: "'{{status_response.json.status}}' != 'green'"