Skip to content

Commit 8393b86

Browse files
committed
Added support for optionally creating the elasticsearch user and group before installing elasticsearch.
Renamed vars, set the tasks to use the es_user and es_group vars in elasticsearch-optional-user.yml. Modifed README.md to list the es_user_id and es_group_id vars, made note that both vars are required if they are used. Removed the commented out instances of the vars in defaults/main.yml. Added es_user, es_group, es_user_id, es_group_id vars to config testing. Made conditionals use explicit 'is defined' test. Add tests for es_user_id and es_group_id. Update defaults/main.yml and test/integration/config.yml to match master plus test config additions.
1 parent e62af4a commit 8393b86

File tree

5 files changed

+35
-1
lines changed

5 files changed

+35
-1
lines changed

README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -221,6 +221,10 @@ If installing Marvel or Watcher, ensure the license plugin is also specified. S
221221

222222
* ```es_user``` - defaults to elasticsearch.
223223
* ```es_group``` - defaults to elasticsearch.
224+
* ```es_user_id``` - default is undefined.
225+
* ```es_group_id``` - default is undefined.
226+
227+
Both ```es_user_id``` and ```es_group_id``` must be set for the user and group ids to be set.
224228

225229
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 ]
226230
controlled by the following parameters:

tasks/elasticsearch-optional-user.yml

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
---
2+
#Add the elasticsearch user before installing from packages.
3+
- name: Ensure optional elasticsearch group is created with the correct id.
4+
group:
5+
state: present
6+
name: "{{ es_group }}"
7+
system: yes
8+
gid: "{{ es_group_id }}"
9+
10+
- name: Ensure optional elasticsearch user is created with the correct id.
11+
user:
12+
state: present
13+
name: "{{ es_user }}"
14+
comment: elasticsearch system user
15+
system: yes
16+
createhome: no
17+
uid: "{{ es_user_id }}"
18+
group: "{{ es_group }}"

tasks/elasticsearch.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,10 @@
88

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

11+
- name: Include optional user and group creation.
12+
when: (es_user_id is defined) and (es_group_id is defined)
13+
include: elasticsearch-optional-user.yml
14+
1115
#- name: Include specific Elasticsearch
1216
# include: "elasticsearch-{{ansible_os_family}}.yml"
1317

test/integration/config.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
hosts: localhost
55
roles:
66
#expand to all available parameters
7-
- { role: elasticsearch, es_instance_name: "node1", es_data_dirs: ["/opt/elasticsearch/data-1","/opt/elasticsearch/data-2"], 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 } }
7+
- { role: elasticsearch, es_instance_name: "node1", es_data_dirs: ["/opt/elasticsearch/data-1","/opt/elasticsearch/data-2"], es_log_dir: "/opt/elasticsearch/logs", es_work_dir: "/opt/elasticsearch/temp", es_user_id: 333, es_group_id: 333, 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 } }
88
vars:
99
es_scripts: false
1010
es_templates: false

test/integration/helpers/serverspec/config_spec.rb

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,14 @@
55
describe user('elasticsearch') do
66
it { should exist }
77
end
8+
9+
describe group('elasticsearch') do
10+
it { should have_gid 333 }
11+
end
12+
13+
describe user('elasticsearch') do
14+
it { should have_uid 333 }
15+
end
816

917
describe service('node1_elasticsearch') do
1018
it { should be_running }

0 commit comments

Comments
 (0)