Skip to content
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

Ansible initiative #60

Closed
wants to merge 12 commits into from
45 changes: 45 additions & 0 deletions ansible/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
Deploy OpenSearch with OpenSearch Dashboards using Ansible
==========================================================

## Single node OpenSearch Installation with Dashboards

This ansible playbook supports the following,

- Can be deployed on baremetal and VMs(AWS EC2)
- Supports most popular **Linux distributions**(Centos7, RHEL7)
- Install and configure the Apache2.0 opensource OpenSearch
- Configure TLS/SSL for OpenSearch transport layer(Nodes to Nodes communication) and REST API layer
- Generate self-signed certificates to configure TLS/SSL for opensearch
- Configure the Internal Users Database with limited users and user-defined passwords

Prerequisite
------------
- **Ansible**
- **Java 8**

Configure
---------

Refer the file `inventories/opensearch/group_vars/all/all.yml` to change the default values.

For example we need to increase the java memory heap size for opensearch,

xms_value: 8
xmx_value: 8


Install
-------

### Ansible

# Deploy with ansible playbook - run the playbook as root
ansible-playbook -i inventories/opensearch/hosts opensearch.yml --extra-vars "admin_password=Test@123 kibanaserver_password=Test@6789"

You should set the reserved users(`admin` and `kibanaserver`) password using `admin_password` and `kibanaserver_password` variables.

It will install and configure the opensearch. Once the deployment completed, you can access the opensearch Dashboards with user `admin` and password which you provided for variable `admin_password`.

## TBD
- opensearch multi-node cluster setup
- Performance analyzer plugin configuration
21 changes: 21 additions & 0 deletions ansible/inventories/opensearch/group_vars/all/all.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
## Common opensearch configuration parameters ##

os_cluster_name: development-cluster

# opensearch download
os_download_url: https://artifacts.opensearch.org/releases/bundle/opensearch

# opensearch version
os_version: "1.0.1"

# Configure hostnames for opensearch nodes
# It is required to configure SSL
# Example es1.example.com, es2.example.com
domain_name: example.com

os_user: opensearch

# Java memory heap values(GB) for opensearch
# You can change it based on server specs
xms_value: 2
xmx_value: 2
10 changes: 10 additions & 0 deletions ansible/inventories/opensearch/hosts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
os1 ansible_host=10.0.1.1 ansible_user=root ip=10.0.1.1 roles=data,master

dashboards1 ansible_host=10.0.1.2 ansible_user=root ip=10.0.1.2

# List all the nodes in the os cluster
[os-cluster]
os1

[dashboards]
dashboards1
13 changes: 13 additions & 0 deletions ansible/opensearch.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
---

- name: opensearch installation & configuration
hosts: os-cluster
gather_facts: false
roles:
- { role: centos7/opensearch }

- name: opensearch dashboards installation & configuration
hosts: dashboards
gather_facts: false
roles:
- { role: centos7/dashboards }
19 changes: 19 additions & 0 deletions ansible/roles/centos7/dashboards/defaults/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
---
os_nodes: |-
{% for item in groups['os-cluster'] -%}
{{ hostvars[item]['ip'] }}{% if not loop.last %}","{% endif %}
{%- endfor %}

populate_inventory_to_hosts_file: true

os_dashboards_home: /usr/share/opensearch-dashboards
os_conf_dir: /usr/share/opensearch-dashboards/config
os_plugin_bin_path: /usr/share/opensearch-dashboards/bin/opensearch-dashboards-plugin

os_api_port: 9200
os_nodes_dashboards: |-
{% for item in groups['os-cluster'] -%}
https://{{ hostvars[item]['ip'] }}:{{ os_api_port }}{% if not loop.last %}","{% endif %}
{%- endfor %}

systemctl_path: /etc/systemd/system
3 changes: 3 additions & 0 deletions ansible/roles/centos7/dashboards/handlers/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
---
- name: restart dashboards
systemd: name=dashboards state=restarted enabled=yes
40 changes: 40 additions & 0 deletions ansible/roles/centos7/dashboards/tasks/dashboards.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
---

- name: Dashboards Install | Download opensearch dashbaord {{ os_version }}
get_url:
url: "{{ os_download_url }}-dashboards/{{ os_version }}/opensearch-dashboards-{{ os_version }}-linux-x64.tar.gz"
dest: "/tmp/opensearch-dashboards.tar.gz"
register: download

- name: Dashboards Install | Create opensearch user
user:
name: "{{ os_user }}"
state: present
shell: /bin/bash
when: download.changed

- name: Dashboards Install | Create home directory
file:
path: "{{ os_dashboards_home }}"
state: directory
owner: "{{ os_user }}"
group: "{{ os_user }}"
when: download.changed

- name: Dashboards Install | Extract the tar file
command: chdir=/tmp/ tar -xvzf opensearch-dashboards.tar.gz -C "{{ os_dashboards_home }}" --strip-components=1
when: download.changed

- name: Dashboards Install | Copy Configuration File
template:
src: opensearch_dashboards.yml
dest: "{{os_conf_dir}}/opensearch_dashboards.yml"
owner: "{{ os_user }}"
group: "{{ os_user }}"
mode: 0644
backup: yes

- name: Dashboards Install | create systemd service
template:
src: dashboards.service
dest: "{{ systemctl_path }}/dashboards.service"
13 changes: 13 additions & 0 deletions ansible/roles/centos7/dashboards/tasks/etchosts.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
---
- name: Hosts | populate inventory into hosts file
blockinfile:
dest: /etc/hosts
block: |-
{% for item in groups['os-cluster'] %}
{{ hostvars[item]['ip'] }} {{ item }}.{{ domain_name }} {{ item }}
{% endfor %}
state: present
create: yes
backup: yes
marker: "# Ansible inventory hosts {mark}"
when: populate_inventory_to_hosts_file
28 changes: 28 additions & 0 deletions ansible/roles/centos7/dashboards/tasks/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
---

- hostname:
name: "{{ inventory_hostname }}"

- name: Disable the selinux
selinux:
state: disabled

- name: Populate the nodes to /etc/hosts
import_tasks: etchosts.yml

- name: include dashboards installation
include: dashboards.yml

- name: Make sure opensearch dashboards is started
service:
name: dashboards
state: started
enabled: yes

- name: Get all the installed dashboards plugins
command: "sudo -u {{ os_user }} {{ os_plugin_bin_path }} list"
register: list_plugins

- name: Show all the installed dashboards plugins
debug:
msg: "{{ list_plugins.stdout }}"
48 changes: 48 additions & 0 deletions ansible/roles/centos7/dashboards/templates/dashboards.service
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
[Unit]
Description=opensearch-dashboards
Wants=network-online.target
After=network-online.target

[Service]
RuntimeDirectory=opensearch-dashboards
PrivateTmp=true

WorkingDirectory={{ os_dashboards_home }}

User=opensearch
Group=opensearch

ExecStart={{ os_dashboards_home }}/bin/opensearch-dashboards -q

StandardOutput=journal
StandardError=inherit

# Specifies the maximum file descriptor number that can be opened by this process
LimitNOFILE=65535

# Specifies the maximum number of processes
LimitNPROC=4096

# Specifies the maximum size of virtual memory
LimitAS=infinity

# Specifies the maximum file size
LimitFSIZE=infinity

# Disable timeout logic and wait until process is stopped
TimeoutStopSec=0

# SIGTERM signal is used to stop the Java process
KillSignal=SIGTERM

# Send the signal only to the JVM rather than its control group
KillMode=process

# Java process is never killed
SendSIGKILL=no

# When a JVM receives a SIGTERM signal it exits with code 143
SuccessExitStatus=143

[Install]
WantedBy=multi-user.target
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
server.port: 5601
server.host: "{{ hostvars[inventory_hostname]['ip'] }}"
opensearch.hosts: ["{{ os_nodes_dashboards }}"]
opensearch.ssl.verificationMode: none
opensearch.username: "kibanaserver"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we use a different name here , maybe dashboardserver?

Copy link
Contributor Author

@saravanan30erd saravanan30erd Sep 11, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@TheAlgo kibanaserver is the name used in default configuration file from Opensearch dashboards source file(Tar file). Refer: https://opensearch.org/docs/dashboards/install/tls/

I suggest we should follow the default configuration from installation source to avoid confusions. May be it should be changed first in source files and official documentations then we can change it.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@peterzhuamazon Just curious , why are we using kibanaserver till now?

Copy link
Contributor Author

@saravanan30erd saravanan30erd Sep 11, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@TheAlgo @peterzhuamazon kibanaserver is used in security plugin where it should be changed and then configuration. I raised the below PRs to fix this. Once this merged and released, then we can update here.

opensearch-project/security#1443
opensearch-project/opensearch-build#458

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We are still in discussion with Security Team on this @saravanan30erd please hold on for some time before we make a decision on this.

Thanks.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@peterzhuamazon Sure, I think we can continue with kibanaserver here as of now.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We will keep this for now @TheAlgo.
@saravanan30erd please create an issue to track this.
Thanks.

opensearch.password: "{{ kibanaserver_password }}"
opensearch.requestHeadersWhitelist: [ authorization,securitytenant ]

opensearch_security.multitenancy.enabled: true
opensearch_security.multitenancy.tenants.preferred: ["Private", "Global"]
opensearch_security.readonly_mode.roles: ["kibana_read_only"]
# Use this setting if you are running dashboards without https
opensearch_security.cookie.secure: false
3 changes: 3 additions & 0 deletions ansible/roles/centos7/dashboards/vars/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
---
# vars file for opensearch
java: "{{ es_java | default('java-1.8.0-openjdk.x86_64') }}"
22 changes: 22 additions & 0 deletions ansible/roles/centos7/opensearch/defaults/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
---

os_nodes: |-
{% for item in groups['os-cluster'] -%}
{{ item }}{% if not loop.last %}","{% endif %}
{%- endfor %}

os_master_nodes: |-
{% for item in groups['master'] -%}
{{ item }}{% if not loop.last %}","{% endif %}
{%- endfor %}

populate_inventory_to_hosts_file: true

os_home: /usr/share/opensearch
os_conf_dir: /usr/share/opensearch/config
os_plugin_bin_path: /usr/share/opensearch/bin/opensearch-plugin
os_sec_plugin_conf_path: /usr/share/opensearch/plugins/opensearch-security/securityconfig
os_sec_plugin_tools_path: /usr/share/opensearch/plugins/opensearch-security/tools
os_api_port: 9200

systemctl_path: /etc/systemd/system
10 changes: 10 additions & 0 deletions ansible/roles/centos7/opensearch/handlers/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
---
# handlers file for opensearch
- name: reload systemd configuration
become: yes
command: systemctl daemon-reload

# Restart service and ensure it is enabled

- name: restart opensearch
systemd: name=opensearch state=restarted enabled=yes
13 changes: 13 additions & 0 deletions ansible/roles/centos7/opensearch/tasks/etchosts.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
---
- name: Hosts | populate inventory into hosts file
blockinfile:
dest: /etc/hosts
block: |-
{% for item in groups['os-cluster'] %}
{{ hostvars[item]['ip'] }} {{ item }}.{{ domain_name }} {{ item }}
{% endfor %}
state: present
create: yes
backup: yes
marker: "# Ansible inventory hosts {mark}"
when: populate_inventory_to_hosts_file
42 changes: 42 additions & 0 deletions ansible/roles/centos7/opensearch/tasks/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
---

- hostname:
name: "{{ inventory_hostname }}"

- name: Disable the selinux
selinux:
state: disabled

- name: Populate the nodes to /etc/hosts
import_tasks: etchosts.yml

- name: include opensearch installation
include: opensearch.yml

- name: include security plugin for opensearch
include: security.yml

- name: Make sure opensearch is started
service:
name: opensearch
state: started
enabled: yes

- name: Get all the installed ES plugins
command: "{{ os_plugin_bin_path }} list"
register: list_plugins

- name: Show all the installed ES plugins
debug:
msg: "{{ list_plugins.stdout }}"

- name: Wait for opensearch to startup
wait_for: host={{ hostvars[inventory_hostname]['ip'] }} port={{os_api_port}} delay=5 connect_timeout=1

- name: Check the opensearch status
command: curl https://{{ inventory_hostname }}:9200/_cluster/health?pretty -u 'admin:{{ admin_password }}' -k
register: os_status

- name: Show the opensearch status
debug:
msg: "{{ os_status.stdout }}"
Loading