Skip to content

Allow to set node types for elasticsearch #136

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 48 commits into from
Jun 1, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
48 commits
Select commit Hold shift + click to select a range
787cb8c
Allow to set node types for elasticsearch
widhalmt Mar 29, 2023
fb1fd5d
Re-enable checks from debugging
widhalmt Mar 29, 2023
d3d8324
Count by groups
widhalmt Mar 30, 2023
d6e61e5
Lint
widhalmt Mar 30, 2023
427d5e1
Lint
widhalmt Mar 30, 2023
27a3159
Typecast count
widhalmt Mar 30, 2023
9b8a44f
group_by doesn't change anything
widhalmt Mar 30, 2023
40b46f0
Run grouping on every host
widhalmt Mar 30, 2023
e396f19
Add a third node for best practices test
widhalmt Mar 30, 2023
4bb5ddb
Lint
widhalmt Mar 30, 2023
7159646
Introduce molecule check for calculations
widhalmt Mar 30, 2023
1fe1f91
No verify for calculations right now
widhalmt Mar 30, 2023
a1411b4
Overdid it with resource saving
widhalmt Mar 31, 2023
9b6cfb2
Try reducing heap and running three nodes
widhalmt Mar 31, 2023
4841aca
Merge branch 'main' into feature/masters-66
widhalmt Mar 31, 2023
0fb21e3
Make sure to only include masters as initial masters
widhalmt Mar 31, 2023
00d696a
Remove option to not start Elasticsearch
widhalmt Mar 31, 2023
c87b11f
Remove initial master nodes from config
widhalmt Mar 31, 2023
d4c7c6d
End play early when testing
widhalmt Mar 31, 2023
b67173d
Refine check for set up cluster
widhalmt Mar 31, 2023
760e986
Typo in quotes
widhalmt Apr 3, 2023
aa25b52
Fix calculation of heap for display
widhalmt Apr 6, 2023
30958fe
Merge branch 'main' into feature/masters-66
widhalmt Apr 6, 2023
3e3e004
Move task for data directory
widhalmt Apr 17, 2023
bdc1218
Merge branch 'main' into feature/masters-66
widhalmt Apr 19, 2023
3c0ff8a
Always set seed hosts
widhalmt Apr 19, 2023
7a5285f
Merge branch 'main' into feature/masters-66
widhalmt May 16, 2023
b127552
Exclude variable names from lint
widhalmt May 16, 2023
1f9b173
Add debug tasks
widhalmt May 16, 2023
e1c5cd0
Use more reliable check for bash
widhalmt May 16, 2023
02c4ded
More debugging
widhalmt May 16, 2023
f483539
More debugging
widhalmt May 16, 2023
5531576
More debug
widhalmt May 16, 2023
61541ef
More debug
widhalmt May 16, 2023
5fe3e4d
Not again...
widhalmt May 16, 2023
4b5812b
Lots more debugging
widhalmt May 16, 2023
5a8f45c
Forked up commenting in Jinja2
widhalmt May 16, 2023
099138d
Discovery type single-node
widhalmt May 17, 2023
29e86f0
Merge branch 'main' into feature/masters-66
widhalmt May 18, 2023
053a907
Merge branch 'main' into feature/masters-66
afeefghannam89 Jun 1, 2023
0f0ed3a
Remove debug tasks
afeefghannam89 Jun 1, 2023
2cd2ff2
Fix extra lines and varible name
afeefghannam89 Jun 1, 2023
c68ebc1
Remove extra pipeline import
afeefghannam89 Jun 1, 2023
af5c3a0
Fix if condition
afeefghannam89 Jun 1, 2023
4d6bfa8
Fix variable name
afeefghannam89 Jun 1, 2023
15b339f
Add needed variable
afeefghannam89 Jun 1, 2023
2279102
Fix elasticsearch config
afeefghannam89 Jun 1, 2023
5ff08b4
Add extra elasticsearch instance
afeefghannam89 Jun 1, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions .github/workflows/test_role_elasticsearch.yml
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,14 @@ jobs:
max-parallel: 1
matrix:
distro: [ubuntu2204]
scenario: [elasticsearch_default, elasticsearch_cluster-oss, elasticsearch_no-security]
release: [7, 8]
scenario:
- elasticsearch_default
- elasticsearch_roles_calculation
- elasticsearch_cluster-oss
- elasticsearch_no-security
release:
- 7
- 8

steps:
- name: Check out code
Expand Down
2 changes: 1 addition & 1 deletion docs/role-elasticsearch.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ Requirements
Role Variables
--------------

