Elasticsearch Create Master - farukerdem34/es-ansible GitHub Wiki

🚀 Elasticsearch Master Node Setup

This Ansible playbook is responsible for initializing and configuring the Elasticsearch master node. It performs a secure password reset for the elastic user, ensures the Elasticsearch service is running, and waits for the cluster's HTTPS endpoint to be available.


📄 Playbook: create-master.yml

🎯 Target Hosts

  • elasticsearch_master

🔐 Privilege Escalation

  • become: true is required to run administrative commands and manage the elasticsearch service.

🛠️ Tasks Breakdown

🔐 1. Reset elastic User Password

This task uses the official elasticsearch-reset-password tool in non-interactive mode to securely reset the password of the built-in elastic superuser.

ansible.builtin.shell: |
  printf "{{ elastic_password }}\n{{ elastic_password }}\n" | /usr/share/elasticsearch/bin/elasticsearch-reset-password -u elastic -s -b -i
Password is defined via the elastic_password variable.

Uses -i flag for interactive (piped) input and -s -b to skip prompts and run in batch mode.

🔄 2. Ensure Elasticsearch Service is Running

Makes sure the elasticsearch systemd service is started and enabled to persist across reboots.

systemd:
  name: elasticsearch
  state: started
  enabled: true

⏱️ 3. Wait for HTTPS Endpoint (No SSL Validation)

Verifies that the Elasticsearch cluster is accepting connections over HTTPS using basic authentication and disables certificate validation.

uri:
  url: "https://{{ elastic_host }}:{{ elastic_port }}"
  method: GET
  status_code: 200
  validate_certs: false
  url_username: elastic
  url_password: "{{ elastic_password }}"

🔧 Custom Variables

Variable Default Description
elastic_password elastic Password for the elastic user
elastic_host localhost Host where Elasticsearch is accessible
elastic_port 9200 Port to connect to the Elasticsearch HTTP API