Skip to content
Open
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
6 changes: 6 additions & 0 deletions .ansible-lint
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
profile: production
exclude_paths:
- .github/
- .travis.yml
- molecule/default/yaml-lint.yml
59 changes: 59 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
---
name: CI
on:
- push
- pull_request

jobs:
lint:
name: Lint
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4

- name: Set up Python 3
uses: actions/setup-python@v5
with:
python-version: '3.13'

- name: Install lint dependencies
run: pip3 install "ansible==14.*" "ansible-lint==26.*" "yamllint==1.*"

- name: Lint YAML
run: yamllint .

- name: Lint Ansible
run: ansible-lint

test:
name: Molecule
needs: lint
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
distro:
- ubuntu2204
- ubuntu2404
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
path: "${{ github.repository }}"

- name: Set up Python 3
uses: actions/setup-python@v5
with:
python-version: '3.13'

- name: Install test dependencies
run: pip3 install "ansible==14.*" "molecule==26.*" "molecule-plugins[docker]==26.*" docker

- name: Run Molecule tests
working-directory: "${{ github.repository }}"
run: molecule test
env:
PY_COLORS: '1'
ANSIBLE_FORCE_COLOR: '1'
MOLECULE_DISTRO: ${{ matrix.distro }}
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
*.retry
*/__pycache__
*.pyc
.ansible/
20 changes: 20 additions & 0 deletions .yamllint
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
---
extends: default

rules:
comments:
min-spaces-from-content: 1
comments-indentation: false
braces:
max-spaces-inside: 1
octal-values:
forbid-implicit-octal: true
forbid-explicit-octal: true
line-length:
max: 160
truthy:
allowed-values: ["true", "false"]
check-keys: false

ignore: |
.travis.yml
2 changes: 1 addition & 1 deletion defaults/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@
java_home: ""
# Whether to set the installed Java binary as the default java. You will need
# to set java_home too for this to be done
java_set_default: true
java_set_default: true
13 changes: 8 additions & 5 deletions meta/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,18 @@ dependencies: []

galaxy_info:
role_name: java
namespace: onaio
author: geerlingguy
description: Java for Linux
company: "Midwestern Mac, LLC"
license: "license (BSD, MIT)"
min_ansible_version: 2.4
min_ansible_version: "2.4"
platforms:
- name: EL
versions:
- 6
- 7
- 8
- "6"
- "7"
- "8"
- name: Fedora
versions:
- all
Expand All @@ -29,9 +30,11 @@ galaxy_info:
- trusty
- xenial
- bionic
- jammy
- noble
- name: FreeBSD
versions:
- 10.2
- "10.2"
galaxy_tags:
- development
- system
Expand Down
22 changes: 8 additions & 14 deletions molecule/default/molecule.yml
Original file line number Diff line number Diff line change
@@ -1,29 +1,23 @@
---
dependency:
name: galaxy
enabled: false
driver:
name: docker
lint:
name: yamllint
options:
config-file: molecule/default/yaml-lint.yml
platforms:
- name: instance
image: "geerlingguy/docker-${MOLECULE_DISTRO:-centos7}-ansible:latest"
command: ${MOLECULE_DOCKER_COMMAND:-""}
volumes:
- /sys/fs/cgroup:/sys/fs/cgroup:ro
image: geerlingguy/docker-${MOLECULE_DISTRO:-ubuntu2204}-ansible:latest
privileged: true
command: /sbin/init
volumes:
- /sys/fs/cgroup:/sys/fs/cgroup:rw
cgroupns_mode: host
pre_build_image: true
provisioner:
name: ansible
lint:
name: ansible-lint
playbooks:
converge: ${MOLECULE_PLAYBOOK:-playbook.yml}
converge: playbook.yml
scenario:
name: default
verifier:
name: testinfra
lint:
name: flake8
name: ansible
10 changes: 7 additions & 3 deletions molecule/default/playbook.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,13 @@

pre_tasks:
- name: Update apt cache.
apt: update_cache=true cache_valid_time=600
ansible.builtin.apt:
update_cache: "true"
cache_valid_time: "600"
when: ansible_os_family == 'Debian'
changed_when: false

roles:
- role: geerlingguy.java
tasks:
- name: Run the role
ansible.builtin.include_role:
name: "{{ lookup('env', 'MOLECULE_PROJECT_DIRECTORY') }}"
13 changes: 13 additions & 0 deletions molecule/default/verify.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
---
- name: Verify
hosts: all
tasks:
- name: Run java
ansible.builtin.command: java -version
register: java_version
changed_when: false

- name: Assert OpenJDK is installed
ansible.builtin.assert:
that:
- "'openjdk' in java_version.stderr | lower"
29 changes: 15 additions & 14 deletions tasks/main.yml
Original file line number Diff line number Diff line change
@@ -1,47 +1,48 @@
---
- name: Include OS-specific variables for Fedora or FreeBSD.
include_vars: "{{ ansible_distribution }}.yml"
ansible.builtin.include_vars: "{{ ansible_distribution }}.yml"
when: ansible_distribution == 'FreeBSD' or ansible_distribution == 'Fedora'

