From b9c9218418ec6510902e6197dd7ddd9dcaed9037 Mon Sep 17 00:00:00 2001 From: Andrea Dell'Amico Date: Mon, 22 Jul 2024 11:22:58 +0200 Subject: [PATCH] Use version_compare for the version comparisons. --- tasks/main.yml | 4 ++-- tasks/tomcat-pkgs.yml | 16 ++++++++++++---- templates/tomcat-default.j2 | 4 ++-- templates/tomcat-server.xml.j2 | 2 +- 4 files changed, 17 insertions(+), 9 deletions(-) diff --git a/tasks/main.yml b/tasks/main.yml index a676009..6b338ac 100644 --- a/tasks/main.yml +++ b/tasks/main.yml @@ -11,10 +11,10 @@ - import_tasks: tomcat-log4j-logging.yml when: - tomcat_use_log4j - - tomcat_version <= 7 + - tomcat_version is version_compare('7', '<=') tags: ['tomcat', 'tomcat_log4j'] - import_tasks: tomcat-logger-logging.yml - when: not tomcat_use_log4j or tomcat_version > 7 + when: not tomcat_use_log4j or tomcat_version is version_compare('7', '>') - import_tasks: access_log.yml when: tomcat_access_log_enabled - import_tasks: pgsql_jdbc.yml diff --git a/tasks/tomcat-pkgs.yml b/tasks/tomcat-pkgs.yml index e1f3c74..dde6c0c 100644 --- a/tasks/tomcat-pkgs.yml +++ b/tasks/tomcat-pkgs.yml @@ -3,7 +3,7 @@ set_fact: tomcat_version: 7 when: - - ansible_distribution_major_version <= '16' + - ansible_distribution_major_version is version_compare('16.04', '<') - tomcat_fixed_version is not defined tags: [ 'tomcat', 'tomcat_ver', 'tomcat_conf', 'tomcat_javamelody' ] @@ -11,7 +11,15 @@ set_fact: tomcat_version: 8 when: - - ansible_distribution_major_version == '18' + - ansible_distribution_major_version is version_compare('18.04', '==') + - tomcat_fixed_version is not defined + tags: [ 'tomcat', 'tomcat_ver', 'tomcat_conf', 'tomcat_javamelody' ] + +- name: Set the tomcat version for Ubuntu bionic + set_fact: + tomcat_version: 10 + when: + - ansible_distribution_major_version is version_compare('24.04', '==') - tomcat_fixed_version is not defined tags: [ 'tomcat', 'tomcat_ver', 'tomcat_conf', 'tomcat_javamelody' ] @@ -32,7 +40,7 @@ - name: Install additional packages needed by tomcat 8+ apt: pkg={{ tomcat8_additional_pkgs }} state={{ tomcat_pkg_state }} cache_valid_time=1800 - when: tomcat_version >= 8 + when: tomcat_version is version_compare('8', '>=') tags: [ 'tomcat', 'tomcat_javamelody', 'tomcat_conf', 'tomcat_javamelody' ] - name: Create the tomcat tmp directory @@ -81,5 +89,5 @@ file: src=/usr/share/java/{{ item }} dest={{ tomcat_catalina_home_dir }}/bin/{{ item }} state=link owner=root group=root mode=0644 with_items: - commons-daemon.jar - when: tomcat_version >= 8 + when: tomcat_version is version_compare('8', '>=') tags: [ 'tomcat', 'tomcat_conf' ] diff --git a/templates/tomcat-default.j2 b/templates/tomcat-default.j2 index 698f436..8e083e9 100644 --- a/templates/tomcat-default.j2 +++ b/templates/tomcat-default.j2 @@ -19,14 +19,14 @@ JAVA_HOME={{ jdk_java_home }} {% endif %} JAVA_OPTS="-server -Djava.awt.headless=true -Dfile.encoding={{ tomcat_file_encoding }}" -{% if jdk_default <= 7 %} +{% if jdk_default is version_compare('7', '<=') %} {% if tomcat_permgen_defined %} {% if tomcat_permgen_size is defined %} JAVA_OPTS="-XX:MaxPermSize={{ tomcat_permgen_size }} $JAVA_OPTS" {% endif %} {% endif %} {% endif %} -{% if jdk_default >= 8 %} +{% if jdk_default is version_compare('8', '>=') %} JAVA_OPTS="{{ tomcat_additional_java_8_opts }} $JAVA_OPTS" {% endif %} {% if tomcat_java_opts is defined %} diff --git a/templates/tomcat-server.xml.j2 b/templates/tomcat-server.xml.j2 index 2aaee74..2c84eb5 100644 --- a/templates/tomcat-server.xml.j2 +++ b/templates/tomcat-server.xml.j2 @@ -32,7 +32,7 @@ -{% if tomcat_version <= 7 %} +{% if tomcat_version is version_compare (7, '<=') %} {% endif %}