---
- name: Decide which Debian release to use
  set_fact:
    java_apt_release: '{% if ansible_distribution_release == "jessie" %}jessie-backports{% else %}{{ ansible_distribution_release }}{% endif %}'
  tags:
    - java

- name: Install jessie-backports
  include_role:
    name: evolix/apt
    tasks_from: backports.yml
  when: ansible_distribution_release == "jessie"
  tags:
    - java

- name: Install openjdk package
  apt:
    name: "openjdk-{{ java_version}}-jre-headless"
    default_release: "{{ java_apt_release }}"
    state: present
  tags:
    - java
    - packages

- name: This openjdk version is the default alternative
  alternatives:
    name: java
    path: "{{ java_bin_path[java_version] }}"
  when: java_default_alternative
  tags:
    - java
