Skip to content
This repository was archived by the owner on Jun 24, 2022. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions defaults/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ es_version: "2.1.0"
es_version_lock: false
es_use_repository: true
es_start_service: true
es_restart_on_change: true
es_plugins_reinstall: false
es_scripts: false
es_templates: false
Expand Down
2 changes: 1 addition & 1 deletion handlers/main.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@

- name: restart elasticsearch
service: name={{instance_init_script | basename}} state=restarted enabled=yes
when: es_start_service and (not elasticsearch_started.changed or (plugin_installed is defined and plugin_installed.changed))
when: es_restart_on_change and es_start_service and (not elasticsearch_started.changed or (plugin_installed is defined and plugin_installed.changed) or elasticsearch_install.changed)
19 changes: 15 additions & 4 deletions tasks/elasticsearch-config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,7 @@
#Relies on elasticsearch distribution installing a serviced script to determine whether one should be copied.


- stat: path={{sysd_script}}
register: systemd_service

- set_fact: use_system_d={{systemd_service.stat.exists and ((ansible_distribution == 'Debian' and ansible_distribution_version | version_compare('8', '>=')) or (ansible_distribution == 'CentOS' and ansible_distribution_version | version_compare('7', '>=')) or (ansible_distribution == 'Ubuntu' and ansible_distribution_version | version_compare('15', '>='))) }}
- set_fact: use_system_d={{(ansible_distribution == 'Debian' and ansible_distribution_version | version_compare('8', '>=')) or (ansible_distribution == 'CentOS' and ansible_distribution_version | version_compare('7', '>=')) or (ansible_distribution == 'Ubuntu' and ansible_distribution_version | version_compare('15', '>=')) }}

- set_fact: instance_sysd_script={{sysd_script | dirname }}/{{es_instance_name}}_{{sysd_script | basename}}
when: use_system_d
Expand Down Expand Up @@ -81,3 +78,17 @@
notify: restart elasticsearch

#Clean up un-wanted package scripts to avoid confusion

- name: Delete Default Init
file: dest=/etc/init.d/elasticsearch state=absent

- name: Delete Default Environment File
file: dest=/etc/default/elasticsearch state=absent
when: ansible_os_family == 'Debian'

- name: Delete Default Environment File
file: dest=/etc/sysconfig/elasticsearch state=absent
when: ansible_os_family == 'RedHat'

- name: Delete Default Sysconfig File
file: dest=/usr/lib/systemd/system/elasticsearch.service state=absent
11 changes: 10 additions & 1 deletion tasks/elasticsearch-plugins.yml
Original file line number Diff line number Diff line change
@@ -1,10 +1,19 @@
---

#es_plugins_reinstall will be set to true if elasticsearch_install.changed i.e. we have changed ES version
- set_fact: es_plugins_reinstall=true
when: elasticsearch_install.changed

#List currently installed plugins



#This needs to removed installed plugins not those listed
- name: Remove elasticsearch plugins
command: "{{es_home}}/bin/plugin remove {{ item.plugin }} --silent"
ignore_errors: yes
with_items: es_plugins
when: ( ansible_os_family == 'RedHat' or ansible_os_family == 'Debian' ) and es_plugins_reinstall
when: es_plugins_reinstall
notify: restart elasticsearch
environment:
CONF_DIR: "{{ conf_dir }}"
Expand Down
6 changes: 6 additions & 0 deletions tasks/elasticsearch-service.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# Make sure the service is started, and restart if necessary
- name: Start elasticsearch service
service: name={{instance_init_script | basename}} state=started enabled=yes
when: es_start_service
register: elasticsearch_started

19 changes: 4 additions & 15 deletions tasks/elasticsearch.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,25 +8,14 @@

- debug: msg="Node configuration {{ es_config }} "

# Install OS specific elasticsearch - this can be abbreviated in version 2.0.0
#- name: Include specific Elasticsearch
# include: "elasticsearch-{{ansible_os_family}}.yml"

#Install OS specific elasticsearch - this can be abbreviated in version 2.0.0
- name: Include specific Elasticsearch
include: elasticsearch-Debian.yml
when: ansible_os_family == 'Debian'

- name: Include specific Elasticsearch
include: elasticsearch-RedHat.yml
when: ansible_os_family == 'RedHat'

#Configuration file for elasticsearch
- name: Elasticsearch configuration
include: elasticsearch-config.yml

# Make sure the service is started, and restart if necessary
- name: Start elasticsearch service
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 enabled=yes
when: es_start_service and elasticsearch_install.changed and not elasticsearch_started.changed
6 changes: 4 additions & 2 deletions tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,12 @@
include_vars: "{{ansible_os_family}}.yml"
- include: java.yml
- include: elasticsearch.yml
- include: elasticsearch-plugins.yml
when: es_plugins is defined
- include: elasticsearch-config.yml
- include: elasticsearch-scripts.yml
when: es_scripts
- include: elasticsearch-plugins.yml
when: es_plugins is defined
- include: elasticsearch-service.yml
- include: elasticsearch-templates.yml
when: es_templates
- meta: flush_handlers
16 changes: 16 additions & 0 deletions test/integration/helpers/serverspec/standard_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -47,5 +47,21 @@
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

end

1 change: 0 additions & 1 deletion vars/Debian.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
---
java: "openjdk-7-jre-headless"
default_file: "/etc/default/elasticsearch"
init_script: "/etc/init.d/elasticsearch"
es_home: "/usr/share/elasticsearch"
1 change: 0 additions & 1 deletion vars/RedHat.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
---
java: "java-1.8.0-openjdk.x86_64"
default_file: "/etc/sysconfig/elasticsearch"
init_script: "/etc/init.d/elasticsearch"
es_home: "/usr/share/elasticsearch"
3 changes: 2 additions & 1 deletion vars/main.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
---
es_package_url: "https://download.elastic.co/elasticsearch/elasticsearch/elasticsearch"
es_conf_dir: "/etc/elasticsearch"
sysd_script: "/usr/lib/systemd/system/elasticsearch.service"
sysd_script: "/usr/lib/systemd/system/elasticsearch.service"
init_script: "/etc/init.d/elasticsearch"