---
# tasks file for java(On Debian family)
- name: Add repositories for latest Java packages
  apt_repository:
    repo: "{{ item }}"
  with_items: "{{ java_apt_repositories }}"
  become: yes
- block:
  # FYI.
  # https://github.com/docker-library/openjdk/pull/95
  # https://github.com/docker-library/openjdk/issues/96
  - name: Install proper CA certificate for Java installation.
    apt:
      name: 'ca-certificates-java=20161107~bpo8+1'
      update_cache: yes
      cache_valid_time: 3600
      install_recommends: no
  - name: Install Java with APT
    apt:
      name: 'openjdk-8-jdk'
      update_cache: yes
      cache_valid_time: 3600
      install_recommends: no
  become: yes

---
# tasks file for java(On Debian family)
- name: Add repositories for latest Java packages
  apt_repository:
    repo: "{{ item }}"
  with_items: "{{ java_apt_repositories }}"
  become: yes
- block:
  # FYI.
  # https://github.com/docker-library/openjdk/pull/95
  # https://github.com/docker-library/openjdk/issues/96
  - name: Install proper CA certificate for Java installation.
    apt:
      name: 'ca-certificates-java=20161107~bpo8+1'
      update_cache: yes
      cache_valid_time: 3600
      install_recommends: no
  - name: Install Java with APT
    apt:
      name: 'openjdk-8-jdk'
      update_cache: yes
      cache_valid_time: 3600
      install_recommends: no
  # TODO: Maybe, it causes several issues.
  - name: Remove Java7 (ca-certificates-java installs it, but it is no more needed after java8 installation)
    apt:
      name: 'openjdk-7-jre-headless'
      state: absent
  become: yes

Remove java7 installed with ca-certificates-java.
Remove java7 installed with ca-certificates-java.
