Skip to content

Commit b7d8300

Browse files
author
gingerwizard
committed
Merge pull request elastic#82 from gingerwizard/master
Improved Plugin Support, More Tests, Refactors, Consistent Ansible version
2 parents 40fd351 + f55f5c3 commit b7d8300

21 files changed

+253
-71
lines changed

.gitignore

-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
.kitchen/
2-
.kitchen.local.yml
32
*.lock
43
.vendor
54
.bundle

.kitchen.yml

+10-5
Original file line numberDiff line numberDiff line change
@@ -26,18 +26,17 @@ platforms:
2626
image: electrical/debian:7.3
2727
privileged: true
2828
provision_command:
29-
- echo 'deb http://http.debian.net/debian/ wheezy-backports main' >> /etc/apt/sources.list
30-
- apt-get update
31-
- apt-get install -y -q ansible
29+
- apt-get update && apt-get -y install python python-dev python-pip build-essential libyaml-dev python-yaml
30+
- pip install ansible
3231
- apt-get install -y -q net-tools
3332
use_sudo: false
3433
- name: debian-8
3534
driver_config:
3635
image: electrical/debian:8
3736
privileged: true
3837
provision_command:
39-
- apt-get update
40-
- apt-get install -y -q ansible
38+
- apt-get update && apt-get -y install python python-dev python-pip build-essential libyaml-dev python-yaml
39+
- pip install ansible
4140
- apt-get install -y -q net-tools
4241
- sed -ri 's/^#?PermitRootLogin .*/PermitRootLogin yes/' /etc/ssh/sshd_config
4342
- sed -ri 's/^#?PasswordAuthentication .*/PasswordAuthentication yes/' /etc/ssh/sshd_config
@@ -48,11 +47,17 @@ platforms:
4847
driver_config:
4948
image: electrical/centos:6.4-1
5049
privileged: true
50+
provision_command:
51+
- yum -y install gmp-devel python-devel python-pip
52+
- pip install ansible
5153
use_sudo: false
5254
- name: centos-7
5355
driver_config:
5456
image: electrical/centos:7
5557
provision_command:
58+
- yum -y install gmp-devel python-devel python-pip
59+
- yum -y groupinstall "Development Tools"
60+
- pip install ansible
5661
- sed -ri 's/^#?PermitRootLogin .*/PermitRootLogin yes/' /etc/ssh/sshd_config
5762
- sed -ri 's/^#?PasswordAuthentication .*/PasswordAuthentication yes/' /etc/ssh/sshd_config
5863
- sed -ri 's/^#?UsePAM .*/UsePAM no/' /etc/ssh/sshd_config

Gemfile

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,5 @@ source 'https://rubygems.org'
22

33
gem 'test-kitchen'
44
gem "kitchen-docker", '< 2.2.0'
5-
gem 'kitchen-ansible'
5+
gem 'kitchen-ansible', '0.40.1'
66
gem 'net-ssh', '~> 2.0'

README.md

+56-7
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ Ansible role for Elasticsearch. Currently this works on Debian and RedHat based
88
* Centos 6
99
* Centos 7
1010

11-
The latest Elasticsearch versions of 1.7.x and 2.1.x are actively tested.
11+
The latest Elasticsearch versions of 1.7.x and 2.x are actively tested.
1212

1313
## Usage
1414

