Created
April 25, 2016 21:07
-
-
Save jpcarey/6d97f43c03bb8dc52ec8567404772323 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
- name: 'Checking that only a single host is in the current play (playbook serial: 1)' | |
assert: { that: "play_hosts | length == 1" } | |
# < --- start httplib2 dependency check, and install if necessary | |
- name: Dummy check to ensure httplib2 is installed | |
uri: | |
url: http://127.0.0.1:9200 | |
ignore_errors: True | |
register: httplib2_check | |
- debug: var=httplib2_check | |
when: httplib2_check|failed | |
# easy_install because AWS AMI python-pip is broken | |
# - yum: name=python-pip | |
# when: httplib2_check|failed and "httplib2 is not installed" in httplib2_check.msg | |
# - pip: name=httplib2 | |
# when: httplib2_check|failed and "httplib2 is not installed" in httplib2_check.msg | |
- shell: easy_install httplib2 | |
when: httplib2_check|failed and "httplib2 is not installed" in httplib2_check.msg | |
# --- > end httplib2 dependency check | |
- name: Check to ensure the cluster is healthy before trying to restart the node | |
uri: | |
url: http://127.0.0.1:9200/_cluster/health | |
return_content: yes | |
until: 'cluster_result.json.status == "green" and cluster_result.json.relocating_shards == 0' | |
retries: 10 | |
delay: 10 | |
register: cluster_result | |
- name: Get current _node information for PID path | |
uri: | |
url: 'http://127.0.0.1:9200/_nodes/_local/settings,plugins' | |
register: node_information | |
- name: trim down the _node data | |
set_fact: | |
node_info: '{{ item.value }}' | |
with_dict: node_information.json.nodes | |
no_log: True | |
- debug: var=node_info.settings.pidfile | |
- name: Disabling shard relocation | |
uri: | |
url: http://127.0.0.1:9200/_cluster/settings | |
method: PUT | |
body: '{"transient": { "cluster.routing.allocation.enable" : "none" } }' | |
return_content: yes | |
register: routing_disable | |
failed_when: routing_disable.json.acknowledged != True | |
changed_when: True | |
- debug: var=routing_disable | |
- name: Capture the process ID of elasticsearch | |
command: "cat '{{ node_info.settings.pidfile }}'" | |
register: proc_id | |
failed_when: "proc_id.stdout == ''" | |
# - debug: var=proc_id.stdout | |
- name: Shutdown the node using _local/shutdown API | |
uri: | |
url: http://127.0.0.1:9200/_cluster/nodes/_local/_shutdown | |
method: POST | |
return_content: yes | |
changed_when: True | |
- name: Wait until the elasticsearch has exited | |
wait_for: path=/proc/{{ proc_id.stdout }}/status | |
state=absent | |
timeout=60 | |
- name: Start elasticsearch service | |
service: name={{ elasticsearch_service_name | default('elasticsearch') }} | |
state=started | |
- name: Check that the cluster has the same number of nodes as when we started | |
uri: | |
url: http://localhost:9200/_cluster/health | |
return_content: yes | |
register: cluster_rejoin | |
until: cluster_rejoin.json.number_of_nodes == cluster_result.json.number_of_nodes | |
retries: 5 | |
delay: 10 | |
- name: Enable shard relocation | |
uri: | |
url: http://127.0.0.1:9200/_cluster/settings | |
method: PUT | |
body: '{"transient": { "cluster.routing.allocation.enable" : "all" } }' | |
return_content: yes | |
register: routing_enable | |
failed_when: routing_enable.json.acknowledged != True | |
changed_when: True |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment