Skip to content

Commit

Permalink
Add Java installation
Browse files Browse the repository at this point in the history
  • Loading branch information
bviktor committed Jan 19, 2023
1 parent 816536a commit e9b3184
Show file tree
Hide file tree
Showing 6 changed files with 29 additions and 4 deletions.
2 changes: 2 additions & 0 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ This role installs, configures, and upgrades Tomcat instances.
|---|---|---|---|
| `uid` | no | `1234` | UID to run Tomcat under. Defaults to `53`. |
| `gid` | no | `1234` | GID to run Tomcat under. Defaults to `53`. |
| `java_version` | no | `17` | Java version to install. Supported values are `8`, `11`, `17`. Defaults to `17`. |

## Examples

Expand All @@ -19,6 +20,7 @@ This role installs, configures, and upgrades Tomcat instances.
vars:
uid: 1234
gid: 1234
java_version: 17
```
## Return Values
Expand Down
20 changes: 20 additions & 0 deletions tasks/java.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
---
# Debian:
# - openjdk-8-jre-headless
# - openjdk-11-jre-headless
# - openjdk-17-jre-headless
#
# EL:
# - java-1.8.0-openjdk-headless
# - java-11-openjdk-headless
# - java-17-openjdk-headless
#
# Facepalm...

- set_fact:
pkg_java_ver: "{% if java_version is defined %}{% if ansible_os_family == 'RedHat' and java_version | string == '8' %}1.8.0{% else %}{{ java_version }}{% endif %}{% else %}{{ default_java_version }}{% endif %}"

- name: "Install Java {{ pkg_java_ver }}"
package:
name: "{% if ansible_os_family == 'RedHat' %}java-{{ pkg_java_ver }}-openjdk-headless{% else %}openjdk-{{ pkg_java_ver }}-jre-headless{% endif %}"
state: latest
1 change: 1 addition & 0 deletions tasks/main.yml
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
---
- include_tasks: unixcred.yml
- include_tasks: java.yml
4 changes: 2 additions & 2 deletions tasks/unixcred.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@
- name: Create Tomcat Unix grop
group:
name: tomcat
gid: "{{ gid | default(tomcat_id) }}"
gid: "{{ gid | default(default_tomcat_id) }}"

- name: Create Tomcat Unix user
user:
name: tomcat
uid: "{{ uid | default(tomcat_id) }}"
uid: "{{ uid | default(default_tomcat_id) }}"
group: tomcat
1 change: 1 addition & 0 deletions tests/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,4 @@
vars:
uid: 1234
gid: '1234'
java_version: 8
5 changes: 3 additions & 2 deletions vars/main.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
---
# this is the ID used on CentOS 7, let's default to that
tomcat_id: 53
# This is the ID used on CentOS 7, let's default to that.
default_tomcat_id: 53
default_java_version: 17

0 comments on commit e9b3184

Please sign in to comment.