Elasticsearch 8.x installation and configuration problem and elasticsearch service not able to start

Hello guys,

I have trouble installing and configuring my elasticsearch 8.x on Ubuntu 20.04 with ansible role.
I am getting an error of Could not create auto-configuration directory with main ERROR Unable to create file /usr/share/elasticsearch/logs/elasticsearch_server.json java.io.IOException.

my ansible playbook:

  apt:
    update_cache: yes
    force_apt_get: yes
    cache_valid_time: 3600

- name: Upgrade all packages on servers
  apt:
    upgrade: dist
    force_apt_get: yes

# Installing necessary packages

- name: Add required dependencies.
  apt:
    name:
      - apt-transport-https
      - gnupg2
      - wget
    state: present
- name: Import the Elasticsearch PGP Key
  shell: |
    wget -qO - https://artifacts.elastic.co/GPG-KEY-elasticsearch | sudo apt-key add -
  args:
    warn: no
- name: Add repository defiition
  copy:
    dest: /etc/apt/sources.list.d/elastic-{{ elasticsearch_version }}.list
    content: |
      deb https://artifacts.elastic.co/packages/{{ elasticsearch_version }}/apt stable main

- name: Update apt repo and cache on Ubuntu vm
  apt:
    update_cache: yes
    force_apt_get: yes
    cache_valid_time: 3600

- name: Install Elasticsearch
  apt:
   name: elasticsearch
   state: present
   update_cache: yes

   
# configure elasticsearch port and host details

- name: configure elasticsearch.yml file
  template:
    src: "{{ item | basename }}.j2"
    dest: "{{ item }}"
    # src: elasticsearch.yml.j2
    # dest: /etc/elasticsearch/elasticsearch.yml
    owner: elasticsearch
    group: elasticsearch
    mode: '0660'
  with_items:
    - /etc/elasticsearch/elasticsearch.yml
    - /etc/elasticsearch/jvm.options
  notify: restart elasticsearch



- name: reload systemd configuration
  systemd:
    daemon_reload: true
 
# Start Elasticsearch

- name: Start Elasticsearch service
  service: 
    name: elasticsearch
    state: started
    enabled: yes

# make sure elasticsearch is running

- name: Make sure Elasticsearch is running before proceeding.
  wait_for:
    host: "{{ elasticsearch_network_host }}"
    port: "{{ elasticsearch_http_port }}"
    delay: 3
    timeout: 300

configuration file

# ======================== Elasticsearch Configuration =========================
#
# NOTE: Elasticsearch comes with reasonable defaults for most settings.
#       Before you set out to tweak and tune the configuration, make sure you
#       understand what are you trying to accomplish and the consequences.
#
# The primary way of configuring a node is via this file. This template lists
# the most important settings you may want to configure for a production cluster.
#
# Please consult the documentation for further information on configuration options:
# https://www.elastic.co/guide/en/elasticsearch/reference/index.html
#
# ---------------------------------- Cluster -----------------------------------
#
# Use a descriptive name for your cluster:
#
#cluster.name: my-application
#
# ------------------------------------ Node ------------------------------------
#
# Use a descriptive name for the node:
#
#node.name: node-1
#
# Add custom attributes to the node:
#
#node.attr.rack: r1
#
# ----------------------------------- Paths ------------------------------------
#
# Path to directory where to store the data (separate multiple locations by comma):
#
#path.data: /path/to/data
#
# Path to log files:
#
path.logs: {{ path_to_logs }}
# ----------------------------------- Memory -----------------------------------
#
# Lock the memory on startup:
#
#bootstrap.memory_lock: true
#
# Make sure that the heap size is set to about half the memory available
# on the system and that the owner of the process is allowed to use this
# limit.
#
# Elasticsearch performs poorly when the system is swapping the memory.
#
# ---------------------------------- Network -----------------------------------
#
# By default Elasticsearch is only accessible on localhost. Set a different
# address here to expose this node on the network:
#
network.host: {{ elasticsearch_network_host }}
#
# By default Elasticsearch listens for HTTP traffic on the first free port it
# finds starting at 9200. Set a specific HTTP port here:
#
http.port: {{ elasticsearch_http_port }}
#
# For more information, consult the network module documentation.
#
# --------------------------------- Discovery ----------------------------------
#
# Pass an initial list of hosts to perform discovery when this node is started:
# The default list of hosts is ["127.0.0.1", "[::1]"]
#
discovery.seed_hosts: []
#
# Bootstrap the cluster using an initial set of master-eligible nodes:
#
#cluster.initial_master_nodes: ["node-1", "node-2"]
#cluster.initial_master_nodes: ["node-1"]
# For more information, consult the discovery and cluster formation module documentation.
#
# --------------------------------- Readiness ----------------------------------
#
# Enable an unauthenticated TCP readiness endpoint on localhost
#
#readiness.port: 9399
#
# ---------------------------------- Various -----------------------------------
#
# Allow wildcard deletion of indices:
#
#action.destructive_requires_name: false

defaults/main.yml

---
# defaults file for elasticsearch
elasticsearch_version: '8.x'
elasticsearch_network_host: localhost
elasticsearch_http_port: 9200

path_to_logs: /usr/share/elasticsearch/logs

elasticsearch_heap_size_min: 1024m
elasticsearch_heap_size_max: 1024m

You need to share your error log as plain text, not as an screenshot, it is not possible to read the entire error.

Copy the error log and share it using the </> button to format correctly.

But from what was possible to see it seems to be a permission error to create the directory /usr/share/elasticsearch/logs.

Normally you would save the logs int o /var/log/elasticsearch and the elasticsearch user would have write permission to it, you need to make sure that the elasticsearch user has write permission to the path /usr/share/elasticsearch/logs.

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.