Skip to content

Commit bdeda03

Browse files
authored
Merge pull request #197 from stackhpc/fix/elasticsearch
Replace opendistro
2 parents 0aaaf67 + f172879 commit bdeda03

File tree

37 files changed

+388
-202
lines changed

37 files changed

+388
-202
lines changed

ansible/.gitignore

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ roles/*
44
# Whitelist roles that are checked into this repository.
55
!roles/filebeat/
66
!roles/filebeat/**
7-
!roles/opendistro/
8-
!roles/opendistro/**
7+
!roles/opensearch/
8+
!roles/opensearch/**
99
!roles/podman/
1010
!roles/podman/**
1111
!roles/grafana-dashboards/

ansible/monitoring.yml

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,13 @@
11
# ---
22
# # NOTE: Requires slurmdbd
33

4-
- name: Setup elasticsearch
5-
hosts: opendistro
6-
tags: opendistro
4+
- name: Setup OpenSearch
5+
hosts: opensearch
6+
tags: opensearch
77
tasks:
88
- import_role:
9-
name: opendistro
10-
tasks_from: config.yml
11-
tags: config
12-
13-
- import_role:
14-
name: opendistro
15-
tasks_from: deploy.yml
16-
tags: deploy
9+
name: opensearch
10+
become: true
1711

1812
- name: Setup slurm stats
1913
hosts: slurm_stats

ansible/roles/filebeat/defaults/main.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,4 @@
22

33
#filebeat_config_path: undefined # REQUIRED. Path to filebeat.yml configuration file template
44
filebeat_podman_user: "{{ ansible_user }}" # User that runs the filebeat container
5+
filebeat_version: 7.12.1 # latest usable with opensearch - see https://opensearch.org/docs/2.4/tools/index/#compatibility-matrix-for-beats

ansible/roles/filebeat/templates/filebeat.service.j2

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,19 @@ After=network-online.target
1212
[Service]
1313
Environment=PODMAN_SYSTEMD_UNIT=%n
1414
Restart=always
15-
ExecStart=/usr/bin/podman run --network slirp4netns:cidr={{ podman_cidr }} --sdnotify=conmon --cgroups=no-conmon --replace --name filebeat --user root --restart=always --security-opt label=disable --volume /var/log/:/logs:ro --volume /etc/filebeat/filebeat.yml:/usr/share/filebeat/filebeat.yml:ro --detach=True docker.elastic.co/beats/filebeat-oss:7.9.3 -e -strict.perms=false -d "*"
15+
ExecStart=/usr/bin/podman run \
16+
--network=host \
17+
--sdnotify=conmon \
18+
--cgroups=no-conmon \
19+
--replace \
20+
--name filebeat \
21+
--user root \
22+
--restart=always \
23+
--security-opt label=disable \
24+
--volume /var/log/:/logs:ro \
25+
--volume /etc/filebeat/filebeat.yml:/usr/share/filebeat/filebeat.yml:ro \
26+
--detach=True docker.elastic.co/beats/filebeat-oss:{{ filebeat_version }} \
27+
-e -strict.perms=false -d "*"
1628
ExecStop=/usr/bin/podman stop --ignore filebeat -t 10
1729
ExecStopPost=/usr/bin/podman rm --ignore -f filebeat
1830
KillMode=none

ansible/roles/mysql/templates/mysql.service.j2

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,17 @@ EnvironmentFile=/etc/sysconfig/mysqld
1515
ExecStartPre=+install -d -o {{ mysql_podman_user }} -g {{ mysql_podman_user }} -Z container_file_t {{ mysql_datadir }}
1616
ExecStartPre=+chown -R {{ mysql_podman_user }}:{{ mysql_podman_user }} {{ mysql_datadir }}
1717
ExecStart=/usr/bin/podman run \
18-
--network slirp4netns:cidr={{ podman_cidr }} \
19-
--sdnotify=conmon --cgroups=no-conmon \
20-
--detach --replace --name mysql --restart=no \
18+
--network=host \
19+
--sdnotify=conmon \
20+
--cgroups=no-conmon \
21+
--detach \
22+
--replace \
23+
--name mysql \
24+
--restart=no \
2125
--user mysql \
2226
--volume {{ mysql_datadir }}:/var/lib/mysql:U \
2327
--publish 3306:3306 \
24-
-e MYSQL_ROOT_PASSWORD=${MYSQL_INITIAL_ROOT_PASSWORD} \
28+
--env MYSQL_ROOT_PASSWORD=${MYSQL_INITIAL_ROOT_PASSWORD} \
2529
mysql:{{ mysql_tag }}{%- for opt in mysql_mysqld_options %} \
2630
--{{ opt }}{% endfor %}
2731

ansible/roles/opendistro/defaults/main.yml

Lines changed: 0 additions & 6 deletions
This file was deleted.

ansible/roles/opendistro/handlers/main.yml

Lines changed: 0 additions & 9 deletions
This file was deleted.

ansible/roles/opendistro/tasks/config.yml

Lines changed: 0 additions & 32 deletions
This file was deleted.

ansible/roles/opendistro/tasks/deploy.yml

Lines changed: 0 additions & 8 deletions
This file was deleted.

ansible/roles/opendistro/tasks/post.yml

Whitespace-only changes.

ansible/roles/opendistro/tasks/validate.yml

Whitespace-only changes.

ansible/roles/opendistro/templates/opendistro.service.j2

Lines changed: 0 additions & 42 deletions
This file was deleted.
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
---
2+
# Used to set passwords
3+
#opensearch_internal_users_path:
4+
5+
opensearch_podman_user: "{{ ansible_user }}"
6+
opensearch_version: '2.4.0' # https://hub.docker.com/r/opensearchproject/opensearch/tags
7+
opensearch_config_path: /usr/share/opensearch/config
8+
opensearch_data_path: /usr/share/opensearch/data
9+
opensearch_state: started # will be restarted if required
10+
opensearch_systemd_service_enabled: true
11+
opensearch_certs_duration: "{{ 365 * 10 }}" # days validity for self-signed certs
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
---
2+
3+
- name: Restart opensearch service
4+
systemd:
5+
name: opensearch.service
6+
state: "{{ 'restarted' if 'started' in opensearch_state else opensearch_state }}"
7+
enabled: "{{ opensearch_systemd_service_enabled }}"
8+
daemon_reload: "{{ 'started' in opensearch_state }}"
9+
become: true
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
- name: Ensure host certs directory exists
2+
file:
3+
path: "{{ opensearch_config_path }}/certs"
4+
state: directory
5+
owner: "{{ opensearch_podman_user }}"
6+
group: "{{ opensearch_podman_user }}"
7+
mode: ug=rwx,o=
8+
9+
# Cert generation based on https://opensearch.org/docs/latest/security-plugin/configuration/generate-certificates/
10+
11+
- name: Generate root private key
12+
community.crypto.openssl_privatekey:
13+
path: "{{ opensearch_config_path }}/certs/root-ca-key.pem"
14+
owner: "{{ opensearch_podman_user }}"
15+
group: "{{ opensearch_podman_user }}"
16+
mode: ug=rw,o=
17+
return_content: false
18+
19+
- name: Generate root CSR
20+
# Required as cert has to have a subject
21+
community.crypto.openssl_csr_pipe:
22+
privatekey_path: "{{ opensearch_config_path }}/certs/root-ca-key.pem"
23+
country_name: XX
24+
register: _opensearch_root_csr
25+
26+
- name: Generate root cert
27+
community.crypto.x509_certificate:
28+
provider: selfsigned
29+
selfsigned_not_after: "+{{ opensearch_certs_duration }}d"
30+
ignore_timestamps: false # so will be regenerated when run if necessary
31+
privatekey_path: "{{ opensearch_config_path }}/certs/root-ca-key.pem"
32+
path: "{{ opensearch_config_path }}/certs/root-ca.pem"
33+
csr_content: "{{ _opensearch_root_csr.csr }}"
34+
owner: "{{ opensearch_podman_user }}"
35+
group: "{{ opensearch_podman_user }}"
36+
mode: ug=rw,o=
37+
return_content: false
38+
39+
- name: Generate node private key in pkcs8 format
40+
community.crypto.openssl_privatekey:
41+
path: "{{ opensearch_config_path }}/certs/esnode-key.pem"
42+
format: pkcs8
43+
owner: "{{ opensearch_podman_user }}"
44+
group: "{{ opensearch_podman_user }}"
45+
mode: ug=rw,o=
46+
return_content: false
47+
48+
- name: Generate node CSR
49+
# Required as cert has to have a subject and subject_alt_name
50+
# Actual subject_alt_name is irrelevant as using enforce_hostname_verification=false
51+
community.crypto.openssl_csr_pipe:
52+
privatekey_path: "{{ opensearch_config_path }}/certs/esnode-key.pem"
53+
country_name: XX
54+
subject_alt_name:
55+
- "DNS:esnode.dns.a-record"
56+
register: _opensearch_node_csr
57+
58+
- name: Generate node cert
59+
community.crypto.x509_certificate:
60+
provider: ownca
61+
ownca_not_after: "+{{ opensearch_certs_duration }}d"
62+
ignore_timestamps: false # so will be regenerated when run if necessary
63+
ownca_path: "{{ opensearch_config_path }}/certs/root-ca.pem"
64+
ownca_privatekey_path: "{{ opensearch_config_path }}/certs/root-ca-key.pem"
65+
path: "{{ opensearch_config_path }}/certs/esnode.pem"
66+
csr_content: "{{ _opensearch_node_csr.csr }}"
67+
owner: "{{ opensearch_podman_user }}"
68+
group: "{{ opensearch_podman_user }}"
69+
mode: ug=rw,o=
70+
return_content: false
Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
---
2+
3+
- name: Check for existing opendistro service
4+
stat:
5+
path: /etc/systemd/system/opendistro.service
6+
register: _opensearch_opendistro_service
7+
8+
- name: Migrate opendistro data
9+
import_tasks:
10+
file: migrate-opendistro.yml
11+
when: _opensearch_opendistro_service.stat.exists
12+
13+
- name: Remove opendistro service
14+
file:
15+
path: /etc/systemd/system/opendistro.service
16+
state: absent
17+
18+
- name: Increase maximum number of virtual memory maps
19+
# see https://opensearch.org/docs/2.0/opensearch/install/important-settings/
20+
ansible.posix.sysctl:
21+
name: vm.max_map_count
22+
value: '262144'
23+
state: present
24+
reload: yes
25+
become: true
26+
27+
- name: Ensure required opensearch host directories exist
28+
file:
29+
state: directory
30+
path: "{{ item }}"
31+
owner: "{{ opensearch_podman_user }}"
32+
group: "{{ opensearch_podman_user }}"
33+
mode: 0770
34+
become: true
35+
loop:
36+
- "{{ opensearch_config_path }}"
37+
- "{{ opensearch_data_path }}"
38+
when: "'started' in opensearch_state" # don't run during image build
39+
40+
- name: Create certs
41+
import_tasks: certs.yml
42+
when: "'started' in opensearch_state" # don't run during image build
43+
44+
- name: Template general configuration
45+
ansible.builtin.template:
46+
src: opensearch.yml.j2
47+
dest: "{{ opensearch_config_path }}/opensearch.yml"
48+
owner: "{{ opensearch_podman_user }}"
49+
group: "{{ opensearch_podman_user }}"
50+
# NOTE: root user in container maps to user on host, so this will appear as
51+
# owned by root in the container.
52+
mode: 0660
53+
notify: Restart opensearch service
54+
become: true
55+
when: "'started' in opensearch_state" # don't run during image build
56+
57+
- name: Template internal user configuration
58+
template:
59+
src: "{{ opensearch_internal_users_path }}"
60+
dest: "{{ opensearch_config_path }}/internal_users.yml"
61+
owner: "{{ opensearch_podman_user }}"
62+
group: "{{ opensearch_podman_user }}"
63+
# NOTE: root user in container maps to user on host, so this will appear as
64+
# owned by root in the container.
65+
mode: 0660
66+
notify: Restart opensearch service
67+
become: true
68+
when: "'started' in opensearch_state" # don't run during image build
69+
70+
- name: Create systemd unit file
71+
template:
72+
dest: /etc/systemd/system/opensearch.service
73+
src: opensearch.service.j2
74+
become: true
75+
notify: Restart opensearch service
76+
77+
- name: Flush handlers
78+
meta: flush_handlers
79+
80+
- name: Ensure opensearch service state
81+
systemd:
82+
name: opensearch.service
83+
state: "{{ opensearch_state }}"
84+
enabled: "{{ opensearch_systemd_service_enabled }}"
85+
become: true
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
# Migrate data from existing containerised opendistro v1.12.0 to containerised opensearch 2.1.0.
2+
#
3+
# This relies on:
4+
# - Both opendistro and opensearch using host directories for data. See `_default_opendistro_data_path` below
5+
# - Pre-upgrade group `opendistro` and current group `opensearch` containing the same host.
6+
#
7+
# NB: If `opendistro_data_path` was set to something non-default it MUST be set again in the `opensearch` group_vars,
8+
# as the `opendistro` group will not exist in the groups.
9+
10+
# NB: This deliberately does not remove the opendistro data - this could be done manually if required.
11+
12+
- name: Stop opendistro
13+
ansible.builtin.systemd:
14+
name: opendistro.service
15+
state: stopped
16+
enabled: false
17+
18+
- name: Copy opendistro data directory
19+
ansible.builtin.copy:
20+
remote_src: true
21+
src: "{{ opendistro_data_path | default(_default_opendistro_data_path) }}"
22+
dest: "{{ opensearch_data_path | dirname }}/" # copying a directory, so need to specify the parent for destination
23+
owner: "{{ opensearch_podman_user }}"
24+
group: "{{ opensearch_podman_user }}"
25+
mode: 0770
26+
vars:
27+
# from environments/common/inventory/group_vars/all/opendistro.yml:
28+
_default_opendistro_data_path: "{{ appliances_state_dir | default('/usr/share') }}/elasticsearch/data"

0 commit comments

Comments
 (0)