Ansible playbook for Elasticsearch
This project is no longer maintained.
You are welcomed to keep using it and adapting it to work for your own needs, including with Elasticsearch 8.x.
For alternative getting started experiences, you may want to try one of these options:
THIS ROLE IS FOR 7.x & 6.x, but should still work with 8.x (see note).
Ansible role for 7.x/6.x Elasticsearch - tests used to run and pass on the below platforms:
Ansible-elasticsearch 7.5.2 is removing the option to customize the maximum number of threads the process can start in #637. We discovered that this option wasn't working anymore since multi-instance support removal in ansible-elasticsearch 7.1.1. This option will be added back in a following release if it's still relevant regarding latest Elasticsearch evolutions.
Ansible-elasticsearch 7.5.2 is updating the configuration files provided by this role in #637 which contained some options deprecated in 6.x and 7.x:
/etc/default/elasticsearch|/etc/sysconfig/elasticsearch: the new template reflect the configuration file provided by Elasticsearch >= 6.x, the parameters we removed were already not used in 6.x and 7.x/etc/elasticsearch/jvm.options: the new template reflect the configuration files provided by Elasticsearch >= 6.x/etc/elasticsearch/log4j2.properties:log4j2.properties.j2 template from this Ansible role as it was a static file not bringing any customization specific to some ansible variable.log4j2.properties provided by Elasticsearch without any override.es_config_log4j2 Ansible variable (see below).Starting from Elasticsearch 7.11.0, OSS distributions will no longer be provided following the recent Elasticsearch license change.
This Ansible role will fail if oss_version is set to true and es_version is greater than
7.11.0.
See Doubling down on open, Part II blog post for more details.
You can now override the configuration files with your own versions by using the following Ansible variables:
es_config_default: "elasticsearch.j2": replace elasticsearch.j2 by your own template to use a custom /etc/default/elasticsearch|/etc/sysconfig/elasticsearch configuration filees_config_jvm: "jvm.options.j2": replace jvm.options.j2 by your own template to use a custom /etc/elasticsearch/jvm.options configuration filees_config_log4j2: "": set this variable to the path of your own template to use a custom /etc/elasticsearch/log4j2.properties configuration fileThis role uses the json_query filter which requires jmespath on the local machine.
Create your Ansible playbook with your own tasks, and include the role elasticsearch. You will have to have this repository accessible within the context of playbook.
ansible-galaxy install elastic.elasticsearch,v7.17.0Then create your playbook yaml adding the role elasticsearch. The application of the elasticsearch role results in the installation of a node on a host.
The simplest configuration therefore consists of:
- name: Simple Example
hosts: localhost
roles:
- role: elastic.elasticsearch
vars:
es_version: 7.17.0The above installs Elasticsearch 7.17.0 in a single node 'node1' on the hosts 'localhost'.
Note:
Elasticsearch default version is described in es_version. You can override this variable in your playbook to install another version.
While we are testing this role only with one 7.x and one 6.x version (respectively 7.17.0 and 6.8.23 at the time of writing), this role should work with other versions also in most cases.
This role also uses Ansible tags. Run your playbook with the --list-tasks flag for more information.
This playbook uses Kitchen for CI and local testing.
elasticsearch, not ansible-elasticsearch.xpack-upgrade suites by appending -trial to the PATTERN variable.VERSION=7.x if some suites are failing.Install the ruby dependencies with bundler
make setupIf you want to test X-Pack features with a license you will first need to export the ES_XPACK_LICENSE_FILE variable.
export ES_XPACK_LICENSE_FILE="$(pwd)/license.json"To converge an Ubuntu 16.04 host running X-Pack
$ make convergeTo run the tests
$ make verifyTo list all of the different test suits
$ make listThe default test suite is Ubuntu 16.04 with X-Pack. If you want to test another suite you can override this with the PATTERN variable
$ make converge PATTERN=security-centos-7The PATTERN is a kitchen pattern which can match multiple suites. To run all tests for CentOS
$ make converge PATTERN=centos-7The default version is 7.x. If you want to test 6.x you can override it with the VERSION variable, for example:
$ make converge VERSION=6.x PATTERN=security-centos-7When you are finished testing you can clean up everything with
$ make destroy-allAll Elasticsearch configuration parameters are supported. This is achieved using a configuration map parameter 'es_config' which is serialized into the elasticsearch.yml file. The use of a map ensures the Ansible playbook does not need to be updated to reflect new/deprecated/plugin configuration parameters.
In addition to the es_config map, several other parameters are supported for additional functions e.g. script installation. These can be found in the role's defaults/main.yml file.
The following illustrates applying configuration parameters to an Elasticsearch instance.
- name: Elasticsearch with custom configuration
hosts: localhost
roles:
- role: elastic.elasticsearch
vars:
es_data_dirs:
- "/opt/elasticsearch/data"
es_log_dir: "/opt/elasticsearch/logs"
es_config:
node.name: "node1"
cluster.name: "custom-cluster"
discovery.seed_hosts: "localhost:9301"
http.port: 9201
transport.port: 9301
node.data: false
node.master: true
bootstrap.memory_lock: true
es_heap_size: 1g
es_api_port: 9201Whilst the role installs Elasticsearch with the default configuration parameters, the following should be configured to ensure a cluster successfully forms:
es_config['http.port'] - the http port for the nodees_config['transport.port'] - the transport port for the nodees_config['discovery.seed_hosts'] - the unicast discovery list, in the comma separated format "<host>:<port>,<host>:<port>" (typically the clusters dedicated masters)es_config['cluster.initial_master_nodes'] - for 7.x and above the list of master-eligible nodes to boostrap the cluster, in the comma separated format "<node.name>:<port>,<node.name>:<port>" (typically the node names of the clusters dedicated masters)es_config['network.host'] - sets both network.bind_host and network.publish_host to the same host value. The network.bind_host setting allows to control the host different network components will bind on.The network.publish_host setting allows to control the host the node will publish itself within the cluster so other nodes will be able to connect to it.
See https://www.elastic.co/guide/en/elasticsearch/reference/current/modules-network.html for further details on default binding behavior and available options. The role makes no attempt to enforce the setting of these are requires users to specify them appropriately. It is recommended master nodes are listed and thus deployed first where possible.
A more complex example:
- name: Elasticsearch with custom configuration
hosts: localhost
roles:
- role: elastic.elasticsearch
vars:
es_data_dirs:
- "/opt/elasticsearch/data"
es_log_dir: "/opt/elasticsearch/logs"
es_config:
node.name: "node1"
cluster.name: "custom-cluster"
discovery.seed_hosts: "localhost:9301"
http.port: 9201
transport.port: 9301
node.data: false
node.master: true
bootstrap.memory_lock: true
es_heap_size: 1g
es_start_service: false
es_api_port: 9201
es_plugins:
- plugin: ingest-attachmentThe role uses es_api_host and es_api_port to communicate with the node for actions only achievable via http e.g. to install templates and to check the NODE IS ACTIVE. These default to "localhost" and 9200 respectively. If the node is deployed to bind on either a different host or port, these must be changed.
Only use es_data_dirs and es_log_dir for customizing the data and log dirs respectively. When using together with es_config['path.data'] and es_config['path.logs'] it would result in generating duplicate data- and logs-keys in elasticsearch.yml and thus let fail to start elasticsearch.
The application of the elasticsearch role results in the installation of a node on a host. Specifying the role multiple times for
No open issues yet, or sync has not completed.