@@ -54,7 +54,18 @@ The following illustrates applying configuration parameters to an Elasticsearch
5454
hosts: localhost
5555
roles:
5656
#expand to all available parameters
57-
- { 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 } }
57+
- { role: elasticsearch, es_instance_name: "node1", es_data_dirs: "/opt/elasticsearch/data", es_log_dir: "/opt/elasticsearch/logs", es_work_dir: "/opt/elasticsearch/temp",
58+
es_config: {
59+
node.name: "node1",
60+
cluster.name: "custom-cluster",
61+
discovery.zen.ping.unicast.hosts: "localhost:9301",
62+
http.port: 9201,
63+
transport.tcp.port: 9301,
64+
node.data: false,
65+
node.master: true,
66+
bootstrap.mlockall: true,
67+
discovery.zen.ping.multicast.enabled: false }
68+
}
5869
vars:
5970
es_scripts: false
6071
es_templates: false
@@ -84,7 +95,18 @@ A more complex example:
8495
hosts: localhost
8596
roles:
8697
#expand to all available parameters
87-
- { 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 } }
98+
- { role: elasticsearch, es_instance_name: "node1", es_data_dirs: "/opt/elasticsearch/data", es_log_dir: "/opt/elasticsearch/logs", es_work_dir: "/opt/elasticsearch/temp",
99+
es_config: {
100+
node.name: "node1",
101+
cluster.name: "custom-cluster",
102+
discovery.zen.ping.unicast.hosts: "localhost:9301",
103+
http.port: 9201,
104+
transport.tcp.port: 9301,
105+
node.data: false,
106+
node.master: true,
107+
bootstrap.mlockall: true,
108+
discovery.zen.ping.multicast.enabled: false }
109+
}
88110
vars:
89111
es_scripts: false
90112
es_templates: false
@@ -126,8 +148,28 @@ recommended in any multi node cluster configuration.
126148
127149
- hosts: data_nodes
128150
roles:
129-
- { 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 } }
130-
- { 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 } }
151+
- { role: elasticsearch, es_instance_name: "node1", es_data_dirs: "/opt/elasticsearch",
152+
es_config: {
153+
"discovery.zen.ping.multicast.enabled": false,
154+
discovery.zen.ping.unicast.hosts: "elastic02:9300",
155+
http.port: 9200,
156+
transport.tcp.port: 9300,
157+
node.data: true,
158+
node.master: false,
159+
bootstrap.mlockall: false,
160+
discovery.zen.ping.multicast.enabled: false }
161+
}
162+
- { role: elasticsearch, es_instance_name: "node2",
163+
es_config: {
164+
"discovery.zen.ping.multicast.enabled": false,
165+
discovery.zen.ping.unicast.hosts: "elastic02:9300",
166+
http.port: 9201,
167+
transport.tcp.port: 9301,
168+
node.data: true,
169+
node.master: false,
170+
bootstrap.mlockall: false,
171+
discovery.zen.ping.multicast.enabled: false }
172+
}
131173
vars:
132174
es_scripts: false
133175
es_templates: false
@@ -159,7 +201,7 @@ Following variables affect the versions installed:
159201
* ```es_version``` (e.g. "1.5.2").
160202
* ```es_start_service``` (true (default) or false)
161203
* ```es_plugins_reinstall``` (true or false (default) )
162-
* ```es_plugins``` (an array of plugin definitons e.g.:
204+
* ```es_plugins``` (an array of plugin definitions e.g.:
163205

164206
```
165207
es_plugins:
@@ -183,10 +225,12 @@ By default, each node on a host will be installed to use unique pid, plugin, wor
183225
controlled by the following parameters:
184226

185227
* ```es_pid_dir``` - defaults to "/var/run/elasticsearch".
186-
* ```es_data_dir``` - defaults to "/var/lib/elasticsearch".
228+
* ```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"
187229
* ```es_log_dir``` - defaults to "/var/log/elasticsearch".
188230
* ```es_work_dir``` - defaults to "/tmp/elasticsearch".
189231
* ```es_plugin_dir``` - defaults to "/usr/share/elasticsearch/plugins".
232+
* ```es_restart_on_change``` - defaults to true. If false, changes will not result in Elasticsearch being restarted.
233+
* ```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.
190234

191235
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.
192236
* ```es_scripts_fileglob``` - defaults to `<role>/files/scripts/`.
@@ -203,3 +247,8 @@ all supported platforms.
203247
Elasticsearch restarted where required.
204248
* Systemd is used for Ubuntu versions >= 15, Debian >=8, Centos >=7. All other versions use init for service scripts.
205249

250+
## IMPORTANT NOTES RE PLUGIN MANAGEMENT
251+
252+
* 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.
253+
* If no plugins are listed in the playbook for a node, all currently installed plugins will be removed.
254+
* 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.

defaults/main.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ es_group: elasticsearch
1313
es_config: {}
1414
#Need to provide default directories
1515
es_pid_dir: "/var/run/elasticsearch"
16-
es_data_dir: "/var/lib/elasticsearch"
16+
es_data_dirs: "/var/lib/elasticsearch"
1717
es_log_dir: "/var/log/elasticsearch"
1818
es_work_dir: "/tmp/elasticsearch"
1919
es_plugin_dir: "/usr/share/elasticsearch/plugins"

filter_plugins/custom.py

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
__author__ = 'dale mcdiarmid'
2+
3+
import re
4+
5+
def modify_list(values=[], pattern='', replacement='', ignorecase=False):
6+
''' Perform a `re.sub` on every item in the list'''
7+
if ignorecase:
8+
flags = re.I
9+
else:
10+
flags = 0
11+
_re = re.compile(pattern, flags=flags)
12+
return [_re.sub(replacement, value) for value in values]
13+
14+
def append_to_list(values=[], suffix=''):
15+
if isinstance(values, basestring):
16+
values = values.split(',')
17+
return [str(value+suffix) for value in values]
18+
19+
def array_to_str(values=[],separator=','):
20+
return separator.join(values)
21+
22+
class FilterModule(object):
23+
def filters(self):
24+
return {'modify_list': modify_list,
25+
'append_to_list':append_to_list,
26+
'array_to_str':array_to_str}

tasks/elasticsearch-config.yml

+27-20
Original file line numberDiff line numberDiff line change
@@ -17,32 +17,31 @@
1717

1818
#For directories we also use the {{inventory_hostname}}-{{ es_instance_name }} - this helps if we have a shared SAN.
1919

20-
- set_fact: pid_dir={{ es_pid_dir }}/{{inventory_hostname}}-{{ es_instance_name }}
20+
- set_fact: instance_suffix={{inventory_hostname}}-{{ es_instance_name }}
2121

22-
- set_fact: data_dir={{ es_data_dir }}/{{inventory_hostname}}-{{ es_instance_name }}
22+
- set_fact: pid_dir={{ es_pid_dir }}/{{instance_suffix}}
2323

24-
- set_fact: log_dir={{ es_log_dir }}/{{inventory_hostname}}-{{ es_instance_name }}
24+
- set_fact: log_dir={{ es_log_dir }}/{{instance_suffix}}
2525

26-
- set_fact: work_dir={{ es_work_dir }}/{{inventory_hostname}}-{{ es_instance_name }}
26+
- set_fact: work_dir={{ es_work_dir }}/{{instance_suffix}}
2727

2828
#Create required directories
29-
- name: Create PID Directory
30-
file: path={{ pid_dir }} state=directory owner={{ es_user }} group={{ es_group }}
29+
- name: Create Directories
30+
file: path={{ item }} state=directory owner={{ es_user }} group={{ es_group }}
31+
with_items:
32+
- "{{pid_dir}}"
33+
- "{{work_dir}}"
34+
- "{{log_dir}}"
35+
- "{{conf_dir}}"
36+
- "{{plugin_dir}}"
3137

32-
- name: Create data dir
33-
file: state=directory path={{ data_dir }} owner={{ es_user }} group={{ es_group }}
38+
- set_fact: data_dirs={{ es_data_dirs | append_to_list('/'+instance_suffix) }}
3439

35-
- name: Create work dir
36-
file: state=directory path={{ work_dir }} owner={{ es_user }} group={{ es_group }}
40+
- name: Create Data Directories
41+
file: path={{ item }} state=directory owner={{ es_user }} group={{ es_group }}
42+
with_items:
43+
- "{{data_dirs}}"
3744

38-
- name: Create log dir
39-
file: state=directory path={{ log_dir }} owner={{ es_user }} group={{ es_group }}
40-
41-
- name: Create Config Directory
42-
file: path={{ conf_dir }} state=directory owner={{ es_user }} group={{ es_group }}
43-
44-
- name: Create Plugin Directory
45-
file: state=directory path={{ plugin_dir }} owner={{ es_user }} group={{ es_group }}
4645

4746
#Copy the config template
4847
- name: Copy Configuration File
@@ -57,13 +56,13 @@
5756
#Copy the instance specific init file
5857
- name: Copy Debian Init File for Instance
5958
template: src=init/debian/elasticsearch.j2 dest={{instance_init_script}} mode=0755 force=yes
60-
when: ansible_os_family == 'Debian'
59+
when: ansible_os_family == 'Debian' and not use_system_d
6160
notify: restart elasticsearch
6261

6362
#Copy the instance specific init file
6463
- name: Copy Redhat Init File for Instance
6564
template: src=init/redhat/elasticsearch.j2 dest={{instance_init_script}} mode=0755 force=yes
66-
when: ansible_os_family == 'RedHat'
65+
when: ansible_os_family == 'RedHat' and not use_system_d
6766
notify: restart elasticsearch
6867

6968
#Copy the systemd specific file if systemd is installed
@@ -92,3 +91,11 @@
9291

9392
- name: Delete Default Sysconfig File
9493
file: dest=/usr/lib/systemd/system/elasticsearch.service state=absent
94+
95+
- name: Delete Default Configuration File
96+
file: dest=/etc/elasticsearch/elasticsearch.yml state=absent
97+
98+
- name: Delete Default Logging File
99+
file: dest=/etc/elasticsearch/logging.yml state=absent
100+
101+
- debug: msg="Data Dirs {{data_dirs}}"

tasks/elasticsearch-plugins.yml

+18-8
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,32 @@
11
---
22

3-
#es_plugins_reinstall will be set to true if elasticsearch_install.changed i.e. we have changed ES version
3+
#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.
44
- set_fact: es_plugins_reinstall=true
5-
when: elasticsearch_install.changed
5+
when: elasticsearch_install.changed or es_plugins is not defined or es_plugins is none
66

7-
#List currently installed plugins
7+
- set_fact: list_command="list"
88

9+
- set_fact: list_command="--list"
10+
when: es_version | version_compare('2.0', '<')
911

12+
#List currently installed plugins
13+
- shell: "{{es_home}}/bin/plugin {{list_command}} | sed -n '1!p' | cut -d '-' -f2-"
14+
register: installed_plugins
15+
changed_when: False
16+
environment:
17+
CONF_DIR: "{{ conf_dir }}"
18+
ES_INCLUDE: "{{ instance_default_file }}"
1019

11-
#This needs to removed installed plugins not those listed
20+
#This needs to removes any currently installed plugins
1221
- name: Remove elasticsearch plugins
13-
command: "{{es_home}}/bin/plugin remove {{ item.plugin }} --silent"
22+
command: "{{es_home}}/bin/plugin remove {{item}} --silent"
1423
ignore_errors: yes
15-
with_items: es_plugins
16-
when: es_plugins_reinstall
24+
with_items: installed_plugins.stdout_lines
25+
when: es_plugins_reinstall and installed_plugins.stdout_lines | length > 0 and not 'No plugin detected' in installed_plugins.stdout_lines[0]
1726
notify: restart elasticsearch
1827
environment:
1928
CONF_DIR: "{{ conf_dir }}"
29+
ES_INCLUDE: "{{ instance_default_file }}"
2030

2131
- name: Install elasticsearch plugins
2232
#debug: var=item
@@ -25,7 +35,7 @@
2535
failed_when: "'Failed to install' in plugin_installed.stderr"
2636
changed_when: plugin_installed.rc == 0
2737
with_items: es_plugins
28-
when: ansible_os_family == 'RedHat' or ansible_os_family == 'Debian'
38+
when: es_plugins is defined and not es_plugins is none
2939
notify: restart elasticsearch
3040
environment:
3141
CONF_DIR: "{{ conf_dir }}"

tasks/elasticsearch-scripts.yml

+5-2
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,11 @@
77

88
- name: Create script dir
99
file: state=directory path={{ es_script_dir }} owner={{ es_user }} group={{ es_group }}
10-
when: es_config['path.scripts'] is defined
10+
11+
- name: Copy default scripts to elasticsearch
12+
copy: src=scripts dest={{ es_script_dir }} owner={{ es_user }} group={{ es_group }}
13+
when: es_scripts_fileglob is not defined
1114

1215
- name: Copy scripts to elasticsearch
1316
copy: src={{ item }} dest={{ es_script_dir }} owner={{ es_user }} group={{ es_group }}
14-
with_fileglob: es_scripts_fileglob | default("scripts")
17+
with_fileglob: es_scripts_fileglob

tasks/elasticsearch-templates.yml

+7-1
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,14 @@
11
---
22

3+
- file: path=/etc/elasticsearch/templates state=directory owner={{ es_user }} group={{ es_group }}
4+
5+
- name: Copy default templates to elasticsearch
6+
copy: src=templates dest=/etc/elasticsearch/ owner={{ es_user }} group={{ es_group }}
7+
when: es_templates_fileglob is not defined
8+
39
- name: Copy templates to elasticsearch
410
copy: src={{ item }} dest=/etc/elasticsearch/ owner={{ es_user }} group={{ es_group }}
5-
with_fileglob: es_templates_fileglob | default("templates")
11+
with_fileglob: es_templates_fileglob
612

713
- set_fact: http_port=9200
814

tasks/main.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
- include: elasticsearch-scripts.yml
1010
when: es_scripts
1111
- include: elasticsearch-plugins.yml
12-
when: es_plugins is defined
12+
when: es_plugins is defined or es_plugins_reinstall
1313
- include: elasticsearch-service.yml
1414
- include: elasticsearch-templates.yml
1515
when: es_templates

templates/elasticsearch.j2

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ ES_HOME={{es_home}}
99
CONF_DIR={{conf_dir}}
1010

1111
# Elasticsearch data directory
12-
DATA_DIR={{data_dir}}
12+
DATA_DIR={{ data_dirs | array_to_str }}
1313

1414
# Elasticsearch logs directory
1515
LOG_DIR={{log_dir}}

templates/elasticsearch.yml.j2

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ node.name: {{inventory_hostname}}-{{es_instance_name}}
1616
# Path to directory containing configuration (this file and logging.yml):
1717
path.conf: {{ conf_dir }}
1818

19-
path.data: {{ data_dir }}
19+
path.data: {{ data_dirs | array_to_str }}
2020

2121
path.work: {{ work_dir }}
2222

templates/init/debian/elasticsearch.j2

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
# Modified by Nicolas Huray for Elasticsearch <[email protected]>.
1111
#
1212
### BEGIN INIT INFO
13-
# Provides: elasticsearch
13+
# Provides: {{es_instance_name}}_{{default_file | basename}}
1414
# Required-Start: $network $remote_fs $named
1515
# Required-Stop: $network $remote_fs $named
1616
# Default-Start: 2 3 4 5

0 commit comments

Comments
 (0)