From 145f345ec1f2f379b9f2d8b01e1eacbf6a03eacc Mon Sep 17 00:00:00 2001 From: Dale McDiarmid Date: Fri, 27 Nov 2015 19:39:47 +0000 Subject: [PATCH] Fixes for serverspec --- tasks/elasticsearch-config.yml | 12 ++++++++-- tasks/elasticsearch.yml | 4 ---- templates/elasticsearch.j2 | 2 +- templates/systemd/elasticsearch.j2 | 2 +- .../multi/serverspec/default_spec.rb | 24 +++++++++---------- 5 files changed, 24 insertions(+), 20 deletions(-) diff --git a/tasks/elasticsearch-config.yml b/tasks/elasticsearch-config.yml index 9f9d117..c98c3b4 100644 --- a/tasks/elasticsearch-config.yml +++ b/tasks/elasticsearch-config.yml @@ -1,6 +1,14 @@ --- # Configure Elasticsearch Node + +#This relies on elasticsearch installing a serviced script to determine whether one should be copied. +- stat: path={{sysd_script}} + register: systemd_service + +- set_fact: instance_sysd_script={{sysd_script | dirname }}/{{es_instance_name}}_{{sysd_script | basename}} + when: systemd_service.stat.exists + #For directories we also use the {{inventory_hostname}}-{{ es_instance_name }} - this helps if we have a shared SAN. - set_fact: pid_dir={{es_pid_dir}}/{{inventory_hostname}}-{{ es_instance_name }} @@ -45,12 +53,12 @@ #Copy the instance specific init file - name: Copy Redhat Init File for Instance template: src=init/redhat/elasticsearch.j2 dest={{instance_init_script}} mode=0755 force=yes - when: ansible_os_family == 'Redhat' + when: ansible_os_family == 'RedHat' #Copy the systemd specific file if systemd is installed - name: Copy Systemd File for Instance template: src=systemd/elasticsearch.j2 dest={{instance_sysd_script}} mode=0644 force=yes - when: systemd_service + when: systemd_service.stat.exists notify: restart elasticsearch #Copy the logging.yml diff --git a/tasks/elasticsearch.yml b/tasks/elasticsearch.yml index e626ddc..b921d8b 100644 --- a/tasks/elasticsearch.yml +++ b/tasks/elasticsearch.yml @@ -3,10 +3,6 @@ - set_fact: instance_default_file={{default_file | dirname}}/{{es_instance_name}}_{{default_file | basename}} - set_fact: instance_init_script={{init_script | dirname }}/{{es_instance_name}}_{{init_script | basename}} - set_fact: instance_config_directory={{ es_conf_dir }}/{{es_instance_name}} -- stat: path={{sysd_script}} - register: systemd_service -- set_fact: instance_sysd_script={{sysd_script | dirname }}/{{es_instance_name}}_{{sysd_script | basename}} - when: systemd_service - set_fact: m_lock_enabled={{ es_config['bootstrap.mlockall'] is defined and es_config['bootstrap.mlockall'] == True }} - debug: msg="Node configuration {{ es_config }} " diff --git a/templates/elasticsearch.j2 b/templates/elasticsearch.j2 index 9c577b5..d940425 100644 --- a/templates/elasticsearch.j2 +++ b/templates/elasticsearch.j2 @@ -9,7 +9,7 @@ ES_HOME={{es_home}} CONF_DIR={{instance_config_directory}} # Elasticsearch configuration file -CONF_FILE=$CONF_DIR/elasticsearch.yml +CONF_FILE={{instance_config_directory}}/elasticsearch.yml # Elasticsearch data directory DATA_DIR={{data_dir}} diff --git a/templates/systemd/elasticsearch.j2 b/templates/systemd/elasticsearch.j2 index 5e19d0e..bedcceb 100644 --- a/templates/systemd/elasticsearch.j2 +++ b/templates/systemd/elasticsearch.j2 @@ -1,5 +1,5 @@ [Unit] -Description=Elasticsearch +Description=Elasticsearch-{{es_instance_name}} Documentation=http://www.elastic.co Wants=network-online.target After=network-online.target diff --git a/test/integration/multi/serverspec/default_spec.rb b/test/integration/multi/serverspec/default_spec.rb index 38f8334..93b03aa 100644 --- a/test/integration/multi/serverspec/default_spec.rb +++ b/test/integration/multi/serverspec/default_spec.rb @@ -87,18 +87,6 @@ context "basic tests" do end end - #test to make sure mlock was applied - describe command('curl "localhost:9200/_nodes/localhost-master/process?pretty" | grep mlockall') do - its(:stdout) { should match /\"mlockall\" : true/ } - its(:exit_status) { should eq 0 } - end - - #test to make sure mlock was not applied - describe command('curl "localhost:9201/_nodes/localhost-node1/process?pretty" | grep mlockall') do - its(:stdout) { should match /\"mlockall\" : false/ } - its(:exit_status) { should eq 0 } - end - describe file('/etc/elasticsearch/templates') do it { should be_directory } it { should be_owned_by 'elasticsearch' } @@ -160,5 +148,17 @@ context "basic tests" do it { should be_directory } it { should be_owned_by 'elasticsearch' } end + + #test to make sure mlock was applied + describe command('curl "localhost:9200/_nodes/localhost-master/process?pretty" | grep mlockall') do + its(:stdout) { should match /true/ } + its(:exit_status) { should eq 0 } + end + + #test to make sure mlock was not applied + describe command('curl "localhost:9201/_nodes/localhost-node1/process?pretty" | grep mlockall') do + its(:stdout) { should match /false/ } + its(:exit_status) { should eq 0 } + end end