├── .ansible-lint ├── .github ├── FUNDING.yml ├── stale.yml └── workflows │ ├── ci.yml │ └── release.yml ├── .gitignore ├── .yamllint ├── LICENSE ├── README.md ├── defaults └── main.yml ├── meta └── main.yml ├── molecule └── default │ ├── converge.yml │ └── molecule.yml ├── tasks ├── main.yml ├── setup-Amazon.yml ├── setup-Debian.yml ├── setup-FreeBSD.yml └── setup-RedHat.yml ├── templates └── java_home.sh.j2 └── vars ├── Amazon-2.yml ├── Amazon-2023.yml ├── Debian-10.yml ├── Debian-11.yml ├── Debian-12.yml ├── Debian-8.yml ├── Debian-9.yml ├── Fedora.yml ├── FreeBSD.yml ├── RedHat-7.yml ├── RedHat-8.yml ├── RedHat-9.yml ├── Ubuntu-12.yml ├── Ubuntu-14.yml ├── Ubuntu-16.yml ├── Ubuntu-18.yml ├── Ubuntu-20.yml ├── Ubuntu-22.yml └── Ubuntu-24.yml /.ansible-lint: -------------------------------------------------------------------------------- 1 | skip_list: 2 | - 'yaml' 3 | - 'role-name' 4 | -------------------------------------------------------------------------------- /.github/FUNDING.yml: -------------------------------------------------------------------------------- 1 | # These are supported funding model platforms 2 | --- 3 | github: geerlingguy 4 | patreon: geerlingguy 5 | -------------------------------------------------------------------------------- /.github/stale.yml: -------------------------------------------------------------------------------- 1 | # Configuration for probot-stale - https://github.com/probot/stale 2 | 3 | # Number of days of inactivity before an Issue or Pull Request becomes stale 4 | daysUntilStale: 90 5 | 6 | # Number of days of inactivity before an Issue or Pull Request with the stale label is closed. 7 | # Set to false to disable. If disabled, issues still need to be closed manually, but will remain marked as stale. 8 | daysUntilClose: 30 9 | 10 | # Only issues or pull requests with all of these labels are check if stale. Defaults to `[]` (disabled) 11 | onlyLabels: [] 12 | 13 | # Issues or Pull Requests with these labels will never be considered stale. Set to `[]` to disable 14 | exemptLabels: 15 | - bug 16 | - pinned 17 | - security 18 | - planned 19 | 20 | # Set to true to ignore issues in a project (defaults to false) 21 | exemptProjects: false 22 | 23 | # Set to true to ignore issues in a milestone (defaults to false) 24 | exemptMilestones: false 25 | 26 | # Set to true to ignore issues with an assignee (defaults to false) 27 | exemptAssignees: false 28 | 29 | # Label to use when marking as stale 30 | staleLabel: stale 31 | 32 | # Limit the number of actions per hour, from 1-30. Default is 30 33 | limitPerRun: 30 34 | 35 | pulls: 36 | markComment: |- 37 | This pull request has been marked 'stale' due to lack of recent activity. If there is no further activity, the PR will be closed in another 30 days. Thank you for your contribution! 38 | 39 | Please read [this blog post](https://www.jeffgeerling.com/blog/2020/enabling-stale-issue-bot-on-my-github-repositories) to see the reasons why I mark pull requests as stale. 40 | 41 | unmarkComment: >- 42 | This pull request is no longer marked for closure. 43 | 44 | closeComment: >- 45 | This pull request has been closed due to inactivity. If you feel this is in error, please reopen the pull request or file a new PR with the relevant details. 46 | 47 | issues: 48 | markComment: |- 49 | This issue has been marked 'stale' due to lack of recent activity. If there is no further activity, the issue will be closed in another 30 days. Thank you for your contribution! 50 | 51 | Please read [this blog post](https://www.jeffgeerling.com/blog/2020/enabling-stale-issue-bot-on-my-github-repositories) to see the reasons why I mark issues as stale. 52 | 53 | unmarkComment: >- 54 | This issue is no longer marked for closure. 55 | 56 | closeComment: >- 57 | This issue has been closed due to inactivity. If you feel this is in error, please reopen the issue or file a new issue with the relevant details. 58 | -------------------------------------------------------------------------------- /.github/workflows/ci.yml: -------------------------------------------------------------------------------- 1 | --- 2 | name: CI 3 | 'on': 4 | pull_request: 5 | push: 6 | branches: 7 | - master 8 | schedule: 9 | - cron: "0 7 * * 2" 10 | 11 | defaults: 12 | run: 13 | working-directory: 'geerlingguy.java' 14 | 15 | jobs: 16 | 17 | lint: 18 | name: Lint 19 | runs-on: ubuntu-latest 20 | steps: 21 | - name: Check out the codebase. 22 | uses: actions/checkout@v4 23 | with: 24 | path: 'geerlingguy.java' 25 | 26 | - name: Set up Python 3. 27 | uses: actions/setup-python@v5 28 | with: 29 | python-version: '3.x' 30 | 31 | - name: Install test dependencies. 32 | run: pip3 install yamllint 33 | 34 | - name: Lint code. 35 | run: | 36 | yamllint . 37 | 38 | molecule: 39 | name: Molecule 40 | runs-on: ubuntu-latest 41 | strategy: 42 | matrix: 43 | distro: 44 | - rockylinux9 45 | - ubuntu2404 46 | - ubuntu2204 47 | - ubuntu2004 48 | - debian12 49 | - debian11 50 | - amazonlinux2023 51 | 52 | steps: 53 | - name: Check out the codebase. 54 | uses: actions/checkout@v4 55 | with: 56 | path: 'geerlingguy.java' 57 | 58 | - name: Set up Python 3. 59 | uses: actions/setup-python@v5 60 | with: 61 | python-version: '3.x' 62 | 63 | - name: Install test dependencies. 64 | run: pip3 install ansible molecule molecule-plugins[docker] docker 65 | 66 | - name: Run Molecule tests. 67 | run: molecule test 68 | env: 69 | PY_COLORS: '1' 70 | ANSIBLE_FORCE_COLOR: '1' 71 | MOLECULE_DISTRO: ${{ matrix.distro }} 72 | -------------------------------------------------------------------------------- /.github/workflows/release.yml: -------------------------------------------------------------------------------- 1 | --- 2 | # This workflow requires a GALAXY_API_KEY secret present in the GitHub 3 | # repository or organization. 4 | # 5 | # See: https://github.com/marketplace/actions/publish-ansible-role-to-galaxy 6 | # See: https://github.com/ansible/galaxy/issues/46 7 | 8 | name: Release 9 | 'on': 10 | push: 11 | tags: 12 | - '*' 13 | 14 | defaults: 15 | run: 16 | working-directory: 'geerlingguy.java' 17 | 18 | jobs: 19 | 20 | release: 21 | name: Release 22 | runs-on: ubuntu-latest 23 | steps: 24 | - name: Check out the codebase. 25 | uses: actions/checkout@v4 26 | with: 27 | path: 'geerlingguy.java' 28 | 29 | - name: Set up Python 3. 30 | uses: actions/setup-python@v5 31 | with: 32 | python-version: '3.x' 33 | 34 | - name: Install Ansible. 35 | run: pip3 install ansible-core 36 | 37 | - name: Trigger a new import on Galaxy. 38 | run: >- 39 | ansible-galaxy role import --api-key ${{ secrets.GALAXY_API_KEY }} 40 | $(echo ${{ github.repository }} | cut -d/ -f1) $(echo ${{ github.repository }} | cut -d/ -f2) 41 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | *.retry 2 | */__pycache__ 3 | *.pyc 4 | .cache 5 | 6 | -------------------------------------------------------------------------------- /.yamllint: -------------------------------------------------------------------------------- 1 | --- 2 | extends: default 3 | 4 | rules: 5 | line-length: 6 | max: 120 7 | level: warning 8 | 9 | ignore: | 10 | .github/stale.yml 11 | .travis.yml 12 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2017 Jeff Geerling 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy of 6 | this software and associated documentation files (the "Software"), to deal in 7 | the Software without restriction, including without limitation the rights to 8 | use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of 9 | the Software, and to permit persons to whom the Software is furnished to do so, 10 | subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS 17 | FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 18 | COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 19 | IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 20 | CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 21 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Ansible Role: Java 2 | 3 | [![CI](https://github.com/geerlingguy/ansible-role-java/actions/workflows/ci.yml/badge.svg)](https://github.com/geerlingguy/ansible-role-java/actions/workflows/ci.yml) 4 | 5 | Installs Java for RedHat/CentOS, Amazon, and Debian/Ubuntu linux servers. 6 | 7 | ## Requirements 8 | 9 | None. 10 | 11 | ## Role Variables 12 | 13 | Available variables are listed below, along with default values: 14 | 15 | # The defaults provided by this role are specific to each distribution. 16 | java_packages: 17 | - java-1.8.0-openjdk 18 | 19 | Set the version/development kit of Java to install, along with any other necessary Java packages. Some other options include are included in the distribution-specific files in this role's 'defaults' folder. 20 | 21 | java_home: "" 22 | 23 | If set, the role will set the global environment variable `JAVA_HOME` to this value. 24 | 25 | ## Dependencies 26 | 27 | None. 28 | 29 | ## Example Playbook (using default package) 30 | 31 | - hosts: servers 32 | roles: 33 | - role: geerlingguy.java 34 | become: yes 35 | 36 | ## Example Playbook (install OpenJDK 8) 37 | 38 | For RHEL / CentOS: 39 | 40 | - hosts: server 41 | roles: 42 | - role: geerlingguy.java 43 | when: "ansible_os_family == 'RedHat'" 44 | java_packages: 45 | - java-1.8.0-openjdk 46 | 47 | For Ubuntu < 16.04: 48 | 49 | - hosts: server 50 | tasks: 51 | - name: installing repo for Java 8 in Ubuntu 52 | apt_repository: repo='ppa:openjdk-r/ppa' 53 | 54 | - hosts: server 55 | roles: 56 | - role: geerlingguy.java 57 | when: "ansible_os_family == 'Debian'" 58 | java_packages: 59 | - openjdk-8-jdk 60 | 61 | ## License 62 | 63 | MIT / BSD 64 | 65 | ## Author Information 66 | 67 | This role was created in 2014 by [Jeff Geerling](https://www.jeffgeerling.com/), author of [Ansible for DevOps](https://www.ansiblefordevops.com/). 68 | -------------------------------------------------------------------------------- /defaults/main.yml: -------------------------------------------------------------------------------- 1 | --- 2 | # Set java_packages if you would like to use a different version than the 3 | # default for the OS (see defaults per OS in `vars` directory). 4 | # java_packages: [] 5 | 6 | java_home: "" 7 | -------------------------------------------------------------------------------- /meta/main.yml: -------------------------------------------------------------------------------- 1 | --- 2 | dependencies: [] 3 | 4 | galaxy_info: 5 | role_name: java 6 | author: geerlingguy 7 | description: Java for Linux 8 | company: "Midwestern Mac, LLC" 9 | license: "license (BSD, MIT)" 10 | min_ansible_version: 2.10 11 | platforms: 12 | - name: Fedora 13 | versions: 14 | - all 15 | - name: Debian 16 | versions: 17 | - wheezy 18 | - jessie 19 | - stretch 20 | - buster 21 | - bullseye 22 | - bookworm 23 | - name: Ubuntu 24 | versions: 25 | - precise 26 | - trusty 27 | - xenial 28 | - bionic 29 | - focal 30 | - jammy 31 | - noble 32 | - name: FreeBSD 33 | versions: 34 | - 10.2 35 | galaxy_tags: 36 | - development 37 | - system 38 | - web 39 | - java 40 | - jdk 41 | - openjdk 42 | - oracle 43 | -------------------------------------------------------------------------------- /molecule/default/converge.yml: -------------------------------------------------------------------------------- 1 | --- 2 | - name: Converge 3 | hosts: all 4 | #become: true 5 | 6 | pre_tasks: 7 | - name: Update apt cache. 8 | apt: 9 | update_cache: true 10 | cache_valid_time: 600 11 | when: ansible_os_family == 'Debian' 12 | changed_when: false 13 | 14 | roles: 15 | - role: geerlingguy.java 16 | -------------------------------------------------------------------------------- /molecule/default/molecule.yml: -------------------------------------------------------------------------------- 1 | --- 2 | role_name_check: 1 3 | dependency: 4 | name: galaxy 5 | options: 6 | ignore-errors: true 7 | driver: 8 | name: docker 9 | platforms: 10 | - name: instance 11 | image: "geerlingguy/docker-${MOLECULE_DISTRO:-rockylinux9}-ansible:latest" 12 | command: ${MOLECULE_DOCKER_COMMAND:-""} 13 | volumes: 14 | - /sys/fs/cgroup:/sys/fs/cgroup:rw 15 | cgroupns_mode: host 16 | privileged: true 17 | pre_build_image: true 18 | provisioner: 19 | name: ansible 20 | playbooks: 21 | converge: ${MOLECULE_PLAYBOOK:-converge.yml} 22 | -------------------------------------------------------------------------------- /tasks/main.yml: -------------------------------------------------------------------------------- 1 | --- 2 | - name: Include OS-specific variables for Fedora or FreeBSD. 3 | include_vars: "{{ ansible_distribution }}.yml" 4 | when: ansible_distribution == 'FreeBSD' or ansible_distribution == 'Fedora' 5 | 6 | - name: Include OS-specific variables for Amazon. 7 | include_vars: "{{ ansible_distribution }}-{{ ansible_distribution_version}}.yml" 8 | when: ansible_distribution == 'Amazon' 9 | 10 | - name: Include version-specific variables for CentOS/RHEL. 11 | include_vars: "RedHat-{{ ansible_distribution_version.split('.')[0] }}.yml" 12 | when: >- 13 | ansible_distribution in [ 14 | 'CentOS', 15 | 'Red Hat Enterprise Linux', 16 | 'RedHat', 17 | 'OracleLinux', 18 | 'Rocky', 19 | 'AlmaLinux' 20 | ] 21 | 22 | - name: Include version-specific variables for Ubuntu. 23 | include_vars: "{{ ansible_distribution }}-{{ ansible_distribution_version.split('.')[0] }}.yml" 24 | when: ansible_distribution == 'Ubuntu' 25 | 26 | - name: Include version-specific variables for Debian. 27 | include_vars: "{{ ansible_distribution | title }}-{{ ansible_distribution_version.split('.')[0] }}.yml" 28 | when: ansible_os_family == 'Debian' 29 | 30 | - name: Define java_packages. 31 | set_fact: 32 | java_packages: "{{ __java_packages | list }}" 33 | when: java_packages is not defined 34 | 35 | # Setup/install tasks. 36 | - include_tasks: setup-RedHat.yml 37 | when: ansible_os_family == 'RedHat' 38 | 39 | - include_tasks: setup-Amazon.yml 40 | when: ansible_distribution == 'Amazon' 41 | 42 | - include_tasks: setup-Debian.yml 43 | when: ansible_os_family == 'Debian' 44 | 45 | - include_tasks: setup-FreeBSD.yml 46 | when: ansible_os_family == 'FreeBSD' 47 | 48 | # Environment setup. 49 | - name: Set JAVA_HOME if configured. 50 | template: 51 | src: java_home.sh.j2 52 | dest: /etc/profile.d/java_home.sh 53 | mode: 0644 54 | when: java_home is defined and java_home 55 | -------------------------------------------------------------------------------- /tasks/setup-Amazon.yml: -------------------------------------------------------------------------------- 1 | --- 2 | - name: Ensure Java is installed. 3 | package: 4 | name: "{{ java_packages }}" 5 | state: present 6 | -------------------------------------------------------------------------------- /tasks/setup-Debian.yml: -------------------------------------------------------------------------------- 1 | --- 2 | # See: https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=863199 and 3 | # https://github.com/geerlingguy/ansible-role-java/issues/64 4 | - name: Ensure 'man' directory exists. 5 | file: # noqa 208 6 | path: /usr/share/man/man1 7 | state: directory 8 | mode: 0755 9 | when: 10 | - ansible_distribution == 'Ubuntu' 11 | - ansible_distribution_major_version | int >= 18 12 | 13 | - name: Ensure Java is installed. 14 | apt: 15 | name: "{{ java_packages }}" 16 | state: present 17 | -------------------------------------------------------------------------------- /tasks/setup-FreeBSD.yml: -------------------------------------------------------------------------------- 1 | --- 2 | - name: Ensure Java is installed. 3 | pkgng: 4 | name: "{{ java_packages }}" 5 | state: present 6 | 7 | - name: Ensure proc is mounted 8 | mount: 9 | name: /proc 10 | fstype: procfs 11 | src: proc 12 | opts: rw 13 | state: mounted 14 | 15 | - name: Ensure fdesc is mounted 16 | mount: 17 | name: /dev/fd 18 | fstype: fdescfs 19 | src: fdesc 20 | opts: rw 21 | state: mounted 22 | -------------------------------------------------------------------------------- /tasks/setup-RedHat.yml: -------------------------------------------------------------------------------- 1 | --- 2 | - name: Ensure Java is installed. 3 | package: 4 | name: "{{ java_packages }}" 5 | state: present 6 | -------------------------------------------------------------------------------- /templates/java_home.sh.j2: -------------------------------------------------------------------------------- 1 | export JAVA_HOME={{ java_home }} 2 | -------------------------------------------------------------------------------- /vars/Amazon-2.yml: -------------------------------------------------------------------------------- 1 | --- 2 | # JDK version options include: 3 | # - java-1.7.0-openjdk 4 | # - java-1.8.0-openjdk 5 | # - java-11-amazon-corretto 6 | # - java-17-amazon-corretto 7 | __java_packages: 8 | - java-17-amazon-corretto 9 | -------------------------------------------------------------------------------- /vars/Amazon-2023.yml: -------------------------------------------------------------------------------- 1 | --- 2 | # JDK version options include: 3 | # - java-1.8.0-openjdk 4 | # - java-11-amazon-corretto 5 | # - java-17-amazon-corretto 6 | # - java-21-amazon-corretto 7 | __java_packages: 8 | - java-11-amazon-corretto 9 | -------------------------------------------------------------------------------- /vars/Debian-10.yml: -------------------------------------------------------------------------------- 1 | --- 2 | # JDK version options include: 3 | # - java 4 | # - openjdk-11-jdk 5 | __java_packages: 6 | - openjdk-11-jdk 7 | -------------------------------------------------------------------------------- /vars/Debian-11.yml: -------------------------------------------------------------------------------- 1 | --- 2 | # JDK version options include: 3 | # - java 4 | # - openjdk-11-jdk 5 | __java_packages: 6 | - openjdk-11-jdk 7 | -------------------------------------------------------------------------------- /vars/Debian-12.yml: -------------------------------------------------------------------------------- 1 | --- 2 | # JDK version options include: 3 | # - java 4 | # - openjdk-17-jdk 5 | __java_packages: 6 | - openjdk-17-jdk 7 | -------------------------------------------------------------------------------- /vars/Debian-8.yml: -------------------------------------------------------------------------------- 1 | --- 2 | # JDK version options include: 3 | # - java 4 | # - openjdk-6-jdk 5 | # - openjdk-7-jdk 6 | __java_packages: 7 | - openjdk-7-jdk 8 | -------------------------------------------------------------------------------- /vars/Debian-9.yml: -------------------------------------------------------------------------------- 1 | --- 2 | # JDK version options include: 3 | # - java 4 | # - openjdk-8-jdk 5 | __java_packages: 6 | - openjdk-8-jdk 7 | -------------------------------------------------------------------------------- /vars/Fedora.yml: -------------------------------------------------------------------------------- 1 | --- 2 | # JDK version options include: 3 | # - java 4 | # - java-1.8.0-openjdk 5 | __java_packages: 6 | - java-1.8.0-openjdk 7 | -------------------------------------------------------------------------------- /vars/FreeBSD.yml: -------------------------------------------------------------------------------- 1 | --- 2 | # JDK version options for FreeBSD include: 3 | # - openjdk 4 | # - openjdk6 5 | # - openjdk8 6 | __java_packages: 7 | - openjdk 8 | -------------------------------------------------------------------------------- /vars/RedHat-7.yml: -------------------------------------------------------------------------------- 1 | --- 2 | # JDK version options include: 3 | # - java 4 | # - java-1.6.0-openjdk 5 | # - java-1.7.0-openjdk 6 | # - java-1.8.0-openjdk-devel 7 | # - java-11-openjdk-devel 8 | __java_packages: 9 | - java-1.8.0-openjdk 10 | -------------------------------------------------------------------------------- /vars/RedHat-8.yml: -------------------------------------------------------------------------------- 1 | --- 2 | # JDK version options include: 3 | # - java-1.8.0-openjdk 4 | # - java-11-openjdk 5 | # - java-latest-openjdk 6 | __java_packages: 7 | - java-11-openjdk 8 | -------------------------------------------------------------------------------- /vars/RedHat-9.yml: -------------------------------------------------------------------------------- 1 | --- 2 | # JDK version options include: 3 | # - java-1.8.0-openjdk 4 | # - java-11-openjdk 5 | # - java-17-openjdk 6 | __java_packages: 7 | - java-17-openjdk 8 | -------------------------------------------------------------------------------- /vars/Ubuntu-12.yml: -------------------------------------------------------------------------------- 1 | --- 2 | # JDK version options include: 3 | # - java 4 | # - openjdk-6-jdk 5 | # - openjdk-7-jdk 6 | __java_packages: 7 | - openjdk-7-jdk 8 | -------------------------------------------------------------------------------- /vars/Ubuntu-14.yml: -------------------------------------------------------------------------------- 1 | --- 2 | # JDK version options include: 3 | # - java 4 | # - openjdk-6-jdk 5 | # - openjdk-7-jdk 6 | __java_packages: 7 | - openjdk-7-jdk 8 | -------------------------------------------------------------------------------- /vars/Ubuntu-16.yml: -------------------------------------------------------------------------------- 1 | --- 2 | # JDK version options include: 3 | # - java 4 | # - openjdk-8-jdk 5 | # - openjdk-9-jdk 6 | __java_packages: 7 | - openjdk-8-jdk 8 | -------------------------------------------------------------------------------- /vars/Ubuntu-18.yml: -------------------------------------------------------------------------------- 1 | --- 2 | # JDK version options include: 3 | # - java 4 | # - openjdk-11-jdk 5 | __java_packages: 6 | - openjdk-11-jdk 7 | -------------------------------------------------------------------------------- /vars/Ubuntu-20.yml: -------------------------------------------------------------------------------- 1 | --- 2 | # JDK version options include: 3 | # - java 4 | # - openjdk-11-jdk 5 | __java_packages: 6 | - openjdk-11-jdk 7 | -------------------------------------------------------------------------------- /vars/Ubuntu-22.yml: -------------------------------------------------------------------------------- 1 | --- 2 | # JDK version options include: 3 | # - java 4 | # - openjdk-18-jdk 5 | __java_packages: 6 | - openjdk-17-jdk 7 | -------------------------------------------------------------------------------- /vars/Ubuntu-24.yml: -------------------------------------------------------------------------------- 1 | --- 2 | # JDK version options include: 3 | # - java 4 | # - openjdk-17-jdk 5 | __java_packages: 6 | - openjdk-21-jdk 7 | --------------------------------------------------------------------------------