I've written two rolling Elasticsearch playbooks
<https://gist.github.com/samdoran/bd996dc0a3018ff6ba8e>: one for restarting
the cluster, the other for updating the cluster. I use the feature of
Ansible that will intelligently take JSON output in a register variable and
make it addressable (not sure if I'm using the right terminology). Because
Elasticsearch returns JSON when you query the API, you can use the
registered output of the uri module and a do-until loop
<http://docs.ansible.com/playbooks_loops.html#do-until-loops> to wait for a
certain condition before continuing. So instead of using result.stdout or
result.content with a search, you can use result.json.[field] to be very
precise.
- 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: 5
delay: 30
The contents of response.json are:
ok: [node01.acme.com] => {
"response": {
"changed": false,
"content_length": "227",
"content_location": "http://localhost:9500/_cluster/health",
"content_type": "application/json; charset=UTF-8",
"invocation": {
"module_args": "url=http://localhost:9500/_cluster/health
method=GET",
"module_name": "uri"
},
"json": {
"active_primary_shards": 405,
"active_shards": 810,
"cluster_name": "elasticsearch",
"initializing_shards": 0,
"number_of_data_nodes": 3,
"number_of_nodes": 4,
"relocating_shards": 0,
"status": "green",
"timed_out": false,
"unassigned_shards": 0
},
"redirected": false,
"status": 200
}
}
I'm not sure of the value of using pre and post tasks with a serial of one
in my playbooks. It could all most likely be one list of tasks.
I based the playbooks on the Elasticsearch documentation for updating 1.0
and later
<http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/setup-upgrade.html#_1_0_and_later>
and
rolling restart
<http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/cluster-nodes-shutdown.html#_rolling_restart_of_nodes_full_cluster_restart>
.
--
You received this message because you are subscribed to the Google Groups
"Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/ansible-project/61c9e24a-f111-4d0d-a516-fc06c9aea2e1%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.