diff --git a/.gitignore b/.gitignore index 3a02b2e..0bb96d7 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,4 @@ .kitchen/ -.kitchen.local.yml *.lock .vendor .bundle diff --git a/.kitchen.yml b/.kitchen.yml index 4874b31..0348eaf 100644 --- a/.kitchen.yml +++ b/.kitchen.yml @@ -26,9 +26,8 @@ platforms: image: electrical/debian:7.3 privileged: true provision_command: - - echo 'deb http://http.debian.net/debian/ wheezy-backports main' >> /etc/apt/sources.list - - apt-get update - - apt-get install -y -q ansible + - apt-get update && apt-get -y install python python-dev python-pip build-essential libyaml-dev python-yaml + - pip install ansible - apt-get install -y -q net-tools use_sudo: false - name: debian-8 @@ -36,8 +35,8 @@ platforms: image: electrical/debian:8 privileged: true provision_command: - - apt-get update - - apt-get install -y -q ansible + - apt-get update && apt-get -y install python python-dev python-pip build-essential libyaml-dev python-yaml + - pip install ansible - apt-get install -y -q net-tools - sed -ri 's/^#?PermitRootLogin .*/PermitRootLogin yes/' /etc/ssh/sshd_config - sed -ri 's/^#?PasswordAuthentication .*/PasswordAuthentication yes/' /etc/ssh/sshd_config @@ -48,11 +47,17 @@ platforms: driver_config: image: electrical/centos:6.4-1 privileged: true + provision_command: + - yum -y install gmp-devel python-devel python-pip + - pip install ansible use_sudo: false - name: centos-7 driver_config: image: electrical/centos:7 provision_command: + - yum -y install gmp-devel python-devel python-pip + - yum -y groupinstall "Development Tools" + - pip install ansible - sed -ri 's/^#?PermitRootLogin .*/PermitRootLogin yes/' /etc/ssh/sshd_config - sed -ri 's/^#?PasswordAuthentication .*/PasswordAuthentication yes/' /etc/ssh/sshd_config - sed -ri 's/^#?UsePAM .*/UsePAM no/' /etc/ssh/sshd_config diff --git a/Gemfile b/Gemfile index cd4bcfb..8607482 100644 --- a/Gemfile +++ b/Gemfile @@ -2,5 +2,5 @@ source 'https://rubygems.org' gem 'test-kitchen' gem "kitchen-docker", '< 2.2.0' -gem 'kitchen-ansible' +gem 'kitchen-ansible', '0.40.1' gem 'net-ssh', '~> 2.0' diff --git a/README.md b/README.md index 1a95b7f..686adbe 100644 --- a/README.md +++ b/README.md @@ -8,7 +8,7 @@ Ansible role for Elasticsearch. Currently this works on Debian and RedHat based * Centos 6 * Centos 7 -The latest Elasticsearch versions of 1.7.x and 2.1.x are actively tested. +The latest Elasticsearch versions of 1.7.x and 2.x are actively tested. ## Usage @@ -54,7 +54,18 @@ The following illustrates applying configuration parameters to an Elasticsearch hosts: localhost roles: #expand to all available parameters - - { 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 } } + - { role: elasticsearch, es_instance_name: "node1", es_data_dirs: "/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 @@ -84,7 +95,18 @@ A more complex example: hosts: localhost roles: #expand to all available parameters - - { 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 } } + - { role: elasticsearch, es_instance_name: "node1", es_data_dirs: "/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 @@ -126,8 +148,28 @@ recommended in any multi node cluster configuration. - hosts: data_nodes roles: - - { role: elasticsearch, es_instance_name: "node1", es_data_dir: "/opt/elasticsearch", es_config: { "discovery.zen.ping.multicast.enabled": false, discovery.zen.ping.unicast.hosts: "elastic02:9300", http.port: 9200, transport.tcp.port: 9300, node.data: true, node.master: false, bootstrap.mlockall: false, discovery.zen.ping.multicast.enabled: false } } - - { role: elasticsearch, es_instance_name: "node2", es_config: { "discovery.zen.ping.multicast.enabled": false, discovery.zen.ping.unicast.hosts: "elastic02:9300", http.port: 9201, transport.tcp.port: 9301, node.data: true, node.master: false, bootstrap.mlockall: false, discovery.zen.ping.multicast.enabled: false } } + - { role: elasticsearch, es_instance_name: "node1", es_data_dirs: "/opt/elasticsearch", + es_config: { + "discovery.zen.ping.multicast.enabled": false, + discovery.zen.ping.unicast.hosts: "elastic02:9300", + http.port: 9200, + transport.tcp.port: 9300, + node.data: true, + node.master: false, + bootstrap.mlockall: false, + discovery.zen.ping.multicast.enabled: false } + } + - { role: elasticsearch, es_instance_name: "node2", + es_config: { + "discovery.zen.ping.multicast.enabled": false, + discovery.zen.ping.unicast.hosts: "elastic02:9300", + http.port: 9201, + transport.tcp.port: 9301, + node.data: true, + node.master: false, + bootstrap.mlockall: false, + discovery.zen.ping.multicast.enabled: false } + } vars: es_scripts: false es_templates: false @@ -159,7 +201,7 @@ Following variables affect the versions installed: * ```es_version``` (e.g. "1.5.2"). * ```es_start_service``` (true (default) or false) * ```es_plugins_reinstall``` (true or false (default) ) -* ```es_plugins``` (an array of plugin definitons e.g.: +* ```es_plugins``` (an array of plugin definitions e.g.: ``` es_plugins: @@ -183,10 +225,12 @@ By default, each node on a host will be installed to use unique pid, plugin, wor controlled by the following parameters: * ```es_pid_dir``` - defaults to "/var/run/elasticsearch". -* ```es_data_dir``` - defaults to "/var/lib/elasticsearch". +* ```es_data_dirs``` - defaults to "/var/lib/elasticsearch". This can be a list or comma separated string e.g. ["/opt/elasticsearch/data-1","/opt/elasticsearch/data-2"] or "/opt/elasticsearch/data-1,/opt/elasticsearch/data-2" * ```es_log_dir``` - defaults to "/var/log/elasticsearch". * ```es_work_dir``` - defaults to "/tmp/elasticsearch". * ```es_plugin_dir``` - defaults to "/usr/share/elasticsearch/plugins". +* ```es_restart_on_change``` - defaults to true. If false, changes will not result in Elasticsearch being restarted. +* ```es_plugins_reinstall``` - defaults to false. If true, all currently installed plugins will be removed from a node. Listed plugins will then be re-installed. This role ships with sample scripts and templates located in the [files/scripts/](files/scripts) and [files/templates/](files/templates) directories, respectively. These variables are used with the Ansible [with_fileglob](http://docs.ansible.com/ansible/playbooks_loops.html#id4) loop. When setting the globs, be sure to use an absolute path. * ```es_scripts_fileglob``` - defaults to `/files/scripts/`. @@ -203,3 +247,8 @@ all supported platforms. Elasticsearch restarted where required. * Systemd is used for Ubuntu versions >= 15, Debian >=8, Centos >=7. All other versions use init for service scripts. +## IMPORTANT NOTES RE PLUGIN MANAGEMENT + +* If the ES version is changed, all plugins will be removed. Those listed in the playbook will be re-installed. This is behaviour is required in ES 2.x. +* If no plugins are listed in the playbook for a node, all currently installed plugins will be removed. +* The role does not currently support automatic detection of differences between installed and listed plugins (other than if none are listed). Should users wish to change installed plugins should set es_plugins_reinstall to true. This will cause all currently installed plugins to be removed and those listed to be installed. Change detection will be implemented in future releases. \ No newline at end of file diff --git a/defaults/main.yml b/defaults/main.yml index 924b229..7bf9af0 100644 --- a/defaults/main.yml +++ b/defaults/main.yml @@ -13,7 +13,7 @@ es_group: elasticsearch es_config: {} #Need to provide default directories es_pid_dir: "/var/run/elasticsearch" -es_data_dir: "/var/lib/elasticsearch" +es_data_dirs: "/var/lib/elasticsearch" es_log_dir: "/var/log/elasticsearch" es_work_dir: "/tmp/elasticsearch" es_plugin_dir: "/usr/share/elasticsearch/plugins" \ No newline at end of file diff --git a/filter_plugins/custom.py b/filter_plugins/custom.py new file mode 100644 index 0000000..0453a25 --- /dev/null +++ b/filter_plugins/custom.py @@ -0,0 +1,26 @@ +__author__ = 'dale mcdiarmid' + +import re + +def modify_list(values=[], pattern='', replacement='', ignorecase=False): + ''' Perform a `re.sub` on every item in the list''' + if ignorecase: + flags = re.I + else: + flags = 0 + _re = re.compile(pattern, flags=flags) + return [_re.sub(replacement, value) for value in values] + +def append_to_list(values=[], suffix=''): + if isinstance(values, basestring): + values = values.split(',') + return [str(value+suffix) for value in values] + +def array_to_str(values=[],separator=','): + return separator.join(values) + +class FilterModule(object): + def filters(self): + return {'modify_list': modify_list, + 'append_to_list':append_to_list, + 'array_to_str':array_to_str} \ No newline at end of file diff --git a/tasks/elasticsearch-config.yml b/tasks/elasticsearch-config.yml index b247f63..70a1f42 100644 --- a/tasks/elasticsearch-config.yml +++ b/tasks/elasticsearch-config.yml @@ -17,32 +17,31 @@ #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 }} +- set_fact: instance_suffix={{inventory_hostname}}-{{ es_instance_name }} -- set_fact: data_dir={{ es_data_dir }}/{{inventory_hostname}}-{{ es_instance_name }} +- set_fact: pid_dir={{ es_pid_dir }}/{{instance_suffix}} -- set_fact: log_dir={{ es_log_dir }}/{{inventory_hostname}}-{{ es_instance_name }} +- set_fact: log_dir={{ es_log_dir }}/{{instance_suffix}} -- set_fact: work_dir={{ es_work_dir }}/{{inventory_hostname}}-{{ es_instance_name }} +- set_fact: work_dir={{ es_work_dir }}/{{instance_suffix}} #Create required directories -- name: Create PID Directory - file: path={{ pid_dir }} state=directory owner={{ es_user }} group={{ es_group }} +- name: Create Directories + file: path={{ item }} state=directory owner={{ es_user }} group={{ es_group }} + with_items: + - "{{pid_dir}}" + - "{{work_dir}}" + - "{{log_dir}}" + - "{{conf_dir}}" + - "{{plugin_dir}}" -- name: Create data dir - file: state=directory path={{ data_dir }} owner={{ es_user }} group={{ es_group }} +- set_fact: data_dirs={{ es_data_dirs | append_to_list('/'+instance_suffix) }} -- name: Create work dir - file: state=directory path={{ work_dir }} owner={{ es_user }} group={{ es_group }} +- name: Create Data Directories + file: path={{ item }} state=directory owner={{ es_user }} group={{ es_group }} + with_items: + - "{{data_dirs}}" -- name: Create log dir - file: state=directory path={{ log_dir }} owner={{ es_user }} group={{ es_group }} - -- name: Create Config Directory - file: path={{ conf_dir }} state=directory owner={{ es_user }} group={{ es_group }} - -- name: Create Plugin Directory - file: state=directory path={{ plugin_dir }} owner={{ es_user }} group={{ es_group }} #Copy the config template - name: Copy Configuration File @@ -57,13 +56,13 @@ #Copy the instance specific init file - name: Copy Debian Init File for Instance template: src=init/debian/elasticsearch.j2 dest={{instance_init_script}} mode=0755 force=yes - when: ansible_os_family == 'Debian' + when: ansible_os_family == 'Debian' and not use_system_d notify: restart elasticsearch #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' and not use_system_d notify: restart elasticsearch #Copy the systemd specific file if systemd is installed @@ -92,3 +91,11 @@ - name: Delete Default Sysconfig File file: dest=/usr/lib/systemd/system/elasticsearch.service state=absent + +- name: Delete Default Configuration File + file: dest=/etc/elasticsearch/elasticsearch.yml state=absent + +- name: Delete Default Logging File + file: dest=/etc/elasticsearch/logging.yml state=absent + +- debug: msg="Data Dirs {{data_dirs}}" \ No newline at end of file diff --git a/tasks/elasticsearch-plugins.yml b/tasks/elasticsearch-plugins.yml index 28e9ec8..46f0b51 100644 --- a/tasks/elasticsearch-plugins.yml +++ b/tasks/elasticsearch-plugins.yml @@ -1,22 +1,32 @@ --- -#es_plugins_reinstall will be set to true if elasticsearch_install.changed i.e. we have changed ES version +#es_plugins_reinstall will be set to true if elasticsearch_install.changed i.e. we have changed ES version, or if no plugins listed. Otherwise it is false and requires explicitly setting. - set_fact: es_plugins_reinstall=true - when: elasticsearch_install.changed + when: elasticsearch_install.changed or es_plugins is not defined or es_plugins is none + +- set_fact: list_command="list" + +- set_fact: list_command="--list" + when: es_version | version_compare('2.0', '<') #List currently installed plugins +- shell: "{{es_home}}/bin/plugin {{list_command}} | sed -n '1!p' | cut -d '-' -f2-" + register: installed_plugins + changed_when: False + environment: + CONF_DIR: "{{ conf_dir }}" + ES_INCLUDE: "{{ instance_default_file }}" - - -#This needs to removed installed plugins not those listed +#This needs to removes any currently installed plugins - name: Remove elasticsearch plugins - command: "{{es_home}}/bin/plugin remove {{ item.plugin }} --silent" + command: "{{es_home}}/bin/plugin remove {{item}} --silent" ignore_errors: yes - with_items: es_plugins - when: es_plugins_reinstall + with_items: installed_plugins.stdout_lines + when: es_plugins_reinstall and installed_plugins.stdout_lines | length > 0 and not 'No plugin detected' in installed_plugins.stdout_lines[0] notify: restart elasticsearch environment: CONF_DIR: "{{ conf_dir }}" + ES_INCLUDE: "{{ instance_default_file }}" - name: Install elasticsearch plugins #debug: var=item @@ -25,7 +35,7 @@ failed_when: "'Failed to install' in plugin_installed.stderr" changed_when: plugin_installed.rc == 0 with_items: es_plugins - when: ansible_os_family == 'RedHat' or ansible_os_family == 'Debian' + when: es_plugins is defined and not es_plugins is none notify: restart elasticsearch environment: CONF_DIR: "{{ conf_dir }}" diff --git a/tasks/elasticsearch-scripts.yml b/tasks/elasticsearch-scripts.yml index 6d7d297..aa363e8 100644 --- a/tasks/elasticsearch-scripts.yml +++ b/tasks/elasticsearch-scripts.yml @@ -7,8 +7,11 @@ - name: Create script dir file: state=directory path={{ es_script_dir }} owner={{ es_user }} group={{ es_group }} - when: es_config['path.scripts'] is defined + +- name: Copy default scripts to elasticsearch + copy: src=scripts dest={{ es_script_dir }} owner={{ es_user }} group={{ es_group }} + when: es_scripts_fileglob is not defined - name: Copy scripts to elasticsearch copy: src={{ item }} dest={{ es_script_dir }} owner={{ es_user }} group={{ es_group }} - with_fileglob: es_scripts_fileglob | default("scripts") + with_fileglob: es_scripts_fileglob diff --git a/tasks/elasticsearch-templates.yml b/tasks/elasticsearch-templates.yml index ba46fd8..0fe3a0f 100644 --- a/tasks/elasticsearch-templates.yml +++ b/tasks/elasticsearch-templates.yml @@ -1,8 +1,14 @@ --- +- file: path=/etc/elasticsearch/templates state=directory owner={{ es_user }} group={{ es_group }} + +- name: Copy default templates to elasticsearch + copy: src=templates dest=/etc/elasticsearch/ owner={{ es_user }} group={{ es_group }} + when: es_templates_fileglob is not defined + - name: Copy templates to elasticsearch copy: src={{ item }} dest=/etc/elasticsearch/ owner={{ es_user }} group={{ es_group }} - with_fileglob: es_templates_fileglob | default("templates") + with_fileglob: es_templates_fileglob - set_fact: http_port=9200 diff --git a/tasks/main.yml b/tasks/main.yml index e021b5d..eb7ecc4 100644 --- a/tasks/main.yml +++ b/tasks/main.yml @@ -9,7 +9,7 @@ - include: elasticsearch-scripts.yml when: es_scripts - include: elasticsearch-plugins.yml - when: es_plugins is defined + when: es_plugins is defined or es_plugins_reinstall - include: elasticsearch-service.yml - include: elasticsearch-templates.yml when: es_templates diff --git a/templates/elasticsearch.j2 b/templates/elasticsearch.j2 index da71a7b..fafb5e2 100644 --- a/templates/elasticsearch.j2 +++ b/templates/elasticsearch.j2 @@ -9,7 +9,7 @@ ES_HOME={{es_home}} CONF_DIR={{conf_dir}} # Elasticsearch data directory -DATA_DIR={{data_dir}} +DATA_DIR={{ data_dirs | array_to_str }} # Elasticsearch logs directory LOG_DIR={{log_dir}} diff --git a/templates/elasticsearch.yml.j2 b/templates/elasticsearch.yml.j2 index 32db02d..203a869 100644 --- a/templates/elasticsearch.yml.j2 +++ b/templates/elasticsearch.yml.j2 @@ -16,7 +16,7 @@ node.name: {{inventory_hostname}}-{{es_instance_name}} # Path to directory containing configuration (this file and logging.yml): path.conf: {{ conf_dir }} -path.data: {{ data_dir }} +path.data: {{ data_dirs | array_to_str }} path.work: {{ work_dir }} diff --git a/templates/init/debian/elasticsearch.j2 b/templates/init/debian/elasticsearch.j2 index 02206cc..5512728 100755 --- a/templates/init/debian/elasticsearch.j2 +++ b/templates/init/debian/elasticsearch.j2 @@ -10,7 +10,7 @@ # Modified by Nicolas Huray for Elasticsearch . # ### BEGIN INIT INFO -# Provides: elasticsearch +# Provides: {{es_instance_name}}_{{default_file | basename}} # Required-Start: $network $remote_fs $named # Required-Stop: $network $remote_fs $named # Default-Start: 2 3 4 5 diff --git a/templates/systemd/elasticsearch.j2 b/templates/systemd/elasticsearch.j2 index 35c48a1..8d400de 100644 --- a/templates/systemd/elasticsearch.j2 +++ b/templates/systemd/elasticsearch.j2 @@ -7,7 +7,7 @@ After=network-online.target [Service] Environment=ES_HOME={{es_home}} Environment=CONF_DIR={{conf_dir}} -Environment=DATA_DIR={{data_dir}} +Environment=DATA_DIR={{ data_dirs | array_to_str }} Environment=LOG_DIR={{log_dir}} Environment=PID_DIR={{pid_dir}} EnvironmentFile=-{{instance_default_file}} diff --git a/test/integration/config.yml b/test/integration/config.yml index 9bd8936..df13fe1 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_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 } } + - { role: elasticsearch, es_instance_name: "node1", es_data_dirs: ["/opt/elasticsearch/data-1","/opt/elasticsearch/data-2"], 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/helpers/serverspec/config_spec.rb b/test/integration/helpers/serverspec/config_spec.rb index f8266fb..7eeb44c 100644 --- a/test/integration/helpers/serverspec/config_spec.rb +++ b/test/integration/helpers/serverspec/config_spec.rb @@ -30,7 +30,7 @@ shared_examples 'config::init' do |es_version| 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: /opt/elasticsearch/data/localhost-node1' } + it { should contain 'path.data: /opt/elasticsearch/data-1/localhost-node1,/opt/elasticsearch/data-2/localhost-node1' } it { should contain 'path.work: /opt/elasticsearch/temp/localhost-node1' } it { should contain 'path.logs: /opt/elasticsearch/logs/localhost-node1' } end @@ -41,7 +41,12 @@ shared_examples 'config::init' do |es_version| it { should be_owned_by 'elasticsearch' } end - describe file('/opt/elasticsearch/data/localhost-node1') do + describe file('/opt/elasticsearch/data-1/localhost-node1') do + it { should be_directory } + it { should be_owned_by 'elasticsearch' } + end + + describe file('/opt/elasticsearch/data-2/localhost-node1') do it { should be_directory } it { should be_owned_by 'elasticsearch' } end @@ -56,10 +61,6 @@ shared_examples 'config::init' do |es_version| 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 describe command('curl -s "localhost:9201"') do #TODO: This is returning an empty string @@ -82,11 +83,42 @@ shared_examples 'config::init' do |es_version| end end - #Not copied on Debian 8 - #describe file('/usr/lib/systemd/system/node1_elasticsearch.service') do - # it { should be_file } - # it { should contain 'LimitMEMLOCK=infinity' } - #end + describe file('/etc/init.d/elasticsearch') do + it { should_not exist } + end + describe file('/etc/default/elasticsearch') do + it { should_not exist } + end + + describe file('/etc/sysconfig/elasticsearch') do + it { should_not exist } + end + + describe file('/usr/lib/systemd/system/elasticsearch.service') do + it { should_not exist } + end + + describe file('/etc/elasticsearch/elasticsearch.yml') do + it { should_not exist } + end + + #Init vs Systemd tests + #Ubuntu 15 and up + #Debian 8 and up + #Centos 7 and up + + if (((os[:family] == 'redhat' || os[:family] == 'centos') && os[:release].to_f >= 7.0) || + (os[:family] == 'ubuntu' && os[:release].to_f >= 15.0) || + (os[:family] == 'debian' && os[:release].to_f >= 8.0)) + describe file('/usr/lib/systemd/system/node1_elasticsearch.service') do + it { should be_file } + it { should contain 'LimitMEMLOCK=infinity' } + end + else + describe file('/etc/init.d/node1_elasticsearch') do + it { should be_file } + end + end end diff --git a/test/integration/helpers/serverspec/multi_spec.rb b/test/integration/helpers/serverspec/multi_spec.rb index 74a8f58..1042ef6 100644 --- a/test/integration/helpers/serverspec/multi_spec.rb +++ b/test/integration/helpers/serverspec/multi_spec.rb @@ -29,7 +29,7 @@ shared_examples 'multi::init' do |es_version,plugins| it { should contain 'node.name: localhost-node1' } it { should_not contain 'bootstrap.mlockall: true' } it { should contain 'path.conf: /etc/elasticsearch/node1' } - it { should contain 'path.data: /var/lib/elasticsearch/localhost-node1' } + it { should contain 'path.data: /opt/elasticsearch/data-1/localhost-node1,/opt/elasticsearch/data-2/localhost-node1' } it { should contain 'path.work: /tmp/elasticsearch/localhost-node1' } it { should contain 'path.logs: /var/log/elasticsearch/localhost-node1' } end @@ -46,7 +46,7 @@ shared_examples 'multi::init' do |es_version,plugins| it { should contain 'node.name: localhost-master' } it { should contain 'bootstrap.mlockall: true' } it { should contain 'path.conf: /etc/elasticsearch/master' } - it { should contain 'path.data: /opt/elasticsearch/localhost-master' } + it { should contain 'path.data: /opt/elasticsearch/master/localhost-master' } it { should contain 'path.work: /tmp/elasticsearch/localhost-master' } it { should contain 'path.logs: /var/log/elasticsearch/localhost-master' } end @@ -129,16 +129,18 @@ shared_examples 'multi::init' do |es_version,plugins| end #Confirm that the data directory has only been set for the first node - describe file('/opt/elasticsearch/localhost-master') do + describe file('/opt/elasticsearch/master/localhost-master') do it { should be_directory } it { should be_owned_by 'elasticsearch' } end - describe file('/opt/elasticsearch/localhost-node1') do - it { should_not exist } + describe file('/opt/elasticsearch/data-1/localhost-node1') do + it { should be_directory } + it { should be_owned_by 'elasticsearch' } end - describe file('/var/lib/elasticsearch/localhost-node1') do + + describe file('/opt/elasticsearch/data-2/localhost-node1') do it { should be_directory } it { should be_owned_by 'elasticsearch' } end @@ -203,6 +205,25 @@ shared_examples 'multi::init' do |es_version,plugins| end end + describe file('/etc/init.d/elasticsearch') do + it { should_not exist } + end + + describe file('/etc/default/elasticsearch') do + it { should_not exist } + end + + describe file('/etc/sysconfig/elasticsearch') do + it { should_not exist } + end + + describe file('/usr/lib/systemd/system/elasticsearch.service') do + it { should_not exist } + end + + describe file('/etc/elasticsearch/elasticsearch.yml') do + it { should_not exist } + end diff --git a/test/integration/helpers/serverspec/package_spec.rb b/test/integration/helpers/serverspec/package_spec.rb index fe99c69..1e4218e 100644 --- a/test/integration/helpers/serverspec/package_spec.rb +++ b/test/integration/helpers/serverspec/package_spec.rb @@ -83,5 +83,25 @@ shared_examples 'package::init' do |es_version,plugins| end end + describe file('/etc/init.d/elasticsearch') do + it { should_not exist } + end + + describe file('/etc/default/elasticsearch') do + it { should_not exist } + end + + describe file('/etc/sysconfig/elasticsearch') do + it { should_not exist } + end + + describe file('/usr/lib/systemd/system/elasticsearch.service') do + it { should_not exist } + end + + describe file('/etc/elasticsearch/elasticsearch.yml') do + it { should_not exist } + end + end diff --git a/test/integration/helpers/serverspec/standard_spec.rb b/test/integration/helpers/serverspec/standard_spec.rb index a79fde0..05b8e0e 100644 --- a/test/integration/helpers/serverspec/standard_spec.rb +++ b/test/integration/helpers/serverspec/standard_spec.rb @@ -63,5 +63,9 @@ shared_examples 'standard::init' do |es_version| it { should_not exist } end + describe file('/etc/elasticsearch/elasticsearch.yml') do + it { should_not exist } + end + end diff --git a/test/integration/multi.yml b/test/integration/multi.yml index 33b9534..e291fcb 100644 --- a/test/integration/multi.yml +++ b/test/integration/multi.yml @@ -3,8 +3,8 @@ - name: Elasticsearch Multi tests hosts: localhost roles: - - { role: elasticsearch, es_instance_name: "master", es_data_dir: "/opt/elasticsearch", es_heap_size: "1g", es_config: { "discovery.zen.ping.multicast.enabled": false, discovery.zen.ping.unicast.hosts: "localhost:9300", http.port: 9200, transport.tcp.port: 9300, node.data: false, node.master: true, bootstrap.mlockall: true, discovery.zen.ping.multicast.enabled: false } } - - { role: elasticsearch, es_instance_name: "node1", es_config: { "discovery.zen.ping.multicast.enabled": false, discovery.zen.ping.unicast.hosts: "localhost:9300", http.port: 9201, transport.tcp.port: 9301, node.data: true, node.master: false, discovery.zen.ping.multicast.enabled: false } } + - { role: elasticsearch, es_instance_name: "master", es_data_dirs: ["/opt/elasticsearch/master"], es_heap_size: "1g", es_config: { "discovery.zen.ping.multicast.enabled": false, discovery.zen.ping.unicast.hosts: "localhost:9300", http.port: 9200, transport.tcp.port: 9300, node.data: false, node.master: true, bootstrap.mlockall: true, discovery.zen.ping.multicast.enabled: false } } + - { role: elasticsearch, es_instance_name: "node1", es_data_dirs: "/opt/elasticsearch/data-1,/opt/elasticsearch/data-2", es_config: { "discovery.zen.ping.multicast.enabled": false, discovery.zen.ping.unicast.hosts: "localhost:9300", http.port: 9201, transport.tcp.port: 9301, node.data: true, node.master: false, discovery.zen.ping.multicast.enabled: false } } vars: es_scripts: true es_templates: true