Ansible and the Elastic Stack

6 August, 2026

Dirk Wening
Dirk Wening
Technical Writer

by | Aug 6, 2026

Last updated: August 6, 2026 · Reading time: 4–6 minutes

In this article, I’d like to introduce you to the Ansible Collection netways.elasticstack, which allows you to automatically deploy and manage Ansible and the Elastic Stack (Elasticsearch, Logstash, Kibana, Beats). Using a detailed example, I’ll show you step by step how to set up an Elasticsearch node.

The most important points in 30 seconds

  • netways.elasticstack fully supports Elasticsearch, Logstash, Kibana, and Beats, and automatically collects facts from all participating hosts so that the components can connect to each other.
  • Requirements on the control node: Ansible Core ≥ 2.18, Python ≥ 3.11, the Python module `elasticsearch` in a version lower than 9, and `passlib ` for password hashing.
  • Installation is performed in two steps: first, the “repos” role for the package source, followed by the “elasticsearch” role for the actual node.
  • You can use ` elasticstack_variant ` and ` elasticstack_release ` to specify whether to use the OSS or Enterprise version and the major version (7 or 8).

What is netways.elasticstack?

The Ansible collection netways.elasticstack is maintained by NETWAYS and covers the entire Elastic Stack. It includes dedicated roles for Elasticsearch, Kibana, Logstash, and Beats, supplemented by a role for managing the required package repositories. In addition, it includes its own modules for managing roles and users within Elasticsearch.

A key feature is that the roles are coordinated and work together. Facts about all participating hosts are collected as soon as the Elasticsearch nodes are created. So that the individual components of the stack can automatically connect to each other using hostnames or IP addresses.

Important: This only works for hosts that are actually part of the same playbook run. According to the documentation, you must ensure that all hosts to be configured are included in the playbook . A host that is not mentioned in any of the plays therefore does not provide any data (hostname/IP) for automatic mapping, even if it exists in the inventory. In addition, you should either ensure reliable DNS resolution for all the hosts involved or manually enter them into the systems’ hosts files so that the components can reach each other via their hostnames. The Collection also distinguishes between the open-source (OSS) and Enterprise versions of Elastic using the `elasticstack_variant` variable, and allows you to install a specific Elastic Stack major version (currently 7 or 8) or a specific version using `elasticstack_release` or `elasticstack_version`, respectively.

According to official documentation, the Collection has been tested on the following Linux distributions using both Elastic Stack 7 and 8. These include Rocky Linux 9, Debian 13, and Ubuntu 22.04 LTS. I tested the collection myself on Ubuntu 22.04 LTS.

Required dependencies for Ansible and the Elastic Stack

Before you begin installing and creating a playbook, I’d like to point out a few additional dependencies.

passlib is required because hashing of Logstash user passwords should not be disabled.

In addition, the Python module ` elasticsearch ` is required on the control node. According to the documentation, caution is advised here. Current versions of the module are compatible with either Elasticsearch 9 or versions prior to 9. Therefore, there is no version that supports both at the same time. For now, the Collection installs a version lower than 9; once the Collection itself is made compatible with Elastic Stack 9, the appropriate module version must be taken into account here.

Additionally, the community role ” geerlingguy.redis ” is available as an option if Redis is to be used as part of the Logstash pipeline.

According to the documentation, the following should be installed on your Ansible control node:

  • The “community.general” collection—though it probably already exists
  • Ansible Core version 2.18.0 or later
  • Python version 3.11.0 or later

You can check the versions using:

ansible --version 
python --version 

Installing the Collection

You can install the collection directly from the Git repository.

ansible-galaxy collection install git+https://github.com/netways/ansible-collection-elasticstack.git

Installing Elasticsearch on a Host

I’d like to show you an example of how to use netways.elasticstack to install a single Elasticsearch node on a host. In this example, I’m using Ubuntu 22.04 LTS as the target system.

Step 1: Create an inventory

First, create your inventory and enter your target host. In my article ” Ansible Basics,” I explain exactly how Ansible works.

vim inventory.ini
[elasticsearch]
elastic01 ansible_host=Ziel.host.IP  ansible_user=deinbenutzer

Later in our playbook, we’ll address this group again specifically.

Step 2: Set up passwordless SSH access

To allow Ansible to connect to elastic01 without being prompted for a password, set up an SSH key.

ssh-keygen -t ed25519 -C "ansible"
ssh-copy-id deinbenutzer@Ziel.IP

Step 3: The Playbook

vim elasticstack.yml

- hosts: elasticsearch
  become: true
  collections:
    - netways.elasticstack
  vars:
    elasticstack_variant: elastic
    elasticstack_release: 8 
  roles:
    - repos

- hosts: elasticsearch
  become: true
  collections:
    - netways.elasticstack
  vars:
    elasticstack_variant: elastic
    elasticstack_release: 8 
    elasticsearch_jna_workaround: true
  roles:
    - elasticsearch

What does the Playbook do?

It consists of two plays that are executed one after the other on the Elasticsearch cluster. The first Play configures the appropriate Elastic package source via the `repos` role.

Using `elasticstack_variante`, you can specify whether to install the free (OSS) or the full Elastic version (elastic). In this example, you’ll use the full version. Using `elasticstack_release`, you can also specify that Elastic Stack 8 be installed instead of the default version 7. We deliberately chose Version 8 because its security features (including TLS) are included by default and no longer need to be enabled separately.
The second play installs the actual Elasticsearch node via the `elasticsearch` role.

The repos role is not required: According to the role documentation, you simply need some form of configured Elastic Repository on the system. Whether you use the included `repos` role or another method, it makes no difference to the Elasticsearch role. However, without a configured repository, the installation will fail because Elasticsearch is installed as a package via apt .

Step 4: Run the playbook

ansible-playbook -i inventory.ini elasticstack.yml --ask-become-pass

Ansible will ask you for the sudo password (–ask-become-pass) because the installation requires root privileges.

Step 5: Verify the installation

Once the process has completed successfully, you can log in to elastic01 and check the status of Elasticsearch.

systemctl status elasticsearch
curl -k https://localhost:9200

Next Steps

If you want to set up the entire Elastic Stack beyond the individual Elasticsearch nodes, you can extend your playbook exactly according to this pattern: The collection provides separate roles for Logstash, Kibana, and Beats, which you can add as additional plays.

Be sure to follow the order of the roles specified in the documentation, as individual components build upon one another (e.g., when creating a certificate). You can find a detailed overview of all roles and their variables in the “Getting Started” guide in the collection’s repository.

Conclusion on Ansible and the Elastic Stack

netways.elasticstack is an actively maintained collection that covers the entire Elastic Stack: from initial setup through Elasticsearch, Logstash, and Kibana to log collection with Beats, including repository management and an architecture designed for seamless role integration. The example shown installs a single Elasticsearch node. The playbook can be extended in the same way for Logstash, Kibana, and Beats.

How did you like our article?