Skip to content

Add Elasticsearch to ChatOps #225

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

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
6 changes: 5 additions & 1 deletion chatops_deployment/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,8 @@
.terraform.lock.hcl
plan
terraform.tfstate
terraform.tfstate.backup
terraform.tfstate.backup
ansible/dev_ssl/*
ansible/prod_ssl/*
ansible/dev-bastion-key
ansible/prod-bastion-key
7 changes: 7 additions & 0 deletions chatops_deployment/ansible/configure.yml
Original file line number Diff line number Diff line change
Expand Up @@ -48,3 +48,10 @@
- alertmanager
tags:
- alertmanager

- name: Configure Elastic Stack
hosts: elastic
remote_user: ubuntu
force_handlers: true
roles:
- elastic
2 changes: 2 additions & 0 deletions chatops_deployment/ansible/group_vars/monitoring/vars.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,5 @@ alertmanager_username: "{{ vault_alertmanager_username }}"
alertmanager_password: "{{ vault_alertmanager_password }}"
alertmanager_version: "0.28.1"
prometheus_version: "3.2.1"
elastic_password: "{{ vault_elastic_password }}"
elasticsearch_version: "9.0.0"
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
- type: filestream
id: elasticsearch
enabled: true
paths:
- /var/log/elasticsearch/*.log
fields:
service.name: elasticsearch
fields_under_root: true
6 changes: 6 additions & 0 deletions chatops_deployment/ansible/roles/elastic/handlers/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
- name: Restart Elasticsearch
become: true
ansible.builtin.systemd_service:
name: elasticsearch.service
state: restarted
81 changes: 81 additions & 0 deletions chatops_deployment/ansible/roles/elastic/tasks/elasticsearch.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
---
- name: Install prerequisite packages
become: true
ansible.builtin.apt:
pkg:
- apt-transport-https
- software-properties-common
- wget
update_cache: true

- name: Create key directory
become: true
ansible.builtin.file:
path: /etc/apt/keyrings
state: directory
mode: "0755"

- name: Add Elasticsearch key and repository to apt
become: true
block:
- name: Add key
ansible.builtin.get_url:
url: https://artifacts.elastic.co/GPG-KEY-elasticsearch
dest: /etc/apt/keyrings/elasticsearch.asc
mode: "0755"

- name: Add repository
ansible.builtin.apt_repository:
repo: "deb [signed-by=/etc/apt/keyrings/elasticsearch.asc] https://artifacts.elastic.co/packages/9.x/apt stable main"
state: present

- name: Install Elasticsearch
become: true
ansible.builtin.apt:
name: elasticsearch
state: latest # noqa: package-latest
update_cache: true

- name: Attach data volume to Elasticsearch data directory
become: true
ansible.posix.mount:
boot: true
path: /var/elasticsearch/data
src: "{{ elasticsearch_device }}"
state: mounted
fstype: ext4

- name: Set permissions on volume
become: true
ansible.builtin.file:
path: /var/elasticsearch/data
state: directory
owner: root
group: elasticsearch
mode: "0774"
recurse: true

- name: Template elasticsearch config
become: true
ansible.builtin.template:
src: elasticsearch.yml.j2
dest: "/etc/elasticsearch/elasticsearch.yml"
owner: root
group: elasticsearch
mode: "0770"
notify:
- Restart Elasticsearch

- name: Copy certificate and key
become: true
ansible.builtin.copy:
src: "./SSL/elasticsearch.{{ item }}"
dest: "/etc/elasticsearch/certs/elasticsearch.{{ item }}"
owner: root
group: elasticsearch
mode: "0440"
notify:
- Restart Elasticsearch
loop:
- key
- crt
5 changes: 5 additions & 0 deletions chatops_deployment/ansible/roles/elastic/tasks/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
- name: Install ElasticSearch
ansible.builtin.import_tasks: elasticsearch.yml
tags:
- elasticsearch
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
path:
data: /var/elasticsearch/data
logs: /var/log/elasticsearch
cluster.name: chatops-elasticsearch
xpack.security.enabled: true
xpack.security.enrollment.enabled: true
xpack.security.http.ssl:
enabled: true
key: /etc/elasticsearch/certs/elasticsearch.key
certificate: /etc/elasticsearch/certs/elasticsearch.crt
xpack.security.transport.ssl:
enabled: false
http.host: 127.0.0.1
http.port: 9200