Last active
December 10, 2021 16:42
-
-
Save VAdamec/c9e103d89414820a24ad to your computer and use it in GitHub Desktop.
ES reload with puppet changes
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
# | |
# https://gist.githubusercontent.com/samdoran/ | |
# https://forge.puppetlabs.com/elasticsearch/elasticsearch - cluster split prod/dev/stg/... by cluster name <project>-<cluster_name>-.... | |
# | |
--- | |
- name: Elasticsearch rolling upgrade | |
hosts: elk | |
serial: 1 | |
sudo: yes | |
gather_facts: true | |
vars: | |
uribody_true: '{"transient":{"cluster.routing.allocation.enable":"none"}}' | |
uribody_false: '{"transient":{"cluster.routing.allocation.enable":"all"}}' | |
es_http_port: 9200 | |
es_transport_port: 9300 | |
pre_tasks: | |
- name: Ensure complete transactions | |
shell: yum-complete-transaction --cleanup-only | |
- name: Ensure python-httplib2 | |
yum: name=python-httplib2 state=latest | |
- name: Get service name | |
shell: facter -p project_service | |
register: servicename | |
- name: Disable shard allocation for the cluster | |
uri: url=http://localhost:{{ es_http_port }}/_cluster/settings method=PUT body='{{ uribody_true }}' | |
tags: shutdown | |
- name: Find master | |
shell: 'curl -s "localhost:9200/_cat/master?pretty" | cut -f 2 -d " "' | |
register: master | |
tasks: | |
- name: Wait for all shards to be reallocated | |
uri: url=http://localhost:{{ es_http_port }}/_cluster/health method=GET | |
register: response | |
until: "response.json.relocating_shards == 0" | |
retries: 100 | |
delay: 30 | |
- name: Wait for command accept | |
shell: 'grep "updating \[cluster.routing.allocation.enable\] from \[ALL\] to \[NONE\]" /var/log/elasticsearch/{{ servicename.stdout }}/{{ servicename.stdout }}.log' | |
register: result | |
until: result.stdout.find("updating [cluster.routing.allocation.enable] from [ALL] to [NONE]") != -1 | |
retries: 60 | |
delay: 10 | |
delegate_to: "{{ master.stdout }}" | |
- name: Shutdown elasticsearch node | |
uri: url=http://localhost:{{ es_http_port }}/_cluster/nodes/_local/_shutdown method=POST | |
tags: shutdown | |
- name: Update elasticsearch | |
yum: name=elasticsearch state=latest | |
- name: "Run Puppet init" | |
shell: /usr/bin/puppet agent -t > /dev/null 2>&1 | |
register: puppet_agent_test | |
ignore_errors: yes | |
- name: "Run Puppet" | |
shell: /usr/bin/puppet agent -t > /dev/null 2>&1 | |
register: puppet_agent | |
until: puppet_agent.rc == 2 or puppet_agent.rc == 0 | |
failed_when: puppet_agent.rc != 2 and puppet_agent.rc != 0 | |
changed_when: puppet_agent.rc == 2 | |
retries: 3 | |
delay: 30 | |
- name: Start elasticsearch | |
service: name=elasticsearch-{{ servicename.stdout }} enabled=yes state=restarted | |
- name: Wait for elasticsearch node to come back up | |
wait_for: port={{ es_transport_port }} delay=35 | |
- name: Wait for cluster health to return to yellow | |
uri: url=http://localhost:{{ es_http_port }}/_cluster/health method=GET | |
register: response | |
until: "response.json.status == 'yellow'" | |
retries: 100 | |
delay: 30 | |
post_tasks: | |
- name: Enable shard allocation for the cluster | |
uri: url=http://localhost:{{ es_http_port }}/_cluster/settings method=PUT body='{{ uribody_false }}' | |
delay: 3 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment