Installing OpenSearch and OpenSearch Dashboards using Ansible
You can use an Ansible playbook to install and configure a production-ready OpenSearch cluster along with OpenSearch Dashboards.
The Ansible playbook deploys OpenSearch and OpenSearch Dashboards to Linux hosts that use systemd. For the operating systems that OpenSearch is tested on, see Compatible operating systems.
Prerequisites
The machine on which you run the playbook (the control node) must have the following installed:
-
Ansible 2.9 or later. If you install only
ansible-coreinstead of the fullansiblepackage, also install the collections that the playbook uses:ansible-galaxy collection install ansible.posix community.general -
Java 8 or later. The playbook uses Java on the control node to generate the TLS certificates for the cluster. If Java is not installed, the playbook fails with a
java: command not founderror.
The control node must have direct SSH access to the root user on each target host.
Configuration
-
Clone the OpenSearch
ansible-playbookrepository and navigate to the repository directory:git clone https://github.com/opensearch-project/ansible-playbook cd ansible-playbookThe
mainbranch installs the latest OpenSearch 3.x version. To install OpenSearch 2.x, check out the2.xbranch. -
Configure the target hosts in the
inventories/opensearch/hostsfile. The default file defines a cluster of five OpenSearch nodes and one OpenSearch Dashboards node. Each line specifies a host name and the following variables:ansible_host: The IP address that Ansible uses to connect to the target host.ansible_user: The user that Ansible uses to connect to the target host.ip: The IP address that OpenSearch and OpenSearch Dashboards bind to. Specify the private IP address of the target host or0.0.0.0.roles: The node roles of the OpenSearch node.
Each host must also be listed in the groups at the end of the file:
os-clusterfor OpenSearch nodes,masterfor cluster manager-eligible nodes, anddashboardsfor the OpenSearch Dashboards node. Hosts that are not listed in a group are not installed. Replace the IP addresses in the default file with the addresses of your hosts.To install OpenSearch and OpenSearch Dashboards on a single host, replace the contents of the file with the following, specifying the IP addresses of your host:
os1 ansible_host=<public-ip-address> ansible_user=root ip=<private-ip-address> roles=data,master [os-cluster] os1 [master] os1 [dashboards] os1For a single host, also set
cluster_typetosingle-nodein theinventories/opensearch/group_vars/all/all.ymlfile:cluster_type: single-node -
You can modify the default configuration values in the
inventories/opensearch/group_vars/all/all.ymlfile. For example, you can increase the Java memory heap size:xms_value: 8 xmx_value: 8
Install OpenSearch and OpenSearch Dashboards using the Ansible playbook
-
From the
ansible-playbookdirectory, run the Ansible playbook:ansible-playbook -i inventories/opensearch/hosts opensearch.yml --extra-vars "admin_password=Test@123 kibanaserver_password=Test@6789 logstash_password=Test@456"You can set the passwords for reserved users (
admin,kibanaserver, andlogstash) using theadmin_password,kibanaserver_password, andlogstash_passwordvariables. To change the admin password after deployment, see Changing the admin password. -
After the deployment process is complete, you can access OpenSearch and OpenSearch Dashboards with the username
adminand the password that you set for theadmin_passwordvariable.To verify that OpenSearch is running, send a request to the IP address that you specified in the
ipvariable. If you specified a private IP address, send the request from a machine in the same network:curl https://<private-ip-address>:9200 -u 'admin:Test@123' --insecureIf you specified
0.0.0.0, you can send the request tolocalhostfrom the target host or to any IP address of the target host. -
To access OpenSearch Dashboards, go to
http://<ip-address>:5601in your browser. OpenSearch Dashboards can take about 1 minute to start after the playbook finishes.
Rerunning the playbook
The playbook restarts OpenSearch on all target hosts at the same time every time it runs, so the cluster is unavailable while the nodes restart. Plan reruns, for example, to apply configuration changes, for a maintenance window.
By default, the playbook generates the TLS certificates on the control node in the /tmp/opensearch-nodecerts directory. When you rerun the playbook, it reuses the certificates and does not copy the security configuration to the target hosts again if this directory exists. If the directory doesn’t exist, for example, because the control node was restarted and /tmp was cleared, the playbook generates a new root certificate authority (CA) and new node and admin certificates and copies them to all target hosts. Clients that verify the cluster’s certificates then need the new root-ca.pem file.
To manage an existing cluster using repeated playbook runs, set iac_enable to true in the inventories/opensearch/group_vars/all/all.yml file. In this mode, the playbook updates the configuration files on every run but copies new certificates only if at least one certificate is missing on at least one host, for example, when you add a host to the cluster. In that case, it replaces the certificates on all hosts.
Rotating certificates
The generated certificates are valid for the number of days set in the cert_valid_days variable (default 730). To replace them with new certificates, delete the /tmp/opensearch-nodecerts directory on the control node, make sure that iac_enable is false, and rerun the playbook. All nodes restart using the new certificates at the same time.
Upgrading a cluster installed using the playbook
The playbook installs OpenSearch but doesn’t upgrade it. Changing os_version and rerunning the playbook isn’t a supported upgrade method for the following reasons:
- The playbook downloads the OpenSearch archive to
/tmp/opensearch.tar.gzon each target host and skips the download if that file exists. Unlessiac_enableistrue, the new version is not installed on hosts that still have the archive from the previous run. - When the new version is installed, the playbook extracts it over the existing installation in
/usr/share/opensearch, so files from the previous version that are not part of the new version remain in the installation directory. - The playbook restarts all nodes at the same time instead of one node at a time.
To upgrade a cluster installed using the playbook, upgrade the nodes one at a time by following the rolling upgrade procedure. The playbook installs OpenSearch in /usr/share/opensearch and stores the configuration, certificates, and Security plugin configuration in /usr/share/opensearch/config. Preserve these files when you install the new version on each node. After you upgrade all nodes, update os_version and os_dashboards_version in inventories/opensearch/group_vars/all/all.yml to match the installed version.