Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
Emilien Kenler committed Jun 11, 2015
0 parents commit a7ddd0e
Show file tree
Hide file tree
Showing 12 changed files with 441 additions and 0 deletions.
21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
The MIT License (MIT)

Copyright (c) 2014 Wizcorp

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
63 changes: 63 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
ElasticSearch Role
==================

This role will install ElasticSearch and ElasticDump on your servers.

Configuration
-------------

### Inventory

```ini
#
# Here, you put the list of your Couchbase cluster
#
[elasticsearch:children]
elasticsearch-somedc-prod

[elasticsearch-somedc-prod:children]
elasticsearch1-somedc-prod

#
# And you create one children per cluster
#
[elasticsearch1-somedc-prod]
node1.elasticsearch.somedc.prod1 ansible_ssh_host=172.16.0.80
node2.elasticsearch.somedc.prod1 ansible_ssh_host=172.16.0.81
node3.elasticsearch.somedc.prod1 ansible_ssh_host=172.16.0.82

#
# Configure the RAM size and # of replicates accordingly
#
[elasticsearch1-somedc-prod:vars]
elasticsearch_cluster_name = elasticsearch1-somedc-prod
#
# Auto-discovery is enabled by default. However,
# in some environment such as AWS, this will not
# work as intended. By setting autodiscovery
# to false, we will use unicast discovery
# instead (as in, we will add all nodes)
# to configuration instead of relying on multicasting
#
elasticsearch_autodiscovery = true

# ElasticSearch heap size (default: 256m)
# http://www.elasticsearch.org/guide/en/elasticsearch/guide/current/heap-sizing.html
elasticsearch_heap_size = 1g

# Version of ElasticDump to install
elasticdump_version = v0.12.0
```

### Execution

You will need to run this on the whole cluster every time you
add or remove nodes to it if you are running this with autodiscovery
set to false. However, you may provision only the machine you are
adding if you are using autodiscovery.

See also
--------

* [ElasticSearch](https://www.elastic.co/products/elasticsearch)
* [ElasticDump](https://github.com/taskrabbit/elasticsearch-dump)
6 changes: 6 additions & 0 deletions defaults/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
elasticsearch_tcp_port: 19350
elasticsearch_http_port: 9200
elasticsearch_autodiscovery: true
elasticsearch_heap_size: 256m

elasticdump_version: v0.12.0
6 changes: 6 additions & 0 deletions handlers/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
- name: "Restart ElasticSearch"
service: >
name=elasticsearch
state=restarted
tags:
- elasticsearch
27 changes: 27 additions & 0 deletions meta/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
galaxy_info:
author: Marc Trudel <[email protected]>
description: Installs ElasticSearch
company: Wizcorp K.K.
license: MIT
min_ansible_version: 1.8.1
platforms:
- name: EL
versions:
- 6
- 7
- name: Debian
versions:
- wheezy
categories:
- database
- database:nosql
- monitoring
dependencies:
- role: aeriscloud.nodejs
- role: aeriscloud.repos
repositories:
centos6:
- elasticsearch
centos7:
- elasticsearch
- role: aeriscloud.yum
44 changes: 44 additions & 0 deletions tasks/centos.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
- name: "Set elasticsearch version"
set_fact:
es_ver: "{{ elasticsearch_version[:3] }}"
tags:
- pkgs
- elasticsearch

- name: "Download and install the Public Signing Key"
rpm_key: >
key=https://packages.elastic.co/GPG-KEY-elasticsearch
state=present
tags:
- pkgs
- elasticsearch

- name: "Install Elasticsearch and its dependencies"
yum: >
name={{ item }}
state=present
enablerepo=elasticsearch-{{ es_ver }}
with_items:
- java-1.7.0-openjdk
- elasticsearch-{{ elasticsearch_version }}
tags:
- pkgs
- elasticsearch
notify:
- Restart ElasticSearch

- name: "Configure Elasticsearch to automatically start during bootup"
service:
name=elasticsearch
enabled=yes
tags:
- pkgs
- elasticsearch

- name: "Upload logrotate config"
template: >
src=logrotate.j2
dest=/etc/logrotate.d/elasticsearch
tags:
- files
- elasticsearch
77 changes: 77 additions & 0 deletions tasks/debian.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
- name: "Set elasticsearch version"
set_fact:
es_ver: "{{ elasticsearch_version[:3] }}"
tags:
- elasticsearch

- name: "Download and install the Public Signing Key"
apt_key: >
url=https://packages.elasticsearch.org/GPG-KEY-elasticsearch
state=present
tags:
- elasticsearch
- pkgs

- name: "Add Elasticsearch apt repository"
apt_repository: >
repo="deb http://packages.elasticsearch.org/elasticsearch/{{ es_ver }}/debian stable main"
state=present
tags:
- elasticsearch
- repos

- name: "Install Elasticsearch's dependencies"
apt: >
name={{ item }}
state=present
update_cache=yes
with_items:
- openjdk-7-jre-headless
tags:
- elasticsearch
- pkgs

- name: "Check if Java 7 as the default"
file: >
src=/usr/lib/jvm/java-1.7.0-openjdk-amd64/jre/bin/java
dest=/etc/alternatives/java
state=link
register: java_set
tags:
- elasticsearch
- files

- name: "Ensure Java 7 is the default"
shell: |
executable=/bin/bash
update-alternatives --set java /usr/lib/jvm/java-7-openjdk-amd64/jre/bin/java
when: java_set.changed
tags:
- elasticsearch

- name: "Install Elasticsearch"
apt: >
update_cache=yes
name=elasticsearch
notify:
- Restart ElasticSearch
tags:
- elasticsearch
- pkgs

- name: "Configure Elasticsearch to automatically start during bootup"
service: >
name=elasticsearch
runlevel="95 10"
enabled=yes
tags:
- elasticsearch
- service

- name: "Upload logrotate config"
template: >
src=logrotate.j2
dest=/etc/logrotate.d/elasticsearch
tags:
- elasticsearch
- files
77 changes: 77 additions & 0 deletions tasks/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
- include: centos.yml
when: ansible_distribution == 'CentOS'
tags:
- elasticsearch

- include: debian.yml
when: ansible_distribution == 'Debian'
tags:
- elasticsearch

- include: tuning.yml
tags:
- elasticsearch

- name: "Install ElasticSearch plugins"
shell: |
chdir=/usr/share/elasticsearch
creates=/usr/share/elasticsearch/plugins/{{ item.dest }}
bin/plugin -install {{ item.src }}
with_items:
- src: royrusso/elasticsearch-HQ
dest: HQ
- src: mobz/elasticsearch-head
dest: head
tags:
- elasticsearch
- plugins

- name: "Setup ElasticSearch configuration"
template: >
src=elasticsearch.yml
dest=/etc/elasticsearch/elasticsearch.yml
mode=0640
owner=root
group=elasticsearch
notify:
- Restart ElasticSearch
tags:
- elasticsearch
- configs
- files

- name: "Make sure ElasticSearch is running"
service: >
name=elasticsearch
state=started
enabled=yes
tags:
- elasticsearch
- services

- name: "Make sure the required node version is installed"
shell: |
creates={{ nvm_dir }}/{{ elasticsearch_node_version }}/bin
executable=/bin/bash
source {{ nvm_dir }}/nvm.sh && \
nvm install {{ elasticsearch_node_version }}
tags:
- elasticsearch
- nodejs

- name: "Install elasticdump"
shell: |
executable=/bin/bash
chdir=/opt
[ ! -d elasticdump ] && git clone https://github.com/taskrabbit/elasticsearch-dump.git elasticdump
cd elasticdump
git checkout {{ elasticdump_version }}
source {{ nvm_dir }}/nvm.sh
nvm use {{ elasticsearch_node_version }}
npm install .
tags:
- elasticsearch
37 changes: 37 additions & 0 deletions tasks/tuning.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
- name: "Reduce swappiness and increase max_map_count"
sysctl: >
name={{ item.name }}
value={{ item.value }}
ignoreerrors=true
state=present
with_items:
- { name: 'vm.swappiness', value: 1 }
- { name: 'vm.max_map_count', value: 262144 }
tags:
- elasticsearch
- sysctl

- name: "Lock the process address space into RAM"
lineinfile: >
line='bootstrap.mlockall: true'
dest=/etc/elasticsearch/elasticsearch.yml
tags:
- elasticsearch

- name: "Configure ES_HEAP_SIZE"
lineinfile: >
line='ES_HEAP_SIZE={{ elasticsearch_heap_size }}'
regexp='^#?ES_HEAP_SIZE='
dest=/etc/sysconfig/elasticsearch
when: ansible_distribution == 'CentOS'
tags:
- elasticsearch

- name: "Configure ES_HEAP_SIZE"
lineinfile: >
line='ES_HEAP_SIZE={{ elasticsearch_heap_size }}'
regexp='^#?ES_HEAP_SIZE='
dest=/etc/default/elasticsearch
when: ansible_distribution == 'Ubuntu' or ansible_distribution == 'Debian'
tags:
- elasticsearch
Loading

0 comments on commit a7ddd0e

Please sign in to comment.