- name: Include version-specific variables for CentOS/RHEL.
include_vars: "RedHat-{{ ansible_distribution_version.split('.')[0] }}.yml"
when: ansible_distribution == 'CentOS' or
ansible_distribution == 'Red Hat Enterprise Linux' or
ansible_distribution == 'RedHat'
ansible.builtin.include_vars: "RedHat-{{ ansible_distribution_version.split('.')[0] }}.yml"
when: ansible_distribution == 'CentOS' or ansible_distribution == 'Red Hat Enterprise Linux' or ansible_distribution == 'RedHat'

- name: Include version-specific variables for Ubuntu.
include_vars: "{{ ansible_distribution }}-{{ ansible_distribution_version.split('.')[0] }}.yml"
ansible.builtin.include_vars: "{{ ansible_distribution }}-{{ ansible_distribution_version.split('.')[0] }}.yml"
when: ansible_distribution == 'Ubuntu'

- name: Include version-specific variables for Debian.
include_vars: "{{ ansible_distribution|title }}-{{ ansible_distribution_version.split('.')[0] }}.yml"
ansible.builtin.include_vars: "{{ ansible_distribution | title }}-{{ ansible_distribution_version.split('.')[0] }}.yml"
when: ansible_os_family == 'Debian'

- name: Define java_packages.
set_fact:
ansible.builtin.set_fact:
java_packages: "{{ __java_packages | list }}"
when: java_packages is not defined

# Setup/install tasks.
- include_tasks: setup-RedHat.yml
- name: Install Java on RedHat
ansible.builtin.include_tasks: setup-RedHat.yml
when: ansible_os_family == 'RedHat'

- include_tasks: setup-Debian.yml
- name: Install Java on Debian
ansible.builtin.include_tasks: setup-Debian.yml
when: ansible_os_family == 'Debian'

- include_tasks: setup-FreeBSD.yml
- name: Install Java on FreeBSD
ansible.builtin.include_tasks: setup-FreeBSD.yml
when: ansible_os_family == 'FreeBSD'

# Environment setup.
- name: Set JAVA_HOME if configured.
template:
ansible.builtin.template:
src: java_home.sh.j2
dest: /etc/profile.d/java_home.sh
mode: 0644
mode: "0644"
when: java_home is defined and java_home | length > 0

- name: Set the default Java
alternatives:
community.general.alternatives:
name: java
path: "{{ java_home }}/bin/java"
when: java_home is defined and java_home | length > 0 and java_set_default
20 changes: 10 additions & 10 deletions tasks/setup-Debian.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# See: https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=863199 and
# https://github.com/geerlingguy/ansible-role-java/issues/64
- name: Ensure 'man' directory exists.
file:
ansible.builtin.file:
path: /usr/share/man/man1
state: directory
recurse: true
Expand All @@ -11,26 +11,26 @@
- ansible_distribution_version is version("18.04", ">=")

- name: Add Java 11 Repository for ubuntu 16.04
become: yes
become: true
become_user: root
apt_repository:
repo: 'ppa:openjdk-r/ppa'
ansible.builtin.apt_repository:
repo: "ppa:openjdk-r/ppa"
state: present
when:
- ansible_distribution == 'Ubuntu'
- ansible_distribution_version == '16.04'
register: openjdk11repo

- name: Update and upgrade apt packages for ubuntu 16.04
- name: Update and upgrade apt packages for ubuntu 16.04 # noqa: no-handler
become: true
become_user: root
apt:
upgrade: yes
update_cache: yes
ansible.builtin.apt:
upgrade: true
update_cache: true
when: openjdk11repo.changed

- name: Ensure Java is installed.
apt:
ansible.builtin.apt:
name: "{{ java_packages }}"
state: present
update_cache: yes
update_cache: true
20 changes: 15 additions & 5 deletions tasks/setup-FreeBSD.yml
Original file line number Diff line number Diff line change
@@ -1,11 +1,21 @@
---
- name: Ensure Java is installed.
pkgng:
community.general.pkgng:
name: "{{ java_packages }}"
state: present

- name: ensure proc is mounted
mount: name=/proc fstype=procfs src=proc opts=rw state=mounted
- name: Ensure proc is mounted
ansible.posix.mount:
name: /proc
fstype: procfs
src: proc
opts: rw
state: mounted

- name: ensure fdesc is mounted
mount: name=/dev/fd fstype=fdescfs src=fdesc opts=rw state=mounted
- name: Ensure fdesc is mounted
ansible.posix.mount:
name: /dev/fd
fstype: fdescfs
src: fdesc
opts: rw
state: mounted
2 changes: 1 addition & 1 deletion tasks/setup-RedHat.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
---
- name: Ensure Java is installed.
package:
ansible.builtin.package:
name: "{{ java_packages }}"
state: present
8 changes: 8 additions & 0 deletions vars/Ubuntu-24.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
---
# JDK version options include:
# - java
# - openjdk-11-jdk
# - openjdk-17-jdk
# - openjdk-21-jdk
__java_packages:
- openjdk-11-jdk
Loading