Skip to content

Commit 5c2ee70

Browse files
Klaus ZerwesKlaus Zerwes
authored andcommitted
make elasticsearch group name configurable
1 parent 870f268 commit 5c2ee70

File tree

20 files changed

+60
-48
lines changed

20 files changed

+60
-48
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ There are some comments in the Playbook. Either fill them with the correct value
120120
121121
### Inventory
122122
123-
_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.
123+
_Note_: The roles rely on hardcoded group names for placing services on hosts. Please make sure you have groups named `elasticsearch` (or define your desired group name using the var `elasticsearch_group_name`), `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.
124124
125125
The execution order of the roles is important! (see below)
126126

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+
elasticsearch_group_name: elasticsearch
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[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[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[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+
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[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: "elasticsearch_group_name is defined and 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: "elasticsearch_group_name is defined and 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: "elasticsearch_group_name is defined and 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: "elasticsearch_group_name is defined and 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[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[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[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: "elasticsearch_group_name is defined and 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: "elasticsearch_group_name is defined and 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: "elasticsearch_group_name is defined and 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: "elasticsearch_group_name is defined and elasticsearch_group_name in group_names"

roles/beats/defaults/main.yml

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

66+
elasticsearch_group_name: elasticsearch
67+
6668
elasticstack_ca_dir: /opt/es-ca
6769
elasticstack_ca_pass: PleaseChangeMe
6870
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[elasticsearch_group_name][0] }}"
3131
when:
3232
- beats_security | bool
3333
- elasticstack_ca is undefined
34-
- groups['elasticsearch'] is defined
34+
- groups[elasticsearch_group_name] is defined
3535
tags:
3636
- certificates
3737
- renew_ca

roles/beats/templates/auditbeat.yml.j2

Lines changed: 2 additions & 2 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[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[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 %}

roles/beats/templates/filebeat.yml.j2

Lines changed: 2 additions & 2 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[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[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 %}

roles/beats/templates/metricbeat.yml.j2

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ setup.kibana:
1010
output.elasticsearch:
1111
{% if elasticsearch_http_security | bool %}
1212
{% if elasticstack_full_stack | bool %}
13-
hosts: [ {% for host in groups['elasticsearch'] %}"https://{{ host }}:{{ elasticstack_elasticsearch_http_port }}"{% if not loop.last %},{% endif %}{% endfor %}]
13+
hosts: [ {% for host in groups[elasticsearch_group_name] %}"https://{{ host }}:{{ elasticstack_elasticsearch_http_port }}"{% if not loop.last %},{% endif %}{% endfor %}]
1414
{% else %}
1515
hosts: [ {% for host in beats_target_hosts %}"https://{{ host }}:{{ elasticstack_elasticsearch_http_port }}"{% if not loop.last %},{% endif %}{% endfor %}]
1616
{% endif %}
@@ -21,7 +21,7 @@ output.elasticsearch:
2121
ssl.certificate_authorities: ["/etc/beats/certs/ca.crt"]
2222
{% else %}
2323
{% if elasticstack_full_stack | bool %}
24-
hosts: [ {% for host in groups['elasticsearch'] %}"http://{{ host }}:{{ elasticstack_elasticsearch_http_port }}"{% if not loop.last %},{% endif %}{% endfor %}]
24+
hosts: [ {% for host in groups[elasticsearch_group_name] %}"http://{{ host }}:{{ elasticstack_elasticsearch_http_port }}"{% if not loop.last %},{% endif %}{% endfor %}]
2525
{% else %}
2626
hosts: [ {% for host in beats_target_hosts %}"http://{{ host }}:{{ elasticstack_elasticsearch_http_port }}"{% if not loop.last %},{% endif %}{% endfor %}]
2727
{% endif %}

roles/elasticsearch/defaults/main.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,3 +61,5 @@ elasticstack_full_stack: true
6161
elasticstack_variant: elastic
6262
elasticstack_elasticsearch_http_port: 9200
6363
elasticstack_no_log: true
64+
65+
elasticsearch_group_name: elasticsearch

0 commit comments

Comments
 (0)