Skip to content

Commit ccd9052

Browse files
zerwesKlaus Zerwes
andauthored
make elasticsearch group name configurable (#305)
For my setup I need multiple `single-node` instances, and here I get into trouble with the hard coded group name. This fixes this limitation for the `elasticsearch` role only. If it is desired, I can implemented it for all roles ... --------- Co-authored-by: Klaus Zerwes <[email protected]>
1 parent f77edd9 commit ccd9052

File tree

23 files changed

+75
-57
lines changed

23 files changed

+75
-57
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ There are some comments in the Playbook. Either fill them with the correct value
125125
126126
### Inventory
127127
128-
_Note_: The roles rely on hardcoded group names for placing services on hosts. Please make sure you have groups named `elasticsearch`, `logstash` and `kibana` in your Ansible inventory. Hosts in these groups will get the respective services. Just restricting your plays to the appropriate hosts will not work because the roles interact with hosts from other groups e.g. for certificate generation.
128+
_Note_: The roles rely on group names for placing services on hosts. Please make sure you have group names defined: `elasticstack_elasticsearch_group_name` (default: `elasticsearch`), `elasticstack_logstash_group_name` (default: `logstash`) and `elasticstack_kibana_group_name` (default: `kibana`) that will match your desired setup in your Ansible inventory. Hosts in these groups will get the respective services. Just restricting your plays to the appropriate hosts will not work because the roles interact with hosts from other groups e.g. for certificate generation.
129129
130130
The execution order of the roles is important! (see below)
131131

molecule/elasticsearch_no-security/converge.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
elasticsearch_heap: "1"
1414
elasticstack_release: 7
1515
elasticstack_no_log: false
16+
elasticstack_elasticsearch_group_name: elasticsearchXYZ
1617
tasks:
1718
- name: Include Elastics repos role
1819
ansible.builtin.include_role:

molecule/elasticsearch_no-security/molecule.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ driver:
88
platforms:
99
- name: elasticsearch-nosecurity1
1010
groups:
11-
- elasticsearch
11+
- elasticsearchXYZ
1212
image: "geerlingguy/docker-${MOLECULE_DISTRO:-debian11}-ansible:latest"
1313
command: ${MOLECULE_DOCKER_COMMAND:-""}
1414
volumes:
@@ -18,7 +18,7 @@ platforms:
1818
pre_build_image: true
1919
- name: elasticsearch-nosecurity2
2020
groups:
21-
- elasticsearch
21+
- elasticsearchXYZ
2222
image: "geerlingguy/docker-${MOLECULE_DISTRO:-debian11}-ansible:latest"
2323
command: ${MOLECULE_DOCKER_COMMAND:-""}
2424
volumes:

molecule/elasticsearch_no-security/verify.yml

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
hosts: all
66
vars:
77
elasticstack_elasticsearch_http_port: 9200
8+
elasticstack_elasticsearch_group_name: elasticsearchXYZ
89
tasks:
910

1011
# Remember, this is the no-security scenario. So no https
@@ -19,7 +20,7 @@
1920
until: result.json.status == "green"
2021
retries: 6
2122
delay: 10
22-
when: groups['elasticsearch'] | length > 1
23+
when: groups[elasticstack_elasticsearch_group_name] | length > 1
2324

2425
- name: Node check
2526
ansible.builtin.uri:
@@ -29,7 +30,7 @@
2930
status_code: 200
3031
validate_certs: false
3132
register: nodes
32-
when: groups['elasticsearch'] | length > 1
33+
when: groups[elasticstack_elasticsearch_group_name] | length > 1
3334

3435
- name: Check if all Nodes see each other
3536
ansible.builtin.assert:
@@ -38,4 +39,4 @@
3839
fail_msg: "'{{ item }}' was not found in nodes.content"
3940
success_msg: "'{{ item }}' was found in nodes.content"
4041
with_inventory_hostnames: all
41-
when: groups['elasticsearch'] | length > 1
42+
when: groups[elasticstack_elasticsearch_group_name] | length > 1

molecule/elasticstack_default/verify.yml

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
vars:
66
elasticstack_elasticsearch_http_port: 9200
77
elasticstack_initial_passwords: /usr/share/elasticsearch/initial_passwords
8+
elasticstack_elasticsearch_group_name: elasticsearch
89
tasks:
910

1011
- name: Run Logstash syntax check
@@ -22,7 +23,7 @@
2223

2324
- name: Set elasticsearch_ca variable if not already done by user
2425
ansible.builtin.set_fact:
25-
elasticsearch_ca: "{{ groups['elasticsearch'][0] }}"
26+
elasticsearch_ca: "{{ groups[elasticstack_elasticsearch_group_name][0] }}"
2627
when: elasticsearch_ca is undefined
2728

2829
- name: fetch Elastic password
@@ -42,22 +43,22 @@
4243
sort -n |
4344
tail -1
4445
register: logstash_count
45-
when: "'elasticsearch' in group_names"
46+
when: "elasticstack_elasticsearch_group_name is defined and elasticstack_elasticsearch_group_name in group_names"
4647

4748
- name: Show full output
4849
ansible.builtin.debug:
4950
var: logstash_count
50-
when: "'elasticsearch' in group_names"
51+
when: "elasticstack_elasticsearch_group_name is defined and elasticstack_elasticsearch_group_name in group_names"
5152

5253
- name: Fail when logstash index is empty
5354
ansible.builtin.fail:
5455
msg: "Logstash Index is empty"
55-
when: "'elasticsearch' in group_names and logstash_count.stdout == 0"
56+
when: "elasticstack_elasticsearch_group_name is defined and elasticstack_elasticsearch_group_name in group_names and logstash_count.stdout == 0"
5657

5758
- name: Show number of received events
5859
ansible.builtin.debug:
5960
msg: "Elasticsearch received {{ logstash_count.stdout }} events so far"
60-
when: "'elasticsearch' in group_names"
61+
when: "elasticstack_elasticsearch_group_name is defined and elasticstack_elasticsearch_group_name in group_names"
6162

6263
- name: Run Kibana checks
6364
when: "'kibana' in group_names"
@@ -112,7 +113,7 @@
112113
until: result.json.status == "green"
113114
retries: 6
114115
delay: 10
115-
when: groups['elasticsearch'] | length > 1
116+
when: groups[elasticstack_elasticsearch_group_name] | length > 1
116117

117118
- name: Elasticsearch Node check
118119
ansible.builtin.uri:
@@ -125,7 +126,7 @@
125126
status_code: 200
126127
validate_certs: false
127128
register: nodes
128-
when: groups['elasticsearch'] | length > 1
129+
when: groups[elasticstack_elasticsearch_group_name] | length > 1
129130

130131
- name: Check if all Nodes see each other
131132
ansible.builtin.assert:
@@ -134,5 +135,5 @@
134135
fail_msg: "'{{ item }}' was not found in nodes.content"
135136
success_msg: "'{{ item }}' was found in nodes.content"
136137
with_inventory_hostnames: all
137-
when: groups['elasticsearch'] | length > 1
138+
when: groups[elasticstack_elasticsearch_group_name] | length > 1
138139

molecule/logstash_full_stack-oss/verify.yml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,16 +25,16 @@
2525
sort -n |
2626
tail -1
2727
register: logstash_count
28-
when: "'elasticsearch' in group_names"
28+
when: "elasticstack_elasticsearch_group_name is defined and elasticstack_elasticsearch_group_name in group_names"
2929
- name: Show full output
3030
ansible.builtin.debug:
3131
var: logstash_count
32-
when: "'elasticsearch' in group_names"
32+
when: "elasticstack_elasticsearch_group_name is defined and elasticstack_elasticsearch_group_name in group_names"
3333
- name: Fail when logstash is empty
3434
ansible.builtin.fail:
3535
msg: "Logstash Index is empty"
36-
when: "'elasticsearch' in group_names and logstash_count.stdout == 0"
36+
when: "elasticstack_elasticsearch_group_name is defined and elasticstack_elasticsearch_group_name in group_names and logstash_count.stdout == 0"
3737
- name: Show number of received events
3838
ansible.builtin.debug:
3939
msg: "Elasticsearch received {{ logstash_count.stdout }} events so far"
40-
when: "'elasticsearch' in group_names"
40+
when: "elasticstack_elasticsearch_group_name is defined and elasticstack_elasticsearch_group_name in group_names"

roles/beats/defaults/main.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,9 @@ elasticstack_full_stack: true
6363
elasticstack_variant: elastic
6464
elasticstack_security: true
6565

66+
elasticstack_elasticsearch_group_name: elasticsearch
67+
elasticstack_logstash_group_name: logstash
68+
6669
elasticstack_ca_dir: /opt/es-ca
6770
elasticstack_ca_pass: PleaseChangeMe
6871
elasticstack_initial_passwords: /usr/share/elasticsearch/initial_passwords

roles/beats/tasks/main.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,11 @@
2727

2828
- name: Set elasticstack_ca variable if not already done by user
2929
ansible.builtin.set_fact:
30-
elasticstack_ca: "{{ groups['elasticsearch'][0] }}"
30+
elasticstack_ca: "{{ groups[elasticstack_elasticsearch_group_name][0] }}"
3131
when:
3232
- beats_security | bool
3333
- elasticstack_ca is undefined
34-
- groups['elasticsearch'] is defined
34+
- groups[elasticstack_elasticsearch_group_name] is defined
3535
tags:
3636
- certificates
3737
- renew_ca

roles/beats/templates/auditbeat.yml.j2

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ setup.kibana:
3333
output.elasticsearch:
3434
{% if elasticsearch_http_security | bool %}
3535
{% if elasticstack_full_stack | bool %}
36-
hosts: [ {% for host in groups['elasticsearch'] %}"https://{{ host }}:{{ elasticstack_elasticsearch_http_port }}"{% if not loop.last %},{% endif %}{% endfor %}]
36+
hosts: [ {% for host in groups[elasticstack_elasticsearch_group_name] %}"https://{{ host }}:{{ elasticstack_elasticsearch_http_port }}"{% if not loop.last %},{% endif %}{% endfor %}]
3737
{% else %}
3838
hosts: [ {% for host in beats_target_hosts %}"https://{{ host }}:{{ elasticstack_elasticsearch_http_port }}"{% if not loop.last %},{% endif %}{% endfor %}]
3939
{% endif %}
@@ -44,7 +44,7 @@ output.elasticsearch:
4444
ssl.certificate_authorities: ["/etc/beats/certs/ca.crt"]
4545
{% else %}
4646
{% if elasticstack_full_stack | bool %}
47-
hosts: [ {% for host in groups['elasticsearch'] %}"http://{{ host }}:{{ elasticstack_elasticsearch_http_port }}"{% if not loop.last %},{% endif %}{% endfor %}]
47+
hosts: [ {% for host in groups[elasticstack_elasticsearch_group_name] %}"http://{{ host }}:{{ elasticstack_elasticsearch_http_port }}"{% if not loop.last %},{% endif %}{% endfor %}]
4848
{% else %}
4949
hosts: [ {% for host in beats_target_hosts %}"http://{{ host }}:{{ elasticstack_elasticsearch_http_port }}"{% if not loop.last %},{% endif %}{% endfor %}]
5050
{% endif %}
@@ -53,7 +53,7 @@ output.elasticsearch:
5353
{% if beats_auditbeat_output == "logstash" %}
5454
output.logstash:
5555
{% if elasticstack_full_stack | bool %}
56-
hosts: [ {% for host in groups['logstash'] %}"{{ host }}:{{ elasticstack_beats_port }}"{% if not loop.last %},{% endif %}{% endfor %}]
56+
hosts: [ {% for host in groups[elasticstack_logstash_group_name] %}"{{ host }}:{{ elasticstack_beats_port }}"{% if not loop.last %},{% endif %}{% endfor %}]
5757
{% else %}
5858
hosts: [ {% for host in beats_target_hosts %}"{{ host }}:{{ elasticstack_beats_port }}"{% if not loop.last %},{% endif %}{% endfor %}]
5959
{% endif %}

roles/beats/templates/filebeat.yml.j2

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ setup.kibana:
108108
output.elasticsearch:
109109
{% if beats_security | bool %}
110110
{% if elasticstack_full_stack | bool %}
111-
hosts: [ {% for host in groups['elasticsearch'] %}"https://{{ host }}:{{ elasticstack_elasticsearch_http_port }}"{% if not loop.last %},{% endif %}{% endfor %}]
111+
hosts: [ {% for host in groups[elasticstack_elasticsearch_group_name] %}"https://{{ host }}:{{ elasticstack_elasticsearch_http_port }}"{% if not loop.last %},{% endif %}{% endfor %}]
112112
{% else %}
113113
hosts: [ {% for host in beats_target_hosts %}"https://{{ host }}:{{ elasticstack_elasticsearch_http_port }}"{% if not loop.last %},{% endif %}{% endfor %}]
114114
{% endif %}
@@ -119,7 +119,7 @@ output.elasticsearch:
119119
ssl.certificate_authorities: ["/etc/beats/certs/ca.crt"]
120120
{% else %}
121121
{% if elasticstack_full_stack | bool %}
122-
hosts: [ {% for host in groups['elasticsearch'] %}"http://{{ host }}:{{ elasticstack_elasticsearch_http_port }}"{% if not loop.last %},{% endif %}{% endfor %}]
122+
hosts: [ {% for host in groups[elasticstack_elasticsearch_group_name] %}"http://{{ host }}:{{ elasticstack_elasticsearch_http_port }}"{% if not loop.last %},{% endif %}{% endfor %}]
123123
{% else %}
124124
hosts: [ {% for host in beats_target_hosts %}"http://{{ host }}:{{ elasticstack_elasticsearch_http_port }}"{% if not loop.last %},{% endif %}{% endfor %}]
125125
{% endif %}
@@ -128,7 +128,7 @@ output.elasticsearch:
128128
{% if beats_filebeat_output == "logstash" %}
129129
output.logstash:
130130
{% if elasticstack_full_stack | bool %}
131-
hosts: [ {% for host in groups['logstash'] %}"{{ host }}:{{ elasticstack_beats_port }}"{% if not loop.last %},{% endif %}{% endfor %}]
131+
hosts: [ {% for host in groups[elasticstack_logstash_group_name] %}"{{ host }}:{{ elasticstack_beats_port }}"{% if not loop.last %},{% endif %}{% endfor %}]
132132
{% else %}
133133
hosts: [ {% for host in beats_target_hosts %}"{{ host }}:{{ elasticstack_beats_port }}"{% if not loop.last %},{% endif %}{% endfor %}]
134134
{% endif %}

0 commit comments

Comments
 (0)