From d7d144b6388d14050d73c5feee30848f26ca6c41 Mon Sep 17 00:00:00 2001 From: Dale McDiarmid Date: Fri, 27 Nov 2015 13:17:09 +0000 Subject: [PATCH] Support for removing mlock + max open files + fix to documentation error --- README.md | 2 -- tasks/elasticsearch-config.yml | 34 +++++++++++++++++++++++++++++----- tasks/elasticsearch.yml | 2 -- 3 files changed, 29 insertions(+), 9 deletions(-) diff --git a/README.md b/README.md index e26197b..02b565b 100644 --- a/README.md +++ b/README.md @@ -112,7 +112,6 @@ An example of a two server deployment, each with 1 node on one server and 2 node es_templates: false es_version_lock: false es_cluster_name: test-cluster - m_lock_enabled: true ansible_user: ansible es_plugins: - plugin: elasticsearch/license @@ -128,7 +127,6 @@ An example of a two server deployment, each with 1 node on one server and 2 node es_templates: false es_version_lock: false es_cluster_name: test-cluster - m_lock_enabled: false ansible_user: ansible es_plugins: - plugin: elasticsearch/license diff --git a/tasks/elasticsearch-config.yml b/tasks/elasticsearch-config.yml index ebceb25..b214b93 100644 --- a/tasks/elasticsearch-config.yml +++ b/tasks/elasticsearch-config.yml @@ -43,12 +43,19 @@ when: es_heap_size is defined register: elasticsearch_configure -#We only have to set these if they are specified. The start scripts will by default use the NAME set later on constructing directory names to avoid collisions. +- debug: msg="{{elasticsearch_configure}}" + +#We only have to set these if they are specified. The start scripts will by default set this value. - name: Configure max open files lineinfile: dest={{instance_default_file}} regexp="^MAX_OPEN_FILES" insertafter="^#MAX_OPEN_FILES" line="MAX_OPEN_FILES={{ es_max_open_files }}" when: es_max_open_files is defined register: elasticsearch_configure +#If the setting is not specified we remove it if its present. This will mean it reverts to the value in the init script. +- name: Remove max open files + lineinfile: dest={{instance_default_file}} regexp="^MAX_OPEN_FILES" line="MAX_OPEN_FILES=" state=absent + when: es_max_open_files is not defined + register: elasticsearch_configure #For directories we also use the {{inventory_hostname}}-{{ es_instance_name }} - this helps if we have a shared SAN. @@ -117,20 +124,37 @@ when: instance_init_script != init_script - file: path={{instance_config_directory}}/logging.yml state=touch owner={{ es_user }} group={{ es_group }} + changed_when: false + +- set_fact: m_lock_enabled={{ es_config['bootstrap.mlockall'] is defined and es_config['bootstrap.mlockall'] == True }} #Configure mlock if enabled - name: Configure mlock lineinfile: dest={{instance_default_file}} regexp="^MAX_LOCKED_MEMORY" insertafter="^#MAX_LOCKED_MEMORY" line="MAX_LOCKED_MEMORY=unlimited" - when: es_config['bootstrap.mlockall'] is defined and es_config['bootstrap.mlockall'] == True + when: m_lock_enabled register: elasticsearch_configure -#Change for systemd setting to ensure mlock is achieved +#Removed mlock if not enabled and present +- name: Remove mlock + lineinfile: dest={{instance_default_file}} regexp="^MAX_LOCKED_MEMORY" line="MAX_LOCKED_MEMORY=unlimited" state=absent + when: not m_lock_enabled - stat: path=/usr/lib/systemd/system/elasticsearch.service register: systemd_service - when: es_config['bootstrap.mlockall'] is defined and es_config['bootstrap.mlockall'] == True + when: m_lock_enabled +#Change for systemd setting to ensure mlock is achieved - name: Configure systemd lineinfile: dest=/usr/lib/systemd/system/elasticsearch.service regexp="^LimitMEMLOCK" insertafter="^#LimitMEMLOCK" line="LimitMEMLOCK=infinity" - when: es_config['bootstrap.mlockall'] is defined and es_config['bootstrap.mlockall'] == True and systemd_service.stat.exists == True + when: m_lock_enabled and systemd_service.stat.exists == True register: elasticsearch_configure + +#Remove setting if mlock is disabled +- name: Remove systemd + lineinfile: dest=/usr/lib/systemd/system/elasticsearch.service regexp="^LimitMEMLOCK" line="LimitMEMLOCK=infinity" state=absent + when: not m_lock_enabled + +- debug: msg="{{m_lock_enabled}}" + + +- debug: msg="{{elasticsearch_configure}}" \ No newline at end of file diff --git a/tasks/elasticsearch.yml b/tasks/elasticsearch.yml index 4b0ebbf..8e54a8a 100644 --- a/tasks/elasticsearch.yml +++ b/tasks/elasticsearch.yml @@ -19,8 +19,6 @@ - name: Elasticsearch configuration include: elasticsearch-config.yml -#We remove the node.name key as it may be set by another node on the same server - # Make sure the service is started, and restart if necessary - name: Start elasticsearch service