OpenJDK role that works on both deb/ubuntu and EL.

This commit is contained in:
Andrea Dell'Amico 2020-05-28 16:10:25 +02:00
parent 400b2a817a
commit 71bfcb5010
6 changed files with 177 additions and 69 deletions

View File

@ -1,31 +1,25 @@
Role Name
=========
A brief description of the role goes here.
Requirements
------------
Any pre-requisites that may not be covered by Ansible itself or the role should be mentioned here. For instance, if the role uses the EC2 module, it may be a good idea to mention in this section that the boto package is required.
A role that installs OpenJDK. The role removes a Oracle JDK if it finds it on the system (Ubuntu only)
Role Variables
--------------
A description of the settable variables for this role should go here, including any variables that are in defaults/main.yml, vars/main.yml, and any variables that can/should be set via parameters to the role. Any variables that are read from other roles and/or the global scope (ie. hostvars, group vars, etc.) should be mentioned here as well.
Here are listed the most important defaults. See defaults/main.yml for the complete set of variables.
``` yaml
openjdk_default: 8
openjdk_pkgs:
- jre-headless
- jdk-headless
# - jre
# - jdk
```
Dependencies
------------
A list of other roles hosted on Galaxy should go here, plus any details in regards to parameters that may need to be set for other roles, or variables that are used from other roles.
Example Playbook
----------------
Including an example of how to use your role (for instance, with variables passed in as parameters) is always nice for users too:
- hosts: servers
roles:
- { role: username.rolename, x: 42 }
None
License
-------
@ -35,4 +29,4 @@ EUPL-1.2
Author Information
------------------
An optional section for the role authors to include contact information, or a website (HTML is not allowed).
Andrea Dell'Amico, <andrea.dellamico@isti.cnr.it>

View File

@ -1,2 +1,44 @@
---
# defaults file for ansible-role-template
openjdk_install: True
openjdk_default: 8
jdk_default: '{{ openjdk_default }}'
openjdk_pkg_state: present
openjdk_version:
- '{{ openjdk_default }}'
dismissed_openjdk_ppa: 'ppa:openjdk-r/ppa'
openjdk_zulu_repo_install: False
openjdk_zulu_repo_key_id: '0xB1998361219BD9C9'
openjdk_zulu_repository: 'deb http://repos.azulsystems.com/{{ ansible_distribution | lower }} stable main'
openjdk_java_home: '/usr/lib/jvm/java-{{ openjdk_default }}-openjdk-amd64'
jdk_java_home: '{{ openjdk_java_home }}'
# jdk_java_home: '/usr/lib/jvm/java-{{ openjdk_el_default_version }}-openjdk'
openjdk_zulu_java_home: '/usr/lib/jvm/zulu-{{ openjdk_default }}-amd64'
openjdk_zulu_package_name: zulu
openjdk_pkgs:
- jre-headless
- jdk-headless
# - jre
# - jdk
# This one we remove
oracle_jdk_ubuntu_ppa: 'ppa:webupd8team/java'
openjdk_oracle_jdk_pkgs:
- oracle-java7-installer
- oracle-java7-set-default
- oracle-java7-unlimited-jce-policy
- oracle-java8-installer
- oracle-java8-set-default
- oracle-java8-unlimited-jce-policy
openjdk_el_default_version: '1.{{ openjdk_default }}.0'
openjdk_el_version:
- '{{ openjdk_default_version }}'
# RHEL CentOS package names
# -devel is needed if we want javac.
openjdk_el_pkgs:
- openjdk-headless
- openjdk-devel

View File

@ -1,61 +1,27 @@
galaxy_info:
author: your name
description: your description
author: Andrea Dell'Amico
description: Systems Architect
company: ISTI-CNR
# If the issue tracker for your role is not on github, uncomment the
# next line and provide a value
issue_tracker_url: https://redmine-s2i2s.isti.cnr.it/projects/provisioning
# Some suggested licenses:
# - BSD (default)
# - MIT
# - GPLv2
# - GPLv3
# - Apache
# - CC-BY
license: EUPL-1.2
license: EUPL 1.2+
min_ansible_version: 2.8
# If this a Container Enabled role, provide the minimum Ansible Container version.
# min_ansible_container_version:
# Optionally specify the branch Galaxy will use when accessing the GitHub
# repo for this role. During role install, if no tags are available,
# Galaxy will use this branch. During import Galaxy will access files on
# this branch. If Travis integration is configured, only notifications for this
# branch will be accepted. Otherwise, in all cases, the repo's default branch
# (usually master) will be used.
#github_branch:
#
# Provide a list of supported platforms, and for each platform a list of versions.
# If you don't wish to enumerate all versions for a particular platform, use 'all'.
# To view available platforms and versions (or releases), visit:
# https://galaxy.ansible.com/api/v1/platforms/
#
# platforms:
# - name: Fedora
# versions:
# - all
# - 25
# - name: SomePlatform
# versions:
# - all
# - 1.0
# - 7
# - 99.99
galaxy_tags: []
# List tags for your role here, one per line. A tag is a keyword that describes
# and categorizes the role. Users find roles by searching for tags. Be sure to
# remove the '[]' above, if you add tags to this list.
#
# NOTE: A tag is limited to a single word comprised of alphanumeric characters.
# Maximum 20 tags per role.
dependencies: []
# List your role dependencies here, one per line. Be sure to remove the '[]' above,
# if you add dependencies to this list.
platforms:
- name: Ubuntu
versions:
- bionic
- name: EL
versions:
- 7
- 8
galaxy_tags:
- openjdk
- jdk
- jre

View File

@ -1,2 +1,5 @@
---
# tasks file for ansible-role-template
- import_tasks: openjdk_deb.yml
when: ansible_distribution_file_variety == "Debian"
- import_tasks: openjdk_el.yml
when: ansible_distribution_file_variety == "RedHat"

79
tasks/openjdk_deb.yml Normal file
View File

@ -0,0 +1,79 @@
---
- block:
- name: Remove the openjdk-r ppa. It is not maintained anymore
apt_repository: repo='{{ dismissed_openjdk_ppa }}' update_cache=yes state=absent
- name: Remove the Oracle JDK PPA
apt_repository: repo='{{ oracle_jdk_ubuntu_ppa }}' state=absent update_cache=yes
- name: Check if we must use the Zulu repository
set_fact:
openjdk_zulu_repo_install: True
when: ansible_distribution_major_version <= '16'
tags: [ 'jdk', 'openjdk' ]
- block:
- name: Install the Zulu repository key
apt_key: keyserver='hkp://keyserver.ubuntu.com' id={{ openjdk_zulu_repo_key_id }}
- name: Install the proper Zulu repository
apt_repository: repo='{{ openjdk_zulu_repository }}' update_cache=yes
- name: Install the Zulu OpenJDK
apt: pkg={{ openjdk_zulu_package_name }}-{{ item }} state={{ openjdk_pkg_state }} update_cache=yes cache_valid_time=3600
with_items: '{{ openjdk_version }}'
register: openjdk_installed
- name: Set the default OpenJDK as Zulu
shell: update-java-alternatives -s /usr/lib/jvm/zulu-{{ openjdk_default }}-amd64
when: openjdk_installed is changed
- name: Set the correct value for jdk_java_home when we are installing Zulu
set_fact:
jdk_java_home: '{{ openjdk_zulu_java_home }}'
when: openjdk_zulu_repo_install
tags: [ 'jdk', 'openjdk' ]
- block:
- name: Remove the Zulu repository if it is present
apt_repository: repo='{{ openjdk_zulu_repository }}' update_cache=yes state=absent
- name: Install the OpenJDK that comes with the distribution
apt: pkg=openjdk-{{ item.0 }}-{{ item[1] }} state={{ openjdk_pkg_state }} update_cache=yes cache_valid_time=3600
with_nested:
- '{{ openjdk_version }}'
- '{{ openjdk_pkgs }}'
register: openjdk_installed
- name: Set the default OpenJDK
shell: update-java-alternatives -s java-1.{{ openjdk_default }}.0-openjdk-amd64
when: openjdk_installed is changed
- name: Set the correct value for jdk_java_home when we are installing the distribution OpenJDK
set_fact:
jdk_java_home: '{{ openjdk_java_home }}'
when: not openjdk_zulu_repo_install
tags: [ 'jdk', 'openjdk' ]
- block:
- name: Rebuild the Ubuntu keystore
command: update-ca-certificates --fresh
when: openjdk_installed is changed
tags: [ 'jdk', 'openjdk' ]
- block:
- name: Remove the Oracle JDK packages
apt: pkg={{ openjdk_oracle_jdk_pkgs }} state=absent cache_valid_time=3600
- name: Remove the OpenJDK packages fthat come with the distribution when we use the Zulu repository
apt: pkg=openjdk-{{ item.0 }}-{{ item[1] }} state=absent update_cache=yes cache_valid_time=3600
with_nested:
- '{{ openjdk_version }}'
- '{{ openjdk_pkgs }}'
when: openjdk_zulu_repo_install
tags: [ 'jdk', 'openjdk' ]

24
tasks/openjdk_el.yml Normal file
View File

@ -0,0 +1,24 @@
---
- block:
- name: Install the OpenJDK packages
yum: pkg=java-{{ item.0 }}-{{ item[1] }} state={{ openjdk_pkg_state }}
with_nested:
- '{{ openjdk_el_version }}'
- '{{ openjdk_el_pkgs }}'
notify: Set the default OpenJDK
- name: Set fact jdk_installed
set_fact: jdk_installed=true
when: openjdk_install | bool
tags: [ 'jdk', 'openjdk' ]
- block:
- name: Remove the OpenJDK packages
yum: pkg=java-{{ item.0 }}-{{ item[1] }} state=absent
with_nested:
- '{{ openjdk_el_version }}'
- '{{ openjdk_el_pkgs }}'
when: not openjdk_install | bool
tags: [ 'jdk', 'openjdk' ]