Skip to content

Commit 14cb6a1

Browse files
author
gingerwizard
committed
Merge pull request elastic#35 from gingerwizard/master
2.0 support
2 parents 3f2adac + 54dd51b commit 14cb6a1

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

42 files changed

+407
-155
lines changed

.kitchen.yml

Lines changed: 58 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -56,24 +56,77 @@ platforms:
5656
use_sudo: false
5757

5858
suites:
59-
- name: standard
59+
- name: standard-2x
6060
provisioner:
6161
playbook: test/integration/standard.yml
6262
run_list:
6363
attributes:
64-
- name: package
64+
- name: package-2x
6565
run_list:
6666
attributes:
67+
extra_vars:
68+
es_plugins:
69+
- plugin: lmenezes/elasticsearch-kopf
70+
version: master
71+
- plugin: license
72+
- plugin: marvel-agent
6773
provisioner:
6874
playbook: test/integration/package.yml
69-
- name: config
75+
- name: config-2x
7076
run_list:
7177
attributes:
7278
provisioner:
7379
playbook: test/integration/config.yml
74-
- name: multi
80+
- name: multi-2x
7581
run_list:
7682
attributes:
83+
extra_vars:
84+
es_plugins:
85+
- plugin: lmenezes/elasticsearch-kopf
86+
version: master
87+
- plugin: license
88+
- plugin: marvel-agent
7789
provisioner:
7890
playbook: test/integration/multi.yml
79-
91+
- name: standard-1x
92+
provisioner:
93+
playbook: test/integration/standard.yml
94+
run_list:
95+
attributes:
96+
extra_vars:
97+
es_major_version: 1.7
98+
es_version: 1.7.3
99+
- name: package-1x
100+
run_list:
101+
attributes:
102+
extra_vars:
103+
es_major_version: 1.7
104+
es_version: 1.7.3
105+
es_plugins:
106+
- plugin: lmenezes/elasticsearch-kopf
107+
version: master
108+
- plugin: elasticsearch/marvel
109+
version: latest
110+
provisioner:
111+
playbook: test/integration/package.yml
112+
- name: config-1x
113+
run_list:
114+
attributes:
115+
extra_vars:
116+
es_major_version: 1.7
117+
es_version: 1.7.3
118+
provisioner:
119+
playbook: test/integration/config.yml
120+
- name: multi-1x
121+
run_list:
122+
attributes:
123+
extra_vars:
124+
es_major_version: 1.7
125+
es_version: 1.7.3
126+
es_plugins:
127+
- plugin: lmenezes/elasticsearch-kopf
128+
version: master
129+
- plugin: elasticsearch/marvel
130+
version: latest
131+
provisioner:
132+
playbook: test/integration/multi.yml

README.md

Lines changed: 55 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# ansible-elasticsearch
22

3-
Ansible playbook / roles / tasks for Elasticsearch. Currently it will work on Debian and RedHat based linux systems. Tested platforms are:
3+
Ansible role for Elasticsearch. Currently this works on Debian and RedHat based linux systems. Tested platforms are:
44

55
* Ubuntu 1404
66
* Debian 7
@@ -23,7 +23,8 @@ mkdir -p roles
2323
ln -s /my/repos/ansible-elasticsearch ./roles/elasticsearch
2424
```
2525

26-
Then create your playbook yaml adding the role elasticsearch. By default, the user is only required to specify a unique es_instance_name per role application.
26+
Then create your playbook yaml adding the role elasticsearch. By default, the user is only required to specify a unique es_instance_name per role application. This should be unique per node.
27+
The application of the elasticsearch role results in the installation of a node on a host.
2728

2829
The simplest configuration therefore consists of:
2930

@@ -36,12 +37,16 @@ The simplest configuration therefore consists of:
3637
vars:
3738
```
3839

40+
The above installs a single node 'node1' on the hosts 'localhost'.
41+
42+
### Basic Elasticsearch Configuration
43+
3944
All Elasticsearch configuration parameters are supported. This is achieved using a configuration map parameter 'es_config' which is serialized into the elasticsearch.yml file.
4045
The use of a map ensures the Ansible playbook does not need to be updated to reflect new/deprecated/plugin configuration parameters.
4146