* *elasticsearch_enable*: Start and enable Elasticsearch (default: `true`)
* *elasticsearch_node_types*: List of types of this very node. Please refer to [official docs](https://www.elastic.co/guide/en/elasticsearch/reference/current/modules-node.html) for details. (default: not set. allowed value: array of types)
* *elasticsearch_heap*: Heapsize for Elasticsearch. (Half of free memory on host. Maximum 30GB. (default: Half of hosts memory. Min 1GB, Max 30GB)
* *elasticsearch_tls_key_passphrase*: Passphrase for elasticsearch certificates (default: `PleaseChangeMeIndividually`)
* *elasticsearch_cert_expiration_buffer*: Ansible will renew the elasticsearch certificate if its validity is shorter than this value, which should be number of days. (default: `30`)
Expand Down
12 changes: 11 additions & 1 deletion molecule/elasticsearch_default/molecule.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,17 @@ dependency:
driver:
name: docker
platforms:
- name: elasticsearch_default
- name: elasticsearch_default1
groups:
- elasticsearch
image: "geerlingguy/docker-${MOLECULE_DISTRO:-centos7}-ansible:latest"
command: ${MOLECULE_DOCKER_COMMAND:-""}
volumes:
- /sys/fs/cgroup:/sys/fs/cgroup:rw
cgroupns_mode: host
privileged: true
pre_build_image: true
- name: elasticsearch_default2
groups:
- elasticsearch
image: "geerlingguy/docker-${MOLECULE_DISTRO:-centos7}-ansible:latest"
Expand Down
23 changes: 23 additions & 0 deletions molecule/elasticsearch_roles_calculation/converge.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
---
# The workaround for arbitrarily named role directory is important because the git repo has one name and the role within it another
# Found at: https://github.com/ansible-community/molecule/issues/1567#issuecomment-436876722
- name: Converge
collections:
- netways.elasticstack
hosts: all
vars:
elasticsearch_jna_workaround: true
elasticsearch_disable_systemcallfilterchecks: true
elastic_release: "{{ lookup('env', 'ELASTIC_RELEASE') | int}}"
elasticsearch_node_types:
- master
- data
elasticsearch_heap: 1
elasticsearch_check_calculation: true
tasks:
- name: Include Elastics repos role
include_role:
name: repos
- name: Include Elasticsearch
include_role:
name: elasticsearch
40 changes: 40 additions & 0 deletions molecule/elasticsearch_roles_calculation/molecule.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
---
dependency:
name: galaxy
driver:
name: docker
platforms:
- name: elasticsearch-cluster1
groups:
- elasticsearch
image: "geerlingguy/docker-${MOLECULE_DISTRO:-centos7}-ansible:latest"
command: ${MOLECULE_DOCKER_COMMAND:-""}
volumes:
- /sys/fs/cgroup:/sys/fs/cgroup:rw
cgroupns_mode: host
privileged: true
pre_build_image: true
- name: elasticsearch-cluster2
groups:
- elasticsearch
image: "geerlingguy/docker-${MOLECULE_DISTRO:-centos7}-ansible:latest"
command: ${MOLECULE_DOCKER_COMMAND:-""}
volumes:
- /sys/fs/cgroup:/sys/fs/cgroup:rw
cgroupns_mode: host
privileged: true
pre_build_image: true
- name: elasticsearch-cluster3
groups:
- elasticsearch
image: "geerlingguy/docker-${MOLECULE_DISTRO:-centos7}-ansible:latest"
command: ${MOLECULE_DOCKER_COMMAND:-""}
volumes:
- /sys/fs/cgroup:/sys/fs/cgroup:rw
cgroupns_mode: host
privileged: true
pre_build_image: true
provisioner:
name: ansible
verifier:
name: ansible
36 changes: 36 additions & 0 deletions molecule/elasticsearch_roles_calculation/prepare.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
---
- name: Prepare
hosts: all
tasks:
- name: Refresh apt cache
apt:
update_cache: yes
when: ansible_os_family == "Debian"

- name: Install git
package:
name: git

- name: Install packages for RHEL
package:
name:
- iproute
- NetworkManager
when: ansible_os_family == "RedHat"

- name: Start NetworkManager
service:
name: NetworkManager
state: started
enabled: yes
when: ansible_os_family == "RedHat"

- name: Install packages for Debian
package:
name:
- gpg
- gpg-agent
- procps
- curl
- iproute2
when: ansible_os_family == "Debian"
3 changes: 3 additions & 0 deletions molecule/elasticsearch_roles_calculation/requirements.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
---
collections:
- community.general
2 changes: 1 addition & 1 deletion roles/beats/tasks/beats-security.yml
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,7 @@

- name: Fetch Beats password # noqa: risky-shell-pipe
shell: >
if test -v BASH; then set -o pipefail; fi;
if test -n "$(ps -p $$ | grep bash)"; then set -o pipefail; fi;
grep "PASSWORD elastic" {{ elasticstack_initial_passwords }} |
awk {' print $4 '}
register: beats_writer_password
Expand Down
1 change: 1 addition & 0 deletions roles/elasticsearch/defaults/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ elasticsearch_jna_workaround: false
# elasticstack_ca: First host in the `elasticsearch` group
elasticstack_ca_dir: /opt/es-ca
elasticstack_initial_passwords: /usr/share/elasticsearch/initial_passwords
elasticsearch_initialized_file: "{{ elasticstack_initial_passwords | dirname }}/cluster_initialized"
elasticstack_ca_pass: PleaseChangeMe
elasticsearch_tls_key_passphrase: PleaseChangeMeIndividually
elasticstack_ca_expiration_buffer: 30
Expand Down
50 changes: 31 additions & 19 deletions roles/elasticsearch/tasks/elasticsearch-security.yml
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,7 @@

- name: Set bootstrap password # noqa: risky-shell-pipe
shell: >
if test -v BASH; then set -o pipefail; fi;
if test -n "$(ps -p $$ | grep bash)"; then set -o pipefail; fi;
echo "{{ elasticsearch_bootstrap_pw }}" |
/usr/share/elasticsearch/bin/elasticsearch-keystore
add -x 'bootstrap.password'
Expand All @@ -248,7 +248,7 @@

- name: Get xpack.security.http.ssl.keystore.secure_password # noqa: risky-shell-pipe
shell: >
if test -v BASH; then set -o pipefail; fi;
if test -n "$(ps -p $$ | grep bash)"; then set -o pipefail; fi;
/usr/share/elasticsearch/bin/elasticsearch-keystore
show 'xpack.security.http.ssl.keystore.secure_password'
when:
Expand All @@ -261,7 +261,7 @@

- name: Set xpack.security.http.ssl.keystore.secure_password # noqa: risky-shell-pipe
shell: >
if test -v BASH; then set -o pipefail; fi;
if test -n "$(ps -p $$ | grep bash)"; then set -o pipefail; fi;
echo "{{ elasticsearch_tls_key_passphrase }}" |
/usr/share/elasticsearch/bin/elasticsearch-keystore
add -f -x 'xpack.security.http.ssl.keystore.secure_password'
Expand All @@ -276,7 +276,7 @@

- name: Remove xpack.security.http.ssl.keystore.secure_password # noqa: risky-shell-pipe
shell: >
if test -v BASH; then set -o pipefail; fi;
if test -n "$(ps -p $$ | grep bash)"; then set -o pipefail; fi;
/usr/share/elasticsearch/bin/elasticsearch-keystore
remove 'xpack.security.http.ssl.keystore.secure_password'
changed_when: false
Expand All @@ -290,7 +290,7 @@

- name: Get xpack.security.http.ssl.truststore.secure_password # noqa: risky-shell-pipe
shell: >
if test -v BASH; then set -o pipefail; fi;
if test -n "$(ps -p $$ | grep bash)"; then set -o pipefail; fi;
/usr/share/elasticsearch/bin/elasticsearch-keystore
show 'xpack.security.http.ssl.truststore.secure_password'
when:
Expand All @@ -303,7 +303,7 @@

- name: Set xpack.security.http.ssl.truststore.secure_password # noqa: risky-shell-pipe
shell: >
if test -v BASH; then set -o pipefail; fi;
if test -n "$(ps -p $$ | grep bash)"; then set -o pipefail; fi;
echo "{{ elasticsearch_tls_key_passphrase }}" |
/usr/share/elasticsearch/bin/elasticsearch-keystore
add -f -x 'xpack.security.http.ssl.truststore.secure_password'
Expand All @@ -317,7 +317,7 @@

- name: Remove xpack.security.http.ssl.truststore.secure_password # noqa: risky-shell-pipe
shell: >
if test -v BASH; then set -o pipefail; fi;
if test -n "$(ps -p $$ | grep bash)"; then set -o pipefail; fi;
/usr/share/elasticsearch/bin/elasticsearch-keystore
remove 'xpack.security.http.ssl.truststore.secure_password'
changed_when: false
Expand All @@ -330,7 +330,7 @@

- name: Get xpack.security.transport.ssl.keystore.secure_password # noqa: risky-shell-pipe
shell: >
if test -v BASH; then set -o pipefail; fi;
if test -n "$(ps -p $$ | grep bash)"; then set -o pipefail; fi;
/usr/share/elasticsearch/bin/elasticsearch-keystore
show 'xpack.security.transport.ssl.keystore.secure_password'
when:
Expand All @@ -343,7 +343,7 @@

- name: Set xpack.security.transport.ssl.keystore.secure_password # noqa: risky-shell-pipe
shell: >
if test -v BASH; then set -o pipefail; fi;
if test -n "$(ps -p $$ | grep bash)"; then set -o pipefail; fi;
echo "{{ elasticsearch_tls_key_passphrase }}" |
/usr/share/elasticsearch/bin/elasticsearch-keystore
add -f -x 'xpack.security.transport.ssl.keystore.secure_password'
Expand All @@ -357,7 +357,7 @@

- name: Remove xpack.security.transport.ssl.keystore.secure_password # noqa: risky-shell-pipe
shell: >
if test -v BASH; then set -o pipefail; fi;
if test -n "$(ps -p $$ | grep bash)"; then set -o pipefail; fi;
/usr/share/elasticsearch/bin/elasticsearch-keystore
remove 'xpack.security.transport.ssl.keystore.secure_password'
changed_when: false
Expand All @@ -370,7 +370,7 @@

- name: Get xpack.security.transport.ssl.truststore.secure_password # noqa: risky-shell-pipe
shell: >
if test -v BASH; then set -o pipefail; fi;
if test -n "$(ps -p $$ | grep bash)"; then set -o pipefail; fi;
/usr/share/elasticsearch/bin/elasticsearch-keystore
show 'xpack.security.transport.ssl.truststore.secure_password'
when:
Expand All @@ -383,7 +383,7 @@

- name: Set xpack.security.transport.ssl.truststore.secure_password # noqa: risky-shell-pipe
shell: >
if test -v BASH; then set -o pipefail; fi;
if test -n "$(ps -p $$ | grep bash)"; then set -o pipefail; fi;
echo "{{ elasticsearch_tls_key_passphrase }}" |
/usr/share/elasticsearch/bin/elasticsearch-keystore
add -f -x 'xpack.security.transport.ssl.truststore.secure_password'
Expand All @@ -397,7 +397,7 @@

- name: Remove xpack.security.transport.ssl.truststore.secure_password # noqa: risky-shell-pipe
shell: >
if test -v BASH; then set -o pipefail; fi;
if test -n "$(ps -p $$ | grep bash)"; then set -o pipefail; fi;
/usr/share/elasticsearch/bin/elasticsearch-keystore
remove 'xpack.security.transport.ssl.truststore.secure_password'
changed_when: false
Expand Down Expand Up @@ -519,7 +519,6 @@
service:
name: elasticsearch
state: started
when: elasticsearch_enable | bool
failed_when: false

- name: Wait for all instances to start
Expand Down Expand Up @@ -556,22 +555,23 @@

- name: Check for cluster status with bootstrap password # noqa: risky-shell-pipe
shell: >
if test -v BASH; then set -o pipefail; fi;
if test -n "$(ps -p $$ | grep bash)"; then set -o pipefail; fi;
curl -ks
{{ elasticsearch_http_protocol }}://elastic:{{ elasticsearch_bootstrap_pw }}@localhost:{{ elasticstack_elasticsearch_http_port }}/_cluster/health?pretty |
grep status |
cut -d\" -f4
register: elasticsearch_cluster_status_bootstrap
changed_when: false
no_log: true
ignore_errors: true
when: not elasticsearch_passwords_file.stat.exists | bool
until: elasticsearch_cluster_status_bootstrap.stdout == "green"
retries: 5
delay: 10

- name: Fetch Elastic password # noqa: risky-shell-pipe
shell: >
if test -v BASH; then set -o pipefail; fi;
if test -n "$(ps -p $$ | grep bash)"; then set -o pipefail; fi;
grep "PASSWORD elastic" {{ elasticstack_initial_passwords }} |
awk {' print $4 '}
register: elasticstack_password
Expand All @@ -582,23 +582,35 @@

- name: Check for cluster status with elastic password # noqa: risky-shell-pipe
shell: >
if test -v BASH; then set -o pipefail; fi;
if test -n "$(ps -p $$ | grep bash)"; then set -o pipefail; fi;
curl -ks
{{ elasticsearch_http_protocol }}://elastic:{{ elasticstack_password.stdout }}@localhost:{{ elasticstack_elasticsearch_http_port }}/_cluster/health?pretty |
grep status |
cut -d\" -f4
register: elasticsearch_cluster_status
changed_when: false
# no_log: true
no_log: true
ignore_errors: true
when: elasticsearch_passwords_file.stat.exists | bool
until: elasticsearch_cluster_status.stdout == "green"
retries: 20
delay: 10

- name: Leave a file showing that the cluster is set up
template:
dest: "{{ elasticsearch_initialized_file }}"
src: elasticsearch_initialized.j2
owner: root
group: root
mode: "0600"

- name: Set var that cluster is set up
set_fact:
elaticsearch_cluster_set_up: true

- name: Create initial passwords # noqa: risky-shell-pipe
shell: >
if test -v BASH; then set -o pipefail; fi;
if test -n "$(ps -p $$ | grep bash)"; then set -o pipefail; fi;
/usr/share/elasticsearch/bin/elasticsearch-setup-passwords auto -b >
{{ elasticstack_initial_passwords }}
when: inventory_hostname == elasticstack_ca
Expand Down
Loading