diff --git a/defaults/main.yml b/defaults/main.yml index c403691..2906571 100644 --- a/defaults/main.yml +++ b/defaults/main.yml @@ -14,4 +14,4 @@ es_group: elasticsearch es_pid_dir: "/var/run/elasticsearch" es_data_dir: "/var/lib/elasticsearch" es_log_dir: "/var/log/elasticsearch" -es_work_dir: "/tmp/elasticsearch" +es_work_dir: "/tmp/elasticsearch" \ No newline at end of file diff --git a/tasks/checkParameters.yml b/tasks/checkParameters.yml index e0b4ac8..11fe3d8 100644 --- a/tasks/checkParameters.yml +++ b/tasks/checkParameters.yml @@ -13,4 +13,4 @@ when: es_config['discovery.zen.ping.multicast.enabled'] == false 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 explictly false) \ No newline at end of file +# If multicast is false OR if > 2.0 AND not defined as true (or explicitly false) \ No newline at end of file diff --git a/tasks/elasticsearch-scripts.yml b/tasks/elasticsearch-scripts.yml index 82655ab..eb55422 100644 --- a/tasks/elasticsearch-scripts.yml +++ b/tasks/elasticsearch-scripts.yml @@ -1,3 +1,12 @@ --- + +- set_fact: es_script_dir={{ es_log_dir }}/{{inventory_hostname}}-{{ es_instance_name }} + +- set_fact: es_script_dir={{es_config['path.scripts']}} + when: es_config['path.scripts'] is not defined + +- name: Create script dir + file: state=directory path={{ es_script_dir }} owner={{ es_user }} group={{ es_group }} + - name: Copy scripts to elasticsearch - copy: src=scripts dest=/etc/elasticsearch/ + copy: src=scripts dest={{ es_scripts_dir }} diff --git a/tasks/main.yml b/tasks/main.yml index ca640cc..2df9bd1 100644 --- a/tasks/main.yml +++ b/tasks/main.yml @@ -7,8 +7,8 @@ - include: elasticsearch.yml - include: elasticsearch-plugins.yml when: es_plugins is defined -#- include: elasticsearch-scripts.yml -# when: es_scripts +- include: elasticsearch-scripts.yml + when: es_scripts #- include: elasticsearch-templates.yml # when: es_templates diff --git a/templates/elasticsearch.yml.j2 b/templates/elasticsearch.yml.j2 index 275c93c..29c970d 100644 --- a/templates/elasticsearch.yml.j2 +++ b/templates/elasticsearch.yml.j2 @@ -17,4 +17,8 @@ path.data: {{ data_dir }} path.work: {{ work_dir }} -path.logs: {{ log_dir }} \ No newline at end of file +path.logs: {{ log_dir }} + +{% if es_scripts and es_config['path.scripts'] is not defined %} +path.scripts: {{ es_conf_dir }}/{{es_instance_name}}/scripts +{% endif %} \ No newline at end of file diff --git a/test/integration/config.yml b/test/integration/config.yml index 98bbd75..71b02b5 100644 --- a/test/integration/config.yml +++ b/test/integration/config.yml @@ -4,7 +4,7 @@ hosts: localhost roles: #expand to all available parameters - - { role: elasticsearch, es_instance_name: "node1", es_config: {node.name: "node1", cluster.name: "custom-cluster", discovery.zen.ping.unicast.hosts: "localhost:9301", http.port: 9201, transport.tcp.port: 9301, node.data: false, node.master: true, bootstrap.mlockall: true, discovery.zen.ping.multicast.enabled: false } } + - { role: elasticsearch, es_instance_name: "node1", es_data_dir: "/opt/elasticsearch/data", es_log_dir: "/opt/elasticsearch/logs", es_work_dir: "/opt/elasticsearch/temp", es_config: {node.name: "node1", cluster.name: "custom-cluster", discovery.zen.ping.unicast.hosts: "localhost:9301", http.port: 9201, transport.tcp.port: 9301, node.data: false, node.master: true, bootstrap.mlockall: true, discovery.zen.ping.multicast.enabled: false } } vars: es_scripts: false es_templates: false diff --git a/test/integration/config/serverspec/default_spec.rb b/test/integration/config/serverspec/default_spec.rb index 0248fe1..627a75f 100644 --- a/test/integration/config/serverspec/default_spec.rb +++ b/test/integration/config/serverspec/default_spec.rb @@ -30,9 +30,34 @@ context "basic tests" do it { should contain 'bootstrap.mlockall: true' } it { should contain 'discovery.zen.ping.unicast.hosts: localhost:9301' } it { should contain 'path.conf: /etc/elasticsearch/node1' } - it { should contain 'path.data: /var/lib/elasticsearch/localhost-node1' } - it { should contain 'path.work: /tmp/elasticsearch/localhost-node1' } - it { should contain 'path.logs: /var/log/elasticsearch/localhost-node1' } + it { should contain 'path.data: /opt/elasticsearch/data/localhost-node1' } + it { should contain 'path.work: /opt/elasticsearch/temp/localhost-node1' } + it { should contain 'path.logs: /opt/elasticsearch/logs/localhost-node1' } + end + + #test directories exist + describe file('/etc/elasticsearch/node1') do + it { should be_directory } + it { should be_owned_by 'elasticsearch' } + end + + describe file('/opt/elasticsearch/data/localhost-node1') do + it { should be_directory } + it { should be_owned_by 'elasticsearch' } + end + + describe file('/opt/elasticsearch/logs/localhost-node1') do + it { should be_directory } + it { should be_owned_by 'elasticsearch' } + end + + describe file('/opt/elasticsearch/temp/localhost-node1') do + it { should be_directory } + it { should be_owned_by 'elasticsearch' } + end + + describe file('/etc/init.d/node1_elasticsearch') do + it { should be_file } end #test we started on the correct port was used diff --git a/test/integration/package.yml b/test/integration/package.yml index 5142f93..9c7db94 100644 --- a/test/integration/package.yml +++ b/test/integration/package.yml @@ -3,4 +3,5 @@ hosts: localhost roles: - { role: elasticsearch, es_config: { "discovery.zen.ping.multicast.enabled": true }, es_instance_name: "node1" } - vars: \ No newline at end of file + vars: + es_scripts: true \ No newline at end of file diff --git a/test/integration/package/scripts/calculate-score.groovy b/test/integration/package/scripts/calculate-score.groovy new file mode 100644 index 0000000..442c25c --- /dev/null +++ b/test/integration/package/scripts/calculate-score.groovy @@ -0,0 +1 @@ +log(_score * 2) + my_modifier \ No newline at end of file diff --git a/test/integration/standard/serverspec/default_spec.rb b/test/integration/standard/serverspec/default_spec.rb index 09e8742..fa19d45 100644 --- a/test/integration/standard/serverspec/default_spec.rb +++ b/test/integration/standard/serverspec/default_spec.rb @@ -20,7 +20,7 @@ context "basic tests" do describe file('/etc/elasticsearch/node1/elasticsearch.yml') do it { should contain 'node.name: localhost-node1' } - it { should contain 'cluster.name: "elasticsearch"' } + it { should contain 'cluster.name: elasticsearch' } it { should contain 'path.conf: /etc/elasticsearch/node1' } it { should contain 'path.data: /var/lib/elasticsearch/localhost-node1' } it { should contain 'path.work: /tmp/elasticsearch/localhost-node1' } diff --git a/vars/Debian.yml b/vars/Debian.yml index 7ad3450..d0d3da3 100644 --- a/vars/Debian.yml +++ b/vars/Debian.yml @@ -2,5 +2,4 @@ java: "openjdk-7-jre-headless" default_file: "/etc/default/elasticsearch" init_script: "/etc/init.d/elasticsearch" -es_conf_dir: "/etc/elasticsearch" es_home: "/usr/share/elasticsearch" \ No newline at end of file diff --git a/vars/RedHat.yml b/vars/RedHat.yml index f2f2f89..0d8dbbe 100644 --- a/vars/RedHat.yml +++ b/vars/RedHat.yml @@ -2,5 +2,4 @@ java: "java-1.8.0-openjdk.x86_64" default_file: "/etc/sysconfig/elasticsearch" init_script: "/etc/init.d/elasticsearch" -es_conf_dir: "/etc/elasticsearch" es_home: "/usr/share/elasticsearch" \ No newline at end of file diff --git a/vars/main.yml b/vars/main.yml index f4531d4..1c232fa 100644 --- a/vars/main.yml +++ b/vars/main.yml @@ -1,2 +1,3 @@ --- es_package_url: "https://download.elastic.co/elasticsearch/elasticsearch/elasticsearch" +es_conf_dir: "/etc/elasticsearch" \ No newline at end of file