diff --git a/meta/main.yml b/meta/main.yml index 4f961d5..bc95109 100644 --- a/meta/main.yml +++ b/meta/main.yml @@ -3,7 +3,7 @@ allow_duplicates: yes galaxy_info: - author: Robin Clarke + author: Robin Clarke, Jakob Reiter, Dale McDiarmid description: Elasticsearch for Linux company: "Elastic.co" license: "license (Apache)" diff --git a/tasks/checkParameters.yml b/tasks/checkParameters.yml index 8e2cc88..3fbf5d9 100644 --- a/tasks/checkParameters.yml +++ b/tasks/checkParameters.yml @@ -4,12 +4,14 @@ when: es_instance_name is not defined - fail: msg="Parameter 'http.port' must be defined when multicast is disabled" - when: es_config['discovery.zen.ping.multicast.enabled'] == false or (es_version | version_compare('2.0', '>=') and es_config['discovery.zen.ping.multicast.enabled'] is not defined) and es_config['http.port'] is not defined + when: (es_config['discovery.zen.ping.multicast.enabled'] == False or (es_version | version_compare('2.0', '>=') and es_config['discovery.zen.ping.multicast.enabled'] is not defined)) and es_config['http.port'] is not defined - fail: msg="Parameter 'transport.tcp.port' must be defined when multicast is disabled" - when: es_config['discovery.zen.ping.multicast.enabled'] == false or (es_version | version_compare('2.0', '>=') and es_config['discovery.zen.ping.multicast.enabled'] is not defined) and es_config['transport.tcp.port'] is not defined + when: (es_config['discovery.zen.ping.multicast.enabled'] == False or (es_version | version_compare('2.0', '>=') and es_config['discovery.zen.ping.multicast.enabled'] is not defined)) and es_config['transport.tcp.port'] is not defined - fail: msg="Parameter 'discovery.zen.ping.unicast.hosts' must be defined when multicast is disabled" - when: es_config['discovery.zen.ping.multicast.enabled'] == false or (es_version | version_compare('2.0', '>=') and es_config['discovery.zen.ping.multicast.enabled'] is not defined) and es_config['discovery.zen.ping.unicast.hosts'] is not defined + when: (es_config['discovery.zen.ping.multicast.enabled'] == False or (es_version | version_compare('2.0', '>=') and es_config['discovery.zen.ping.multicast.enabled'] is not defined)) and es_config['discovery.zen.ping.unicast.hosts'] is not defined -# If multicast is false OR if > 2.0 AND not defined as true (or explicitly false) \ No newline at end of file +#If the user attempts to lock memory they must specify a heap size +- fail: msg="If locking memory with bootstrap.mlockall a heap size must be specified" + when: es_config['bootstrap.mlockall'] == True and es_heap_size is not defined \ No newline at end of file diff --git a/tasks/elasticsearch-config.yml b/tasks/elasticsearch-config.yml index c8decc6..a26ef55 100644 --- a/tasks/elasticsearch-config.yml +++ b/tasks/elasticsearch-config.yml @@ -111,9 +111,25 @@ register: elasticsearch_configure when: ansible_os_family == 'RedHat' -#Copy the logging.yml - TODO: i.e we may template this. +#Copy the logging.yml - name: Copy Logging.yml for Instance command: creates={{instance_config_directory}}/logging.yml cp "{{ es_conf_dir }}/logging.yml" "{{instance_config_directory}}/logging.yml" when: instance_init_script != init_script -- file: path={{instance_config_directory}}/logging.yml state=touch owner={{ es_user }} group={{ es_group }} \ No newline at end of file +- file: path={{instance_config_directory}}/logging.yml state=touch owner={{ es_user }} group={{ es_group }} + +#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 + register: elasticsearch_configure + +#Change for systemd setting to ensure mlock is achieved + +- stat: path=/usr/lib/systemd/system/elasticsearch.service + register: systemd_service + +- 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 + register: elasticsearch_configure diff --git a/tasks/elasticsearch.yml b/tasks/elasticsearch.yml index d161cac..4b0ebbf 100644 --- a/tasks/elasticsearch.yml +++ b/tasks/elasticsearch.yml @@ -24,12 +24,12 @@ # Make sure the service is started, and restart if necessary - name: Start elasticsearch service - service: name={{instance_init_script | basename}} state=started + service: name={{instance_init_script | basename}} state=started enabled=yes when: es_start_service register: elasticsearch_started - name: Restart elasticsearch service if new version installed - service: name={{instance_init_script | basename}} state=restarted + service: name={{instance_init_script | basename}} state=restarted enabled=yes when: es_start_service and ( elasticsearch_install.changed or elasticsearch_configure.changed ) and not elasticsearch_started.changed diff --git a/test/integration/config.yml b/test/integration/config.yml index bcb8925..357752d 100644 --- a/test/integration/config.yml +++ b/test/integration/config.yml @@ -8,4 +8,5 @@ vars: es_scripts: false es_templates: false - es_version_lock: false \ No newline at end of file + es_version_lock: false + es_heap_size: 1g \ No newline at end of file diff --git a/test/integration/config/serverspec/default_spec.rb b/test/integration/config/serverspec/default_spec.rb index 627a75f..4d42eeb 100644 --- a/test/integration/config/serverspec/default_spec.rb +++ b/test/integration/config/serverspec/default_spec.rb @@ -67,6 +67,11 @@ context "basic tests" do its(:exit_status) { should eq 0 } end + #test to make sure mlock was applied + describe command('curl "localhost:9201/_nodes/process?pretty" | grep mlockall') do + its(:stdout) { should match /\"mlockall\" : true/ } + its(:exit_status) { should eq 0 } + end end