---
- name: Install dependencies for build java package
  apt:
    name:
      - java-package
      - build-essential
    state: present
  tags:
  - java

- name: Create jvm dir
  file:
    path: "{{ item }}"
    state: directory
    mode: "0777"
  loop:
    - /srv/java-package
    - /srv/java-package/src
    - /srv/java-package/tmp
  tags:
  - java

- name: Get Oracle jre archive
  get_url:
    url: 'https://download.oracle.com/otn-pub/java/jdk/8u192-b12/750e1c8617c5452694857ad95c3ee230/server-jre-8u192-linux-x64.tar.gz'
    dest: '/srv/java-package/src/'
    checksum: 'sha256:3d811a5ec65dc6fc261f488757bae86ecfe285a79992363b016f60cdb4dbe7e6'
    headers: 'Cookie: oraclelicense=accept-securebackup-cookie'
    mode: "0644"
  tags:
  - java

- name: Make Debian package from Oracle JDK archive
  shell: "yes | TMPDIR=/srv/java-package/tmp make-jpkg /srv/java-package/src/server-jre-8u192-linux-x64.tar.gz"
  args:
    chdir: /srv/java-package
    creates: /srv/java-package/oracle-java8-server-jre_8u192_amd64.deb
  become: False
  tags:
  - java

- include_role:
    name: evolix/remount-usr

- name: Install java package
  apt:
    deb: /srv/java-package/oracle-java8-server-jre_8u192_amd64.deb
  tags:
   - java

- name: This openjdk version is the default alternative
  alternatives:
    name: java
    path: "/usr/lib/jvm/oracle-java{{ java_version }}-server-jre-amd64/bin/java"
  when: java_default_alternative | bool
  tags:
    - java