4247
In addition to the es_config map, several other parameters are supported for additional functions e.g. script installation. These can be found in the role's defaults/main.yml file.
4348

44-
The following illustrates applying configuration parameters to an Elasticsearch instance.
49+
The following illustrates applying configuration parameters to an Elasticsearch instance. By default, Elasticsearch 2.1.0 is installed.
4550

4651
```
4752
- name: Elasticsearch with custom configuration
@@ -55,17 +60,20 @@ The following illustrates applying configuration parameters to an Elasticsearch
5560
es_version_lock: false
5661
es_heap_size: 1g
5762
```
63+
`
64+
The role utilises Elasticsearch version defaults. Multicast is therefore enabled for 1.x and disabled for 2.x (plugin required in 2.x). If using 1.x it is strongly recommended you disable
65+
multicast and specify the required uni-cast settings for a production environment.
66+
When not utilizing multicast, the following should be set to ensure a successful cluster forms.
5867

68+
* ```es_config['http.port']``` - the http port for the node
69+
* ```es_config['transport.tcp.port']``` - the transport port for the node
70+
* ```es_config['discovery.zen.ping.unicast.hosts']``` - the unicast discovery list, in the comma separated format "<host>:<port>,<host>:<port>" (typically the clusters dedicated masters)
71+
* ```es_config['network.host']``` - sets both network.bind_host and network.publish_host to the same host value. The network.bind_host setting allows to control the host different network components will bind on.
5972

73+
The network.publish_host setting allows to control the host the node will publish itself within the cluster so other nodes will be able to connect to it.
6074

61-
The playbook utilises Elasticsearch version defaults. By default, therefore, multicast is enabled for 1.x. If disabled, the user user is required to specify the following additional parameters:
62-
63-
1. es_config['http.port'] - the http port for the node
64-
2. es_config['transport.tcp.port'] - the transport port for the node
65-
3. es_config['discovery.zen.ping.unicast.hosts'] - the unicast discovery list, in the comma separated format "<host>:<port>,<host>:<port>" (typically the clusters dedicated masters)
66-
67-
68-
If set to true, the ports will be auto defined and node discovery will be performed using multicast.
75+
See https://www.elastic.co/guide/en/elasticsearch/reference/current/modules-network.html for further details on default binding behaviour and available options.
76+
The role makes no attempt to enforce the setting of these are requires users to specify them appropriately. IT is recommended master nodes are listed and thus deployed first where possible.
6977

7078
A more complex example:
7179

@@ -87,32 +95,23 @@ A more complex example:
8795
es_start_service: false
8896
es_plugins_reinstall: false
8997
es_plugins:
90-
- plugin: elasticsearch/elasticsearch-cloud-aws
91-
version: 2.5.0
92-
- plugin: elasticsearch/marvel
93-
version: latest
94-
- plugin: elasticsearch/license
95-
version: latest
96-
- plugin: elasticsearch/shield
97-
version: latest
98-
- plugin: elasticsearch/elasticsearch-support-diagnostics
99-
version: latest
98+
- plugin: license
99+
- plugin: marvel-agent
100100
- plugin: lmenezes/elasticsearch-kopf
101101
version: master
102102
```
103103

104-
The application of a role results in the installation of a node on a host. Multiple roles equates to multiple nodes for a single host.
104+
### Multi Node Server Installations
105105

106-
In any multi node cluster configuration it is recommened the user list the master eligble roles first - especially if these are used a unicast hosts off which other nodes are 'booted'
106+
The application of the elasticsearch role results in the installation of a node on a host. Specifying the role multiple times for a host therefore results in the installation of multiple nodes for the host.
107107

108-
An example of a two server deployment, each with 1 node on one server and 2 nodes on another. The first server holds the master and is thus declared first.
108+
An example of a two server deployment, each with 1 node on one server and 2 nodes on another. The first server holds the master and is thus declared first. Whilst not mandatory, this is
109+
recommended in any multi node cluster configuration.
109110

110-
```
111-
---
112111

112+
```
113113
- hosts: master_nodes
114114
roles:
115-
# one master per host
116115
- { role: elasticsearch, es_instance_name: "node1", es_heap_size: "1g", es_config: { "discovery.zen.ping.multicast.enabled": false, discovery.zen.ping.unicast.hosts: "elastic02:9300", http.port: 9200, transport.tcp.port: 9300, node.data: false, node.master: true, bootstrap.mlockall: false, discovery.zen.ping.multicast.enabled: false } }
117116
vars:
118117
es_scripts: false
@@ -126,7 +125,6 @@ An example of a two server deployment, each with 1 node on one server and 2 node
126125
127126
- hosts: data_nodes
128127
roles:
129-
# two nodes per host
130128
- { 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 } }
131129
- { 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 } }
132130
vars:
@@ -146,17 +144,17 @@ Make sure your hosts are defined in your ```inventory``` file with the appropria
146144

147145
Then run it:
148146

149-
```
150-
ansible-playbook -i hosts ./your-playbook.yml
147+
```ansible-playbook -i hosts ./your-playbook.yml
151148
```
152149

153-
## Configuration
154-
You can add the role without any customisation and it will by default install Java and Elasticsearch, without any plugins.
150+
### Additional Configuration
151+
152+
Additional parameters to es_config allow the customization of the Java and Elasticsearch versions, in addition to role behaviour. Options include:
155153

156154
Following variables affect the versions installed:
157155

158-
* ```es_major_version``` (e.g. "1.5" )
159-
* ```es_version``` (e.g. "1.5.2")
156+
* ```es_major_version``` (e.g. "1.5" ). Should be consistent with es_version.
157+
* ```es_version``` (e.g. "1.5.2"). For versions > 2.x this must be "2.x".
160158
* ```es_start_service``` (true (default) or false)
161159
* ```es_plugins_reinstall``` (true or false (default) )
162160
* ```es_plugins``` (an array of plugin definitons e.g.:
@@ -166,14 +164,33 @@ Following variables affect the versions installed:
166164
- plugin: elasticsearch-cloud-aws
167165
version: 2.5.0
168166
```
169-
170-
* ```java_repos``` (an array of repositories to be added to allow java to be installed)
171-
* ```java_packages``` (an array of packages to be installed to get Java installed)
167+
Earlier examples illustrate the installation of plugins for 2.x. The correct use of this parameter varies depending on the version of Elasticsearch being installed:
168+
169+
- 2.x. - For officially supported plugins no version or source delimiter is required. The plugin script will determine the appropriate plugin version based on the target Elasticsearch version.
170+
For community based plugins include the full path e.g. "lmenezes/elasticsearch-kopf" and the appropriate version for the target version of Elasticsearch.
171+
- 1.x - Full path and version is required for both community and official plugins e.g. "elasticsearch/marvel"
172+
173+
If installing Marvel or Watcher, ensure the license plugin is also specified. Shield configuration is currently not supported but planned for later versions.
174+
175+
* ```es_user``` - defaults to elasticsearch.
176+
* ```es_group``` - defaults to elasticsearch.
177+
178+
By default, each node on a host will be installed to use unique pid, plugin, work, data and log directories. These directories are created, using the instance and host name, beneath default locations ]
179+
controlled by the following parameters:
180+
181+
* ```es_pid_dir``` - defaults to "/var/run/elasticsearch".
182+
* ```es_data_dir``` - defaults to "/var/lib/elasticsearch".
183+
* ```es_log_dir``` - defaults to "/var/log/elasticsearch".
184+
* ```es_work_dir``` - defaults to "/tmp/elasticsearch".
185+
* ```es_plugin_dir``` - defaults to "/usr/share/elasticsearch/plugins".
172186

173187
## Notes
174188

175189
* The role assumes the user/group exists on the server. The elasticsearch packages create the default elasticsearch user. If this needs to be changed, ensure the user exists.
176190
* The playbook relies on the inventory_name of each host to ensure its directories are unique
177191
* Systemd scripts are by default installed in addition to init scripts - with the exception of Debian 8. This is pending improvement and currently relies on the user to determine the preferred mechanism.
178192
* Changing an instance_name for a role application will result in the installation of a new component. The previous component will remain.
179-
* KitchenCI has been used for testing. This is used to confirm images reach the correct state after a play is first applied.
193+
* KitchenCI has been used for testing. This is used to confirm images reach the correct state after a play is first applied. We currently test only the latest version of each major release i.e. 1.7.3 and 2.1.0 on
194+
all supported platforms.
195+
* The role aims to be idempotent. Running the role multiple times, with no changes, should result in no state change on the server. If the configuration is changed, these will be applied and
196+
Elasticsearch restarted where required.

defaults/main.yml

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
---
2-
es_major_version: "1.7"
3-
es_version: "1.7.3"
2+
es_major_version: "2.x"
3+
es_version: "2.1.0"
44
es_version_lock: false
55
es_use_repository: true
66
es_start_service: true
@@ -14,4 +14,5 @@ es_config: {}
1414
es_pid_dir: "/var/run/elasticsearch"
1515
es_data_dir: "/var/lib/elasticsearch"
1616
es_log_dir: "/var/log/elasticsearch"
17-
es_work_dir: "/tmp/elasticsearch"
17+
es_work_dir: "/tmp/elasticsearch"
18+
es_plugin_dir: "/usr/share/elasticsearch/plugins"

handlers/main.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11

22
- name: restart elasticsearch
33
service: name={{instance_init_script | basename}} state=restarted enabled=yes
4-
when: es_start_service and not elasticsearch_started.changed
4+
when: es_start_service and (not elasticsearch_started.changed or plugin_installed.changed)

tasks/checkParameters.yml

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
11
# Check for mandatory parameters
22

3-
- fail: msg="es_instance_name must be specified"
4-
when: es_instance_name is not defined
3+
- fail: msg="es_instance_name must be specified and cannot be blank"
4+
when: es_instance_name is not defined or es_instance_name == ''
55

6-
- set_fact: multi_cast={{ (es_version | version_compare('2.0', '<') and es_config['discovery.zen.ping.multicast.enabled'] is not defined) or es_config['discovery.zen.ping.multicast.enabled']}}
6+
- set_fact: multi_cast={{ (es_version | version_compare('2.0', '<') and es_config['discovery.zen.ping.multicast.enabled'] is not defined) or (es_config['discovery.zen.ping.multicast.enabled'] is defined and es_config['discovery.zen.ping.multicast.enabled'])}}
77

8-
- fail: msg="Parameter 'http.port' must be defined when multicast is disabled"
8+
- debug: msg="WARNING - It is recommended you specify the parameter 'http.port' when multicast is disabled"
99
when: not multi_cast and es_config['http.port'] is not defined
1010

11-
- fail: msg="Parameter 'transport.tcp.port' must be defined when multicast is disabled"
11+
- debug: msg="WARNING - It is recommended you specify the parameter 'transport.tcp.port' when multicast is disabled"
1212
when: not multi_cast and es_config['transport.tcp.port'] is not defined
1313

14-
- fail: msg="Parameter 'discovery.zen.ping.unicast.hosts' must be defined when multicast is disabled"
14+
- debug: msg="WARNING - It is recommended you specify the parameter 'discovery.zen.ping.unicast.hosts' when multicast is disabled"
1515
when: not multi_cast and es_config['discovery.zen.ping.unicast.hosts'] is not defined
1616

1717
#If the user attempts to lock memory they must specify a heap size

tasks/elasticsearch-config.yml

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212

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

15-
- set_fact: pid_dir={{es_pid_dir}}/{{inventory_hostname}}-{{ es_instance_name }}
15+
- set_fact: pid_dir={{ es_pid_dir }}/{{inventory_hostname}}-{{ es_instance_name }}
1616

1717
- set_fact: data_dir={{ es_data_dir }}/{{inventory_hostname}}-{{ es_instance_name }}
1818

@@ -34,11 +34,14 @@
3434
file: state=directory path={{ log_dir }} owner={{ es_user }} group={{ es_group }}
3535

3636
- name: Create Config Directory
37-
file: path={{ instance_config_directory }} state=directory owner={{ es_user }} group={{ es_group }}
37+
file: path={{ conf_dir }} state=directory owner={{ es_user }} group={{ es_group }}
38+
39+
- name: Create Plugin Directory
40+
file: state=directory path={{ plugin_dir }} owner={{ es_user }} group={{ es_group }}
3841

3942
#Copy the config template
4043
- name: Copy Configuration File
41-
template: src=elasticsearch.yml.j2 dest={{instance_config_directory}}/elasticsearch.yml owner={{ es_user }} group={{ es_group }} mode=0644 force=yes
44+
template: src=elasticsearch.yml.j2 dest={{conf_dir}}/elasticsearch.yml owner={{ es_user }} group={{ es_group }} mode=0644 force=yes
4245
notify: restart elasticsearch
4346

4447
#Copy the instance specific default file
@@ -64,5 +67,7 @@
6467

6568
#Copy the logging.yml
6669
- name: Copy Logging.yml File for Instance
67-
template: src=logging.yml.j2 dest={{instance_config_directory}}/logging.yml owner={{ es_user }} group={{ es_group }} mode=0644 force=yes
68-
notify: restart elasticsearch
70+
template: src=logging.yml.j2 dest={{conf_dir}}/logging.yml owner={{ es_user }} group={{ es_group }} mode=0644 force=yes
71+
notify: restart elasticsearch
72+
73+
#Clean up un-wanted package scripts to avoid confusion

tasks/elasticsearch-plugins.yml

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,26 @@
11
---
2+
23
- name: Remove elasticsearch plugins
3-
command: /usr/share/elasticsearch/bin/plugin --remove {{ item.plugin }} --silent
4+
command: "{{es_home}}/bin/plugin remove {{ item.plugin }} --silent"
45
ignore_errors: yes
56
with_items: es_plugins
67
when: ( ansible_os_family == 'RedHat' or ansible_os_family == 'Debian' ) and es_plugins_reinstall
8+
notify: restart elasticsearch
9+
environment:
10+
CONF_DIR: "{{ conf_dir }}"
711

812
- name: Install elasticsearch plugins
913
#debug: var=item
10-
command: /usr/share/elasticsearch/bin/plugin --install {{ item.plugin }}/{{ item.version }} --silent
11-
register: command_result
12-
failed_when: "'Failed to install' in command_result.stderr"
13-
changed_when: command_result.rc == 0
14+
command: "{{es_home}}/bin/plugin install {{ item.plugin }}{% if item.version is defined and item.version != '' %}/{{ item.version }}{% endif %} --silent"
15+
register: plugin_installed
16+
failed_when: "'Failed to install' in plugin_installed.stderr"
17+
changed_when: plugin_installed.rc == 0
1418
with_items: es_plugins
15-
when: ( ansible_os_family == 'RedHat' or ansible_os_family == 'Debian' )
19+
when: ansible_os_family == 'RedHat' or ansible_os_family == 'Debian'
20+
notify: restart elasticsearch
21+
environment:
22+
CONF_DIR: "{{ conf_dir }}"
23+
24+
#Set permissions on plugins directory
25+
- name: Set Plugin Directory Permissions
26+
file: state=directory path={{ plugin_dir }} owner={{ es_user }} group={{ es_group }} recurse=yes

tasks/elasticsearch.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@
22

33
- set_fact: instance_default_file={{default_file | dirname}}/{{es_instance_name}}_{{default_file | basename}}
44
- set_fact: instance_init_script={{init_script | dirname }}/{{es_instance_name}}_{{init_script | basename}}
5-
- set_fact: instance_config_directory={{ es_conf_dir }}/{{es_instance_name}}
5+
- set_fact: conf_dir={{ es_conf_dir }}/{{es_instance_name}}
6+
- set_fact: plugin_dir={{ es_plugin_dir }}/{{es_instance_name}}
67
- set_fact: m_lock_enabled={{ es_config['bootstrap.mlockall'] is defined and es_config['bootstrap.mlockall'] == True }}
78

89
- debug: msg="Node configuration {{ es_config }} "
@@ -20,7 +21,6 @@
2021
- name: Elasticsearch configuration
2122
include: elasticsearch-config.yml
2223

23-
2424
# Make sure the service is started, and restart if necessary
2525
- name: Start elasticsearch service
2626
service: name={{instance_init_script | basename}} state=started enabled=yes

0 commit comments

Comments
 (0)