geerlingguy / ansible-role-elasticsearch

Ansible Role - Elasticsearch
https://galaxy.ansible.com/geerlingguy/elasticsearch/
MIT License
185 stars 208 forks source link

on Ubuntu bionic beaver, it will fail to install because of Java 10 #36

Closed tychay closed 6 years ago

tychay commented 6 years ago

elasticsearch does not support Java 9 or 10, which is the default on Ubuntu.

I believe the solution is just to have it install java 8

roles:
    - role: geerlingguy.java
      java_packages:
        - openjdk-8-jdk
    - geerlingguy.elasticsearch

(not tested, I don't think you need to make a change, just document the dependency in the readme).

tychay commented 6 years ago

Okay tested. I needed a single task after the java role and before the elasticsearch role.

---
# This avoids the java10 error: 'Unrecognized VM option 'UseParNewGC'
# for elasticsearch
# c.f. https://stackoverflow.com/questions/49623648/logstash-with-java10-get-error-unrecognized-vm-option-useparnewgc
# in a manner similar to the way elastic.elasticsearch handles it
# c.f. https://github.com/elastic/ansible-elasticsearch/blob/master/tasks/java.yml for redhat
- name: downgrade to 1.8 if available (Debian)
  block: 
  - name: Get the installed java path (for Debian)
    shell: "update-alternatives --display java | grep '^/' | awk '{print $1}' | grep java-8 | head -1"
    become: yes
    register: java_full_path
    failed_when: false
    changed_when: false
  - name: set java alternatives to 1.8
    alternatives:
      name: java
      path: "{{ java_full_path.stdout }}"
      link: /usr/bin/java
    when: java_full_path is defined
  when: ansible_os_family == 'Debian'
- name: downgrade to 1.8 if available (RedHat)
  block: 
  - name: Get the installed java path (for RedHat)
    shell: "update-alternatives --display java | grep '^/' | awk '{print $1}' | grep 1.8.0 | head -1"
    become: yes
    register: java_full_path
    failed_when: false
    changed_when: false
  - name: set java alternatives to 1.8
    alternatives:
      name: java
      path: "{{ java_full_path.stdout }}"
      link: /usr/bin/java
    when: java_full_path is defined
  when: ansible_os_family == 'RedHat'

This downgrades java before starting the elasticsearch server. (Theoretically, it could go anywhere but if put before the roles, java might not be installed, and if put after then the script will fail/hang waiting for the server to start.

I only tested this for Ubuntu 18.04 LTS

geerlingguy commented 6 years ago

Yeah: https://travis-ci.org/geerlingguy/ansible-role-elasticsearch/jobs/445212649

The actual failure (if you go in and monitor syslog when it tries starting the service) is:

Oct 23 20:31:51 instance systemd[1]: Started Elasticsearch.
Oct 23 20:31:51 instance elasticsearch[5805]: Unrecognized VM option 'UseParNewGC'
Oct 23 20:31:51 instance elasticsearch[5805]: Error: Could not create the Java Virtual Machine.
Oct 23 20:31:51 instance elasticsearch[5805]: Error: A fatal exception has occurred. Program will exit.

It looks like this role is still on ES 2.x (yikes!). Upgrading to the latest version of Elasticsearch should make it compatible with Java 10...