tomcat: add tags so that we set tomcat_version when we use tomcat_conf or tomcat_javamelody.

This commit is contained in:
Andrea Dell'Amico 2020-02-17 12:40:46 +01:00
parent a5c523bb4c
commit 973faadfe2
2 changed files with 44 additions and 49 deletions

View File

@ -11,7 +11,7 @@
user: name={{ item.user }} home={{ item.user_home }} createhome=false shell={{ item.user_shell | default('/bin/false') }} user: name={{ item.user }} home={{ item.user_home }} createhome=false shell={{ item.user_shell | default('/bin/false') }}
with_items: '{{ tomcat_m_instances }}' with_items: '{{ tomcat_m_instances }}'
when: when:
- not tomcat_m_use_default_user - not tomcat_m_use_default_user | bool
- item.user != "tomcat{{ tomcat_version }}" - item.user != "tomcat{{ tomcat_version }}"
register: tomcat_first_install register: tomcat_first_install
tags: [ 'tomcat', 'tomcat_instances' ] tags: [ 'tomcat', 'tomcat_instances' ]
@ -19,7 +19,7 @@
- name: Create a tomcat user if needed - name: Create a tomcat user if needed
user: name={{ tomcat_m_default_user }} home={{ tomcat_m_instances_base_path }} createhome=false shell={{ tomcat_m_default_user_shell }} user: name={{ tomcat_m_default_user }} home={{ tomcat_m_instances_base_path }} createhome=false shell={{ tomcat_m_default_user_shell }}
when: when:
- tomcat_m_use_default_user - tomcat_m_use_default_user | bool
- tomcat_m_default_user != "tomcat{{ tomcat_version }}" - tomcat_m_default_user != "tomcat{{ tomcat_version }}"
register: tomcat_first_install register: tomcat_first_install
tags: [ 'tomcat', 'tomcat_instances' ] tags: [ 'tomcat', 'tomcat_instances' ]
@ -68,8 +68,7 @@
- '{{ tomcat_m_instances }}' - '{{ tomcat_m_instances }}'
- [ 'context.xml' ] - [ 'context.xml' ]
register: restart_needed register: restart_needed
notify: notify: tomcat restart instances with changed configs
- tomcat restart instances with changed configs
tags: [ 'tomcat', 'tomcat_instances' ] tags: [ 'tomcat', 'tomcat_instances' ]
- name: Install catalina.properties - name: Install catalina.properties
@ -78,8 +77,7 @@
- '{{ tomcat_m_instances }}' - '{{ tomcat_m_instances }}'
- [ 'catalina.properties' ] - [ 'catalina.properties' ]
register: restart_needed register: restart_needed
notify: notify: tomcat restart instances with changed configs
- tomcat restart instances with changed configs
tags: [ 'tomcat', 'tomcat_instances', 'tomcat_catalina_properties' ] tags: [ 'tomcat', 'tomcat_instances', 'tomcat_catalina_properties' ]
- name: Populate the instances conf/policy.d directory - name: Populate the instances conf/policy.d directory
@ -88,8 +86,7 @@
- '{{ tomcat_m_instances }}' - '{{ tomcat_m_instances }}'
- [ '01system.policy', '02debian.policy', '03catalina.policy', '04webapps.policy', '50local.policy' ] - [ '01system.policy', '02debian.policy', '03catalina.policy', '04webapps.policy', '50local.policy' ]
register: restart_needed register: restart_needed
notify: notify: tomcat restart instances with changed configs
- tomcat restart instances with changed configs
tags: [ 'tomcat', 'tomcat_instances' ] tags: [ 'tomcat', 'tomcat_instances' ]
- name: Install logging.properties if we do not use log4j for the tomcat logging - name: Install logging.properties if we do not use log4j for the tomcat logging
@ -99,57 +96,51 @@
- [ 'logging.properties' ] - [ 'logging.properties' ]
when: when:
- tomcat_use_log4j is defined - tomcat_use_log4j is defined
- not tomcat_use_log4j - not tomcat_use_log4j | bool
register: restart_needed register: restart_needed
notify: notify: tomcat restart instances with changed configs
- tomcat restart instances with changed configs
tags: [ 'tomcat', 'tomcat_instances' ] tags: [ 'tomcat', 'tomcat_instances' ]
- name: Install the server.xml conf file - name: Install the server.xml conf file
template: src=tomcat-server.xml.j2 dest={{ item.instance_path }}/conf/server.xml owner={{ item.user }} group={{ item.user }} mode=0640 template: src=tomcat-server.xml.j2 dest={{ item.instance_path }}/conf/server.xml owner={{ item.user }} group={{ item.user }} mode=0640
with_items: '{{ tomcat_m_instances }}' with_items: '{{ tomcat_m_instances }}'
register: restart_needed register: restart_needed
notify: notify: tomcat restart instances with changed configs
- tomcat restart instances with changed configs
tags: [ 'tomcat', 'tomcat_instances', 'tomcat_conf', 'tomcat_serverxml' ] tags: [ 'tomcat', 'tomcat_instances', 'tomcat_conf', 'tomcat_serverxml' ]
- name: Install the web.xml file - name: Install the web.xml file
template: src=tomcat-web.xml.j2 dest={{ item.instance_path }}/conf/web.xml owner={{ item.user }} group={{ item.user }} mode=0640 template: src=tomcat-web.xml.j2 dest={{ item.instance_path }}/conf/web.xml owner={{ item.user }} group={{ item.user }} mode=0640
with_items: '{{ tomcat_m_instances }}' with_items: '{{ tomcat_m_instances }}'
register: restart_needed register: restart_needed
notify: notify: tomcat restart instances with changed configs
- tomcat restart instances with changed configs
tags: [ 'tomcat', 'tomcat_instances', 'tomcat_conf', 'tomcat_serverxml' ] tags: [ 'tomcat', 'tomcat_instances', 'tomcat_conf', 'tomcat_serverxml' ]
- name: Install the tomcat-admin package if the host-manager or manager apps are required - name: Install the tomcat-admin package if the host-manager or manager apps are required
apt: pkg=tomcat{{ tomcat_version }}-admin state={{ tomcat_pkg_state }} cache_valid_time=1800 update_cache=yes apt: pkg=tomcat{{ tomcat_version }}-admin state={{ tomcat_pkg_state }} cache_valid_time=1800 update_cache=yes
when: tomcat_m_host_manager_install or tomcat_m_manager_install when: tomcat_m_host_manager_install | bool or tomcat_m_manager_install | bool
tags: [ 'tomcat', 'tomcat_instances', 'tomcat_conf', 'tomcat_host_manager', 'tomcat_manager' ] tags: [ 'tomcat', 'tomcat_instances', 'tomcat_conf', 'tomcat_host_manager', 'tomcat_manager' ]
- name: Install the catalina configuration for the tomcat manager - name: Install the catalina configuration for the tomcat manager
template: src=tomcat-manager.xml.j2 dest={{ item.instance_path }}/conf/Catalina/localhost/manager.xml owner={{ item.user }} group={{ item.user }} mode=0640 template: src=tomcat-manager.xml.j2 dest={{ item.instance_path }}/conf/Catalina/localhost/manager.xml owner={{ item.user }} group={{ item.user }} mode=0640
with_items: '{{ tomcat_m_instances }}' with_items: '{{ tomcat_m_instances }}'
register: restart_needed register: restart_needed
when: tomcat_m_manager_install when: tomcat_m_manager_install | bool
notify: notify: tomcat restart instances with changed configs
- tomcat restart instances with changed configs
tags: [ 'tomcat', 'tomcat_instances', 'tomcat_conf', 'tomcat_manager' ] tags: [ 'tomcat', 'tomcat_instances', 'tomcat_conf', 'tomcat_manager' ]
- name: Install the catalina configuration for the tomcat host manager - name: Install the catalina configuration for the tomcat host manager
template: src=tomcat-host-manager.xml.j2 dest={{ item.instance_path }}/conf/Catalina/localhost/host-manager.xml owner={{ item.user }} group={{ item.user }} mode=0640 template: src=tomcat-host-manager.xml.j2 dest={{ item.instance_path }}/conf/Catalina/localhost/host-manager.xml owner={{ item.user }} group={{ item.user }} mode=0640
with_items: '{{ tomcat_m_instances }}' with_items: '{{ tomcat_m_instances }}'
register: restart_needed register: restart_needed
when: tomcat_m_host_manager_install when: tomcat_m_host_manager_install | bool
notify: notify: tomcat restart instances with changed configs
- tomcat restart instances with changed configs
tags: [ 'tomcat', 'tomcat_instances', 'tomcat_conf', 'tomcat_host_manager' ] tags: [ 'tomcat', 'tomcat_instances', 'tomcat_conf', 'tomcat_host_manager' ]
- name: Install the catalina configuration for the tomcat manager - name: Install the catalina configuration for the tomcat manager
template: src=tomcat-users.xml.j2 dest={{ item.instance_path }}/conf/tomcat-users.xml owner={{ item.user }} group={{ item.user }} mode=0640 template: src=tomcat-users.xml.j2 dest={{ item.instance_path }}/conf/tomcat-users.xml owner={{ item.user }} group={{ item.user }} mode=0640
with_items: '{{ tomcat_m_instances }}' with_items: '{{ tomcat_m_instances }}'
register: restart_needed register: restart_needed
notify: notify: tomcat restart instances with changed configs
- tomcat restart instances with changed configs
tags: [ 'tomcat', 'tomcat_instances', 'tomcat_conf', 'tomcat_host_manager', 'tomcat_manager' ] tags: [ 'tomcat', 'tomcat_instances', 'tomcat_conf', 'tomcat_host_manager', 'tomcat_manager' ]
- name: Install the instances startup scripts - name: Install the instances startup scripts
@ -166,15 +157,16 @@
- name: Reload the systemd daemon if we are running on a systemd-backed server - name: Reload the systemd daemon if we are running on a systemd-backed server
command: systemctl daemon-reload command: systemctl daemon-reload
when: ansible_service_mgr == 'systemd' when:
- ansible_service_mgr == 'systemd'
- reload_systemd | bool
- name: Install a custom context.xml file - name: Install a custom context.xml file
template: src=tomcat-context.xml.j2 dest={{ item.instance_path }}/conf/context.xml owner={{ item.user }} group={{ item.user }} mode=0640 template: src=tomcat-context.xml.j2 dest={{ item.instance_path }}/conf/context.xml owner={{ item.user }} group={{ item.user }} mode=0640
with_items: '{{ tomcat_m_instances }}' with_items: '{{ tomcat_m_instances }}'
register: restart_needed register: restart_needed
notify: notify: tomcat restart instances with changed configs
- tomcat restart instances with changed configs when: tomcat_m_jndi_pool | bool
when: tomcat_m_jndi_pool
tags: [ 'tomcat', 'tomcat_instances', 'tomcat_conf', 'tomcat_contextxml', 'jdk' ] tags: [ 'tomcat', 'tomcat_instances', 'tomcat_conf', 'tomcat_contextxml', 'jdk' ]
- name: Install a logrotate entry for the access log file - name: Install a logrotate entry for the access log file
@ -188,11 +180,10 @@
when: when:
- item.jmx_enabled is defined - item.jmx_enabled is defined
- item.jmx_auth_enabled is defined - item.jmx_auth_enabled is defined
- item.jmx_enabled - item.jmx_enabled | bool
- item.jmx_auth_enabled - item.jmx_auth_enabled | bool
register: jmx_restart_needed register: jmx_restart_needed
notify: notify: tomcat restart instances with changed jmx config
- tomcat restart instances with changed jmx config
tags: [ 'tomcat', 'tomcat_instances', 'tomcat_jmx' ] tags: [ 'tomcat', 'tomcat_instances', 'tomcat_jmx' ]
- name: Install the jmx role file - name: Install the jmx role file
@ -201,24 +192,23 @@
when: when:
- item.jmx_enabled is defined - item.jmx_enabled is defined
- item.jmx_auth_enabled is defined - item.jmx_auth_enabled is defined
- item.jmx_enabled - item.jmx_enabled | bool
- item.jmx_auth_enabled - item.jmx_auth_enabled | bool
register: jmx restart_needed register: jmx_restart_needed
notify: notify: tomcat restart instances with changed jmx config
- tomcat restart instances with changed jmx config
tags: [ 'tomcat', 'tomcat_instances', 'tomcat_jmx' ] tags: [ 'tomcat', 'tomcat_instances', 'tomcat_jmx' ]
- name: Start all the tomcat instances - name: Start all the tomcat instances
service: name='tomcat-instance-{{ item.http_port }}' state=started sleep=20 service: name='tomcat-instance-{{ item.http_port }}' state=started sleep=20
with_items: '{{ tomcat_m_instances }}' with_items: '{{ tomcat_m_instances }}'
when: when:
- tomcat_first_install.changed - tomcat_first_install.changed | bool
- tomcat_m_start_instances - tomcat_m_start_instances | bool
tags: [ 'tomcat', 'tomcat_instances'] tags: [ 'tomcat', 'tomcat_instances']
ignore_errors: True ignore_errors: True
- name: Enable all the tomcat instances - name: Enable all the tomcat instances
service: name='tomcat-instance-{{ item.http_port }}' enabled=yes service: name='tomcat-instance-{{ item.http_port }}' enabled=yes
with_items: '{{ tomcat_m_instances }}' with_items: '{{ tomcat_m_instances }}'
when: tomcat_m_enable_instances when: tomcat_m_enable_instances | bool
tags: [ 'tomcat', 'tomcat_instances'] tags: [ 'tomcat', 'tomcat_instances']

View File

@ -5,7 +5,7 @@
when: when:
- ansible_distribution_major_version <= '16' - ansible_distribution_major_version <= '16'
- tomcat_fixed_version is not defined - tomcat_fixed_version is not defined
tags: [ 'tomcat', 'tomcat_ver' ] tags: [ 'tomcat', 'tomcat_ver', 'tomcat_conf', 'tomcat_javamelody' ]
- name: Set the tomcat version for Ubuntu bionic - name: Set the tomcat version for Ubuntu bionic
set_fact: set_fact:
@ -13,13 +13,18 @@
when: when:
- ansible_distribution_major_version == '18' - ansible_distribution_major_version == '18'
- tomcat_fixed_version is not defined - tomcat_fixed_version is not defined
tags: [ 'tomcat', 'tomcat_ver' ] tags: [ 'tomcat', 'tomcat_ver', 'tomcat_conf', 'tomcat_javamelody' ]
- name: Impose a tomcat version - name: Impose a tomcat version
set_fact: set_fact:
tomcat_version: '{{ tomcat_fixed_version }}' tomcat_version: '{{ tomcat_fixed_version }}'
when: tomcat_fixed_version is defined when: tomcat_fixed_version is defined
tags: [ 'tomcat', 'tomcat_ver' ] tags: [ 'tomcat', 'tomcat_ver', 'tomcat_conf', 'tomcat_javamelody' ]
- name: Print the Tomcat version
debug:
msg: "The Tomcat version we are going to install is {{ tomcat_version }}"
tags: [ 'tomcat', 'tomcat_ver', 'tomcat_conf', 'tomcat_javamelody' ]
- name: Install the tomcat packages - name: Install the tomcat packages
apt: pkg={{ tomcat_pkgs }} state={{ tomcat_pkg_state }} cache_valid_time=1800 apt: pkg={{ tomcat_pkgs }} state={{ tomcat_pkg_state }} cache_valid_time=1800
@ -28,7 +33,7 @@
- name: Install additional packages needed by tomcat 8+ - name: Install additional packages needed by tomcat 8+
apt: pkg={{ tomcat8_additional_pkgs }} state={{ tomcat_pkg_state }} cache_valid_time=1800 apt: pkg={{ tomcat8_additional_pkgs }} state={{ tomcat_pkg_state }} cache_valid_time=1800
when: tomcat_version >= 8 when: tomcat_version >= 8
tags: [ 'tomcat', 'tomcat_javamelody' ] tags: [ 'tomcat', 'tomcat_javamelody', 'tomcat_conf', 'tomcat_javamelody' ]
- name: Create the tomcat tmp directory - name: Create the tomcat tmp directory
file: dest={{ tomcat_tmp_dir }} state=directory owner={{ tomcat_user }} group={{ tomcat_user }} file: dest={{ tomcat_tmp_dir }} state=directory owner={{ tomcat_user }} group={{ tomcat_user }}
@ -77,17 +82,17 @@
with_items: with_items:
- commons-daemon.jar - commons-daemon.jar
when: tomcat_version >= 8 when: tomcat_version >= 8
tags: [ 'tomcat', 'tomcat_javamelody' ] tags: [ 'tomcat', 'tomcat_conf' ]
- name: Install the javamelody dependency jar into the Java shared libs directory - name: Install the javamelody dependency jar into the Java shared libs directory
maven_artifact: artifact_id=jrobin version=latest group_id=org.jrobin extension=jar dest=/usr/share/java/jrobin.jar verify_checksum=always mode=0644 owner=root group=root repository_url=https://repo1.maven.org/maven2 maven_artifact: artifact_id=jrobin version=latest group_id=org.jrobin extension=jar dest=/usr/share/java/jrobin.jar verify_checksum=always mode=0644 owner=root group=root repository_url=https://repo1.maven.org/maven2
when: tomcat_javamelody | bool when: tomcat_javamelody | bool
tags: [ 'tomcat', 'tomcat_javamelody' ] tags: [ 'tomcat', 'tomcat_javamelody', 'tomcat_conf' ]
- name: Install the javamelody-core jar into the Java shared libs directory - name: Install the javamelody-core jar into the Java shared libs directory
maven_artifact: artifact_id=javamelody-core version={{ tomcat_javamelody_version }} group_id=net.bull.javamelody extension=jar dest=/usr/share/java/javamelody-core.jar verify_checksum=always mode=0644 owner=root group=root repository_url=https://repo1.maven.org/maven2 maven_artifact: artifact_id=javamelody-core version={{ tomcat_javamelody_version }} group_id=net.bull.javamelody extension=jar dest=/usr/share/java/javamelody-core.jar verify_checksum=always mode=0644 owner=root group=root repository_url=https://repo1.maven.org/maven2
when: tomcat_javamelody | bool when: tomcat_javamelody | bool
tags: [ 'tomcat', 'tomcat_javamelody' ] tags: [ 'tomcat', 'tomcat_javamelody', 'tomcat_conf' ]
- name: Create a link to the the javamelody jar and its dependencies if the javamelody support is enabled - name: Create a link to the the javamelody jar and its dependencies if the javamelody support is enabled
file: src=../../java/{{ item }} dest={{ tomcat_catalina_home_dir }}/lib/{{ item }} state=link owner=root group=root mode=0644 file: src=../../java/{{ item }} dest={{ tomcat_catalina_home_dir }}/lib/{{ item }} state=link owner=root group=root mode=0644
@ -95,7 +100,7 @@
- javamelody-core.jar - javamelody-core.jar
- jrobin.jar - jrobin.jar
when: tomcat_javamelody | bool when: tomcat_javamelody | bool
tags: [ 'tomcat', 'tomcat_javamelody' ] tags: [ 'tomcat', 'tomcat_javamelody', 'tomcat_conf' ]
- name: Remove the javamelody jar and its dependencies if the javamelody support is disabled - name: Remove the javamelody jar and its dependencies if the javamelody support is disabled
file: dest={{ tomcat_catalina_home_dir }}/lib/{{ item }} state=absent file: dest={{ tomcat_catalina_home_dir }}/lib/{{ item }} state=absent
@ -103,4 +108,4 @@
- javamelody-core.jar - javamelody-core.jar
- jrobin.jar - jrobin.jar
when: not tomcat_javamelody | bool when: not tomcat_javamelody | bool
tags: [ 'tomcat', 'tomcat_javamelody' ] tags: [ 'tomcat', 'tomcat_javamelody', 'tomcat_conf' ]