Skip to content

Commit 9155b78

Browse files
committed
Replace lineinfile in favour of a template
Also adds default variables so that you can more easily override the values from your own wrapper playbook.
1 parent 0e549bc commit 9155b78

File tree

4 files changed

+130
-11
lines changed

4 files changed

+130
-11
lines changed

README.md

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,27 @@ An Ansible Role that installs Elasticsearch on RedHat/CentOS or Debian/Ubuntu.
99
None.
1010

1111
## Role Variables
12+
Available variables are listed below, along with default values (see
13+
`defaults/main.yml`):
1214

13-
None.
15+
elasticsearch_network_host: localhost
16+
17+
Network host to listen for incoming connections on. By default we only listen
18+
on the localhost interface. Change this to the IP address to listen on a
19+
specific interface, or `0.0.0.0` to listen on all interfaces.
20+
21+
elasticsearch_http_port: 9200
22+
23+
The port to listen for HTTP connections on.
24+
25+
elasticsearch_script_inline: true
26+
elasticsearch_script_indexed: true
27+
28+
Whether to allow inline scripting against ElasticSearch. You should read the
29+
following link as there are possible security implications for enabling these
30+
options: [Enable Dynamic
31+
Scripting](https://www.elastic.co/guide/en/elasticsearch/reference/current/modules-scripting.html#enable-dynamic-scripting).
32+
Available options are: `true`, `false`, `sandbox`.
1433

1534
## Dependencies
1635

@@ -29,4 +48,5 @@ MIT / BSD
2948

3049
## Author Information
3150

32-
This role was created in 2014 by [Jeff Geerling](http://jeffgeerling.com/), author of [Ansible for DevOps](http://ansiblefordevops.com/).
51+
This role was created in 2014 by [Jeff Geerling](http://jeffgeerling.com/),
52+
author of [Ansible for DevOps](http://ansiblefordevops.com/).

defaults/main.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
elasticsearch_network_host: localhost
3+
elasticsearch_http_port: 9200
4+
elasticsearch_script_inline: true
5+
elasticsearch_script_indexed: true

tasks/main.yml

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,12 @@
66
when: ansible_os_family == 'Debian'
77

88
- name: Configure Elasticsearch.
9-
lineinfile: >
10-
dest=/etc/elasticsearch/elasticsearch.yml
11-
regexp="{{ item.regexp }}"
12-
line="{{ item.line }}"
13-
state=present
14-
with_items:
15-
- { regexp: '^script\.inline', line: 'script.inline: on' }
16-
- { regexp: '^script\.indexed', line: 'script.indexed: on' }
17-
- { regexp: 'network\.host', line: 'network.host: localhost' }
9+
template:
10+
src: elasticsearch.yml.j2
11+
dest: /etc/elasticsearch/elasticsearch.yml
12+
owner: root
13+
group: elasticsearch
14+
mode: 0750
1815
notify: restart elasticsearch
1916

2017
- name: Start Elasticsearch.

templates/elasticsearch.yml.j2

Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
# {{ ansible_managed }}
2+
# ======================== Elasticsearch Configuration =========================
3+
#
4+
# NOTE: Elasticsearch comes with reasonable defaults for most settings.
5+
# Before you set out to tweak and tune the configuration, make sure you
6+
# understand what are you trying to accomplish and the consequences.
7+
#
8+
# The primary way of configuring a node is via this file. This template lists
9+
# the most important settings you may want to configure for a production cluster.
10+
#
11+
# Please see the documentation for further information on configuration options:
12+
# <http://www.elastic.co/guide/en/elasticsearch/reference/current/setup-configuration.html>
13+
#
14+
# ---------------------------------- Cluster -----------------------------------
15+
#
16+
# Use a descriptive name for your cluster:
17+
#
18+
# cluster.name: my-application
19+
#
20+
# ------------------------------------ Node ------------------------------------
21+
#
22+
# Use a descriptive name for the node:
23+
#
24+
# node.name: node-1
25+
#
26+
# Add custom attributes to the node:
27+
#
28+
# node.rack: r1
29+
#
30+
# ----------------------------------- Paths ------------------------------------
31+
#
32+
# Path to directory where to store the data (separate multiple locations by comma):
33+
#
34+
# path.data: /path/to/data
35+
#
36+
# Path to log files:
37+
#
38+
# path.logs: /path/to/logs
39+
#
40+
# ----------------------------------- Memory -----------------------------------
41+
#
42+
# Lock the memory on startup:
43+
#
44+
# bootstrap.mlockall: true
45+
#
46+
# Make sure that the `ES_HEAP_SIZE` environment variable is set to about half the memory
47+
# available on the system and that the owner of the process is allowed to use this limit.
48+
#
49+
# Elasticsearch performs poorly when the system is swapping the memory.
50+
#
51+
# ---------------------------------- Network -----------------------------------
52+
#
53+
# Set the bind address to a specific IP (IPv4 or IPv6):
54+
#
55+
network.host: {{ elasticsearch_network_host }}
56+
#
57+
# Set a custom port for HTTP:
58+
#
59+
http.port: {{ elasticsearch_http_port }}
60+
#
61+
# For more information, see the documentation at:
62+
# <http://www.elastic.co/guide/en/elasticsearch/reference/current/modules-network.html>
63+
#
64+
# --------------------------------- Discovery ----------------------------------
65+
#
66+
# Pass an initial list of hosts to perform discovery when new node is started:
67+
# The default list of hosts is ["127.0.0.1", "[::1]"]
68+
#
69+
# discovery.zen.ping.unicast.hosts: ["host1", "host2"]
70+
#
71+
# Prevent the "split brain" by configuring the majority of nodes (total number of nodes / 2 + 1):
72+
#
73+
# discovery.zen.minimum_master_nodes: 3
74+
#
75+
# For more information, see the documentation at:
76+
# <http://www.elastic.co/guide/en/elasticsearch/reference/current/modules-discovery.html>
77+
#
78+
# ---------------------------------- Gateway -----------------------------------
79+
#
80+
# Block initial recovery after a full cluster restart until N nodes are started:
81+
#
82+
# gateway.recover_after_nodes: 3
83+
#
84+
# For more information, see the documentation at:
85+
# <http://www.elastic.co/guide/en/elasticsearch/reference/current/modules-gateway.html>
86+
#
87+
# ---------------------------------- Various -----------------------------------
88+
#
89+
# Disable starting multiple nodes on a single system:
90+
#
91+
# node.max_local_storage_nodes: 1
92+
#
93+
# Require explicit names when deleting indices:
94+
#
95+
# action.destructive_requires_name: true
96+
script.inline: {{ elasticsearch_script_inline }}
97+
script.indexed: {{ elasticsearch_script_indexed }}

0 commit comments

Comments
 (0)