Update ILM policy if non-existent

Currently, ILM policies are not updated when running the elastic_ilm role if
the named ILM policy does not exist, and the beat itself is already installed.
This can occur if one changes the name of the ILM policy post-install using the
ilm_policy_name variable and wishes to update existing beats to reflect this.
This commit adds another task which explicitly pushes the ILM policy in this case.

Change-Id: I6b97af316843b9bc1feaa762d9074d824e2d02a8
This commit is contained in:
Duncan Martin Walker 2020-02-05 16:45:42 +00:00
parent 1214e42b85
commit ed345ece52

View File

@ -17,6 +17,18 @@
body_format: json
when: check_policy.status == 200 and ilm_policy_name is defined and ilm_policy is defined and (elk_package_state | default('present')) != "latest"
# If e.g. the ilm_policy_name has changed, the ILM policy may not exist, and needs to be pushed
- name: Add ILM policy if non-existent
uri:
url: "http://127.0.0.1:{{ elastic_port }}/_ilm/policy/{{ ilm_policy_name }}"
method: PUT
body: "{{ ilm_policy }}"
status_code: 200
body_format: json
when: check_policy.status == 404 and ilm_policy_name is defined and ilm_policy is defined and (elk_package_state | default('present')) != "latest"
- name: Get template
uri:
url: "http://127.0.0.1:{{ elastic_port }}/_template/{{ ilm_policy_template }}/"
@ -27,7 +39,7 @@
when: ilm_policy_template is defined and ilm_policy_name is defined
- set_fact:
updated_template: "{{ template.json | combine({template.json.keys()[0]|string:{'settings': {'index': {'lifecycle': {'name': 'ilm_policy_name' }}}}}, recursive=True) }}"
updated_template: "{{ template.json | combine({template.json.keys()[0]|string:{'settings': {'index': {'lifecycle': {'name': ilm_policy_name }}}}}, recursive=True) }}"
when: template.status == 200 and ilm_policy_template is defined and ilm_policy_name is defined
- name: Update template