Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add amazonlinux support and improv common role style #4

Merged
merged 7 commits into from
May 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .github/workflows/molecule.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ jobs:
strategy:
matrix:
include:
- distro: 'amazonlinux-2023'
- distro: 'debian-12'
- distro: 'rockylinux-9'
- distro: 'ubuntu-22.04'
Expand Down
11 changes: 7 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
Java
====

An Ansible role to install Java.
An Ansible role to install the `Java` package.

Requirements
------------

- Supported version of Ansible: 2.12 and highter.
- Supported platforms:
- Amazon Linux
- all
- Debian
- 10
- 11
Expand All @@ -24,7 +26,8 @@ Requirements
Role Variables
--------------

- `java_package` `Java` package name (see default values in `vars/*.yml`).
- `java_package` The Java package name (see default values in `vars/*.yml`).
- `java_home` The JAVA_HOME environment variable is used to specify the location of the Java executable files.

Dependencies
------------
Expand All @@ -34,11 +37,11 @@ None.
Example Playbook
----------------

Install `Java` package:
Install the `Java` package:

```yaml
---
- name: 'Install Java package'
- name: 'Install the Java package'
hosts: all

roles:
Expand Down
1 change: 1 addition & 0 deletions defaults/main.yml
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
---
java_package: '{{ _default_java_package }}'
java_home: ''
20 changes: 12 additions & 8 deletions meta/main.yml
Original file line number Diff line number Diff line change
@@ -1,33 +1,37 @@
---
galaxy_info:
author: antmelekhin
role_name: java
description: An Ansible role to install Java.
author: 'antmelekhin'
role_name: 'java'
description: 'An Ansible role to install the Java package.'

license: MIT
license: 'MIT'

min_ansible_version: '2.12'

platforms:
- name: Debian
- name: 'Amazon Linux'
versions:
- 'all'
- name: 'Debian'
versions:
- 'buster'
- 'bullseye'
- 'bookworm'
- name: EL
- name: 'EL'
versions:
- '7'
- '8'
- '9'
- name: Ubuntu
- name: 'Ubuntu'
versions:
- 'bionic'
- 'focal'
- 'jammy'

galaxy_tags:
- 'openjdk'
- 'corretto'
- 'java'
- 'jdk'
- 'openjdk'

dependencies: []
12 changes: 6 additions & 6 deletions molecule/default/molecule.yml
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
---
role_name_check: 2
dependency:
name: galaxy
name: 'galaxy'
enabled: true
driver:
name: docker
name: 'docker'
platforms:
- name: 'java-${IMAGE:-docker-systemd}-${TAG:-ubuntu-22.04}${TOX_ENVNAME}'
image: '${NAMESPACE:-antmelekhin}/${IMAGE:-docker-systemd}:${TAG:-ubuntu-22.04}'
volumes:
- /sys/fs/cgroup:/sys/fs/cgroup:rw
- /var/lib/containerd
- '/sys/fs/cgroup:/sys/fs/cgroup:rw'
- '/var/lib/containerd'
cgroupns_mode: host
privileged: true
pre_build_image: true
provisioner:
name: ansible
name: 'ansible'
verifier:
name: ansible
name: 'ansible'
6 changes: 3 additions & 3 deletions molecule/default/verify.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@
gather_facts: false

tasks:
- name: 'Check current Java version'
- name: 'Check the current Java version'
ansible.builtin.command:
cmd: 'java --version'
changed_when: false
register: __java_version_check

- name: 'Java version output'
- name: 'The Java version output'
ansible.builtin.debug:
var: __java_version_check.stdout
var: __java_version_check.stdout_lines[0]
2 changes: 1 addition & 1 deletion tasks/configure.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@
src: 'java_home.sh.j2'
dest: '/etc/profile.d/java_home.sh'
mode: 0755
when: java_home is defined and java_home
when: java_home | length
become: true
2 changes: 1 addition & 1 deletion tasks/install-Debian.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
---
- name: 'Install Java package'
- name: 'Debian | Install the Java package'
ansible.builtin.apt:
name: '{{ java_package }}'
update_cache: true
Expand Down
2 changes: 1 addition & 1 deletion tasks/install-RedHat.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
---
- name: 'Install Java package'
- name: 'RedHat | Install the Java package'
ansible.builtin.package:
name: '{{ java_package }}'
state: 'present'
Expand Down
13 changes: 9 additions & 4 deletions tasks/main.yml
Original file line number Diff line number Diff line change
@@ -1,9 +1,14 @@
---
- name: 'Include OS-specific Java variables'
ansible.builtin.include_vars: '{{ ansible_os_family }}.yml'
- name: 'Load the Java OS-specific variables'
ansible.builtin.include_vars: '{{ java_variables_file }}'
with_first_found:
- '{{ ansible_distribution }}.yml'
- '{{ ansible_os_family }}.yml'
loop_control:
loop_var: java_variables_file

- name: 'Include tasks to install Java'
- name: 'Install the Java package'
ansible.builtin.include_tasks: 'install-{{ ansible_os_family }}.yml'

- name: 'Include tasks to configure Java'
- name: 'Configure the Java package'
ansible.builtin.import_tasks: 'configure.yml'
2 changes: 2 additions & 0 deletions vars/Amazon.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
---
_default_java_package: "{{ (ansible_distribution_major_version == '2018') | ternary('java-1.8.0-openjdk', 'java-17-amazon-corretto') }}"