Skip to content

Commit

Permalink
Allow setting a java version per instance.
Browse files Browse the repository at this point in the history
  • Loading branch information
robert-de-bock committed Mar 3, 2025
1 parent 82248db commit efe65f6
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 4 deletions.
10 changes: 6 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,8 @@ This example is taken from [`molecule/default/converge.yml`](https://github.com/
# - host-manager
# - manager
# - ROOT
# - name: "tomcat-java_home"
# java_home: "/opt/java/jdk-17"

roles:
- role: robertdebock.tomcat
Expand Down Expand Up @@ -154,7 +156,7 @@ The default values for the variables are set in [`defaults/main.yml`](https://gi
# Some "sane" defaults.
tomcat_name: tomcat
tomcat_directory: /opt
tomcat_version: 9
tomcat_version: 10
tomcat_user: tomcat
tomcat_group: tomcat
tomcat_xms: 512M
Expand Down Expand Up @@ -216,9 +218,9 @@ tomcat_instances:

# The explicit version to use when referring to the short name.
tomcat_version7: "7.0.109"
tomcat_version8: "8.5.73"
tomcat_version9: "9.0.55"
tomcat_version10: "10.1.12"
tomcat_version8: "8.5.100"
tomcat_version9: "9.0.100"
tomcat_version10: "10.1.36"

# The location where to download Apache Tomcat from.
tomcat_mirror: "https://archive.apache.org"
Expand Down
2 changes: 2 additions & 0 deletions molecule/default/converge.yml
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,8 @@
# - host-manager
# - manager
# - ROOT
# - name: "tomcat-java_home"
# java_home: "/opt/java/jdk-17"

roles:
- role: ansible-role-tomcat
12 changes: 12 additions & 0 deletions tasks/assert.yml
Original file line number Diff line number Diff line change
Expand Up @@ -441,3 +441,15 @@
label: "{{ item.name }}"
when:
- item.remove_webapps is defined

- name: assert | Test item.java_home in tomcat_instances
ansible.builtin.assert:
that:
- item.java_home is string
- item.java_home is not none
quiet: true
loop: "{{ tomcat_instances }}"
loop_control:
label: "{{ item.name }}"
when:
- item.java_home is defined
5 changes: 5 additions & 0 deletions templates/setenv.sh.j2
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
{{ ansible_managed | comment }}

{% if instance.java_home is defined %}
JAVA_HOME="{{ instance.java_home }}"
PATH=$JAVA_HOME/bin:/$PATH
{% endif %}

{% if instance.java_opts is defined %}
{% for java_opt in instance.java_opts %}
{{ java_opt.name }}="{{ java_opt.value }}"
Expand Down

0 comments on commit efe65f6

Please sign in to comment.