Some syntax cleanup.

This commit is contained in:
Andrea Dell'Amico 2022-07-18 19:16:23 +02:00
parent c13b556fc8
commit 93b7887f26
Signed by: adellam
GPG Key ID: 147ABE6CEB9E20FF
1 changed files with 138 additions and 91 deletions

View File

@ -2,164 +2,206 @@
# #
# Note: the library role 'tomcat' is a dependency # Note: the library role 'tomcat' is a dependency
# #
- name: disable the tomcat main instance - name: Manage the tomcat main instance
service: name='tomcat{{ tomcat_version }}' state=stopped enabled=no block:
when: not tomcat_service_enabled - name: disable the tomcat main instance
tags: [ 'tomcat', 'tomcat_instances' ] service:
name: 'tomcat{{ tomcat_version }}'
state: stopped
enabled: false
when: not tomcat_service_enabled
- name: Create a tomcat user for each instance if needed tags: ['tomcat', 'tomcat_instances']
user: name={{ item.user }} home={{ item.user_home }} createhome=false shell={{ item.user_shell | default('/bin/false') }}
with_items: '{{ tomcat_m_instances }}'
when:
- not tomcat_m_use_default_user | bool
- item.user != "tomcat{{ tomcat_version }}"
register: tomcat_first_install
tags: [ 'tomcat', 'tomcat_instances' ]
- name: Create a tomcat user if needed - name: Manage the tomcat user and directory tree
user: name={{ tomcat_m_default_user }} home={{ tomcat_m_instances_base_path }} createhome=false shell={{ tomcat_m_default_user_shell }} block:
when: - name: Create a tomcat user for each instance if needed
- tomcat_m_use_default_user | bool user:
- tomcat_m_default_user != "tomcat{{ tomcat_version }}" name: '{{ item.user }}'
register: tomcat_first_install home: '{{ item.user_home }}'
tags: [ 'tomcat', 'tomcat_instances' ] createhome: false
shell: "{{ item.user_shell | default('/bin/false') }}"
loop: '{{ tomcat_m_instances }}'
when:
- not tomcat_m_use_default_user | bool
- item.user != "tomcat{{ tomcat_version }}"
register: tomcat_first_install
- name: Create the instances directory trees - name: Create a global tomcat user if needed
file: dest={{ item.0.instance_path }}/{{ item[1] }} owner={{ item.0.user }} group={{ item.0.user }} mode=0755 state=directory user:
with_nested: name: '{{ tomcat_m_default_user }}'
- '{{ tomcat_m_instances }}' home: '{{ tomcat_m_instances_base_path }}'
- [ 'common/classes', 'conf/Catalina/localhost', 'conf/policy.d', 'lib', 'server/classes', 'shared/classes', 'webapps' ] createhome: false
register: tomcat_first_install shell: '{{ tomcat_m_default_user_shell }}'
tags: [ 'tomcat', 'tomcat_instances' ] when:
- tomcat_m_use_default_user | bool
- tomcat_m_default_user != "tomcat{{ tomcat_version }}"
register: tomcat_first_install
- name: Create the tomcat logs base directory - name: Create the instances directory trees
file: file:
dest: '{{ tomcat_m_instances_logdir_base }}' dest: '{{ item.0.instance_path }}/{{ item[1] }}'
state: directory owner: '{{ item.0.user }}'
mode: 0755 group: '{{ item.0.user }}'
tags: [ 'tomcat', 'tomcat_instances', 'tomcat_log_dir' ] mode: 0755
state: directory
with_nested:
- '{{ tomcat_m_instances }}'
- ['common/classes', 'conf/Catalina/localhost', 'conf/policy.d', 'lib', 'server/classes', 'shared/classes', 'webapps']
register: tomcat_first_install
- name: Create the instances log dirs - name: Create the tomcat logs base directory
file: dest={{ tomcat_m_instances_logdir_base }}/{{ item.http_port }} owner={{ item.user }} group={{ item.user }} mode='0750' state=directory file:
with_items: '{{ tomcat_m_instances }}' dest: '{{ tomcat_m_instances_logdir_base }}'
register: tomcat_first_install state: directory
when: not tomcat_m_expose_log_directory mode: 0755
tags: [ 'tomcat', 'tomcat_instances', 'tomcat_log_dir' ] tags: ['tomcat', 'tomcat_instances', 'tomcat_log_dir']
- name: Create log dirs, readable by the user that runs the http service - name: Create the instances log dirs
file: dest={{ tomcat_m_instances_logdir_base }}/{{ item.http_port }} owner={{ item.user }} group='www-data' mode='0750' state=directory file:
with_items: '{{ tomcat_m_instances }}' dest: '{{ tomcat_m_instances_logdir_base }}/{{ item.http_port }}'
register: tomcat_first_install owner: '{{ item.user }}'
when: tomcat_m_expose_log_directory group: '{{ item.user }}'
tags: [ 'tomcat', 'tomcat_instances', 'tomcat_log_dir' ] mode: '0750'
state: directory
loop: '{{ tomcat_m_instances }}'
register: tomcat_first_install
when: not tomcat_m_expose_log_directory
tags: ['tomcat', 'tomcat_instances', 'tomcat_log_dir']
- name: Create the instances work dirs - name: Create log dirs, readable by the user that runs the http service
file: dest={{ tomcat_m_cache_base }}/{{ item.http_port }} owner={{ item.user }} group={{ item.user }} mode=0755 state=directory file:
with_items: '{{ tomcat_m_instances }}' dest: '{{ tomcat_m_instances_logdir_base }}/{{ item.http_port }}'
register: tomcat_first_install owner: '{{ item.user }}'
tags: [ 'tomcat', 'tomcat_instances' ] group: 'www-data'
mode: '0750'
state: directory
loop: '{{ tomcat_m_instances }}'
register: tomcat_first_install
when: tomcat_m_expose_log_directory
tags: ['tomcat', 'tomcat_instances', 'tomcat_log_dir']
- name: Create links to work dir inside the instances directory tree - name: Create the instances work dirs
file: src={{ tomcat_m_cache_base }}/{{ item.http_port }} dest={{ item.instance_path }}/work state=link file:
with_items: '{{ tomcat_m_instances }}' dest: '{{ tomcat_m_cache_base }}/{{ item.http_port }}'
register: tomcat_first_install owner: '{{ item.user }}'
tags: [ 'tomcat', 'tomcat_instances' ] group: '{{ item.user }}'
mode: 0755
state: directory
loop: '{{ tomcat_m_instances }}'
register: tomcat_first_install
- name: Create links to log dir inside the instances directory tree - name: Create links to work dir inside the instances directory tree
file: src={{ tomcat_m_instances_logdir_base }}/{{ item.http_port }} dest={{ item.instance_path }}/logs state=link file:
with_items: '{{ tomcat_m_instances }}' src: '{{ tomcat_m_cache_base }}/{{ item.http_port }}'
register: tomcat_first_install dest: '{{ item.instance_path }}/work'
tags: [ 'tomcat', 'tomcat_instances' ] state: link
loop: '{{ tomcat_m_instances }}'
register: tomcat_first_install
- name: Create the catalina tmp directory - name: Create links to log dir inside the instances directory tree
file: dest={{ item.catalina_tmp_directory }} state=directory owner={{ item.user }} group={{ item.user }} mode=0700 file:
with_items: '{{ tomcat_m_instances }}' src: '{{ tomcat_m_instances_logdir_base }}/{{ item.http_port }}'
when: item.catalina_tmp_directory is defined dest: '{{ item.instance_path }}/logs'
tags: [ 'tomcat', 'tomcat_instances' ] state: link
loop: '{{ tomcat_m_instances }}'
register: tomcat_first_install
- name: Create the catalina tmp directory
file:
dest: '{{ item.catalina_tmp_directory }}'
state: directory
owner: '{{ item.user }}'
group: '{{ item.user }}'
mode: 0700
loop: '{{ tomcat_m_instances }}'
when: item.catalina_tmp_directory is defined
tags: ['tomcat', 'tomcat_instances']
- name: Populate the instances conf directory - name: Populate the instances conf directory
copy: src={{ item[1] }} dest={{ item.0.instance_path }}/conf/{{ item[1] }} owner={{ item.0.user }} group={{ item.0.user }} mode=0640 copy: src={{ item[1] }} dest={{ item.0.instance_path }}/conf/{{ item[1] }} owner={{ item.0.user }} group={{ item.0.user }} mode=0640
with_nested: with_nested:
- '{{ tomcat_m_instances }}' - '{{ tomcat_m_instances }}'
- [ 'context.xml' ] - ['context.xml']
notify: tomcat multiple-instances restart notify: tomcat multiple-instances restart
tags: [ 'tomcat', 'tomcat_instances' ] tags: ['tomcat', 'tomcat_instances']
- name: Install catalina.properties - name: Install catalina.properties
template: src={{ item[1] }}.j2 dest={{ item.0.instance_path }}/conf/{{ item[1] }} owner={{ item.0.user }} group={{ item.0.user }} mode=0640 template: src={{ item[1] }}.j2 dest={{ item.0.instance_path }}/conf/{{ item[1] }} owner={{ item.0.user }} group={{ item.0.user }} mode=0640
with_nested: with_nested:
- '{{ tomcat_m_instances }}' - '{{ tomcat_m_instances }}'
- [ 'catalina.properties' ] - ['catalina.properties']
notify: tomcat multiple-instances restart notify: tomcat multiple-instances restart
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
copy: src=policy.d/{{ item[1] }} dest={{ item.0.instance_path }}/conf/policy.d/{{ item[1] }} owner={{ item.0.user }} group={{ item.0.user }} mode=0640 copy: src=policy.d/{{ item[1] }} dest={{ item.0.instance_path }}/conf/policy.d/{{ item[1] }} owner={{ item.0.user }} group={{ item.0.user }} mode=0640
with_nested: with_nested:
- '{{ 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']
notify: tomcat multiple-instances restart notify: tomcat multiple-instances restart
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
copy: src={{ item[1] }} dest={{ item.0.instance_path }}/conf/{{ item[1] }} owner={{ item.0.user }} group={{ item.0.user }} mode=0640 copy: src={{ item[1] }} dest={{ item.0.instance_path }}/conf/{{ item[1] }} owner={{ item.0.user }} group={{ item.0.user }} mode=0640
with_nested: with_nested:
- '{{ tomcat_m_instances }}' - '{{ tomcat_m_instances }}'
- [ 'logging.properties' ] - ['logging.properties']
when: when:
- tomcat_use_log4j is defined - tomcat_use_log4j is defined
- not tomcat_use_log4j | bool - not tomcat_use_log4j | bool
notify: tomcat multiple-instances restart notify: tomcat multiple-instances restart
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 }}'
notify: tomcat multiple-instances restart notify: tomcat multiple-instances restart
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 }}'
notify: tomcat multiple-instances restart notify: tomcat multiple-instances restart
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 | bool or tomcat_m_manager_install | bool 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 }}'
when: tomcat_m_manager_install | bool when: tomcat_m_manager_install | bool
notify: tomcat multiple-instances restart notify: tomcat multiple-instances restart
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 }}'
when: tomcat_m_host_manager_install | bool when: tomcat_m_host_manager_install | bool
notify: tomcat multiple-instances restart notify: tomcat multiple-instances restart
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 }}'
notify: tomcat multiple-instances restart notify: tomcat multiple-instances restart
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
template: src=tomcat-instance.init.j2 dest=/etc/init.d/tomcat-instance-{{ item.http_port }} mode=0755 owner=root group=root template: src=tomcat-instance.init.j2 dest=/etc/init.d/tomcat-instance-{{ item.http_port }} mode=0755 owner=root group=root
with_items: '{{ tomcat_m_instances }}' with_items: '{{ tomcat_m_instances }}'
register: reload_systemd register: reload_systemd
tags: [ 'tomcat', 'tomcat_instances', 'tomcat_init' ] tags: ['tomcat', 'tomcat_instances', 'tomcat_init']
- name: Install the tomcat instances default file - name: Install the tomcat instances default file
template: src=tomcat-default.j2 dest=/etc/default/tomcat-instance-{{ item.http_port }} mode=0640 owner=root group={{ item.user }} template: src=tomcat-default.j2 dest=/etc/default/tomcat-instance-{{ item.http_port }} mode=0640 owner=root group={{ item.user }}
with_items: '{{ tomcat_m_instances }}' with_items: '{{ tomcat_m_instances }}'
notify: tomcat multiple-instances restart notify: tomcat multiple-instances restart
tags: [ 'tomcat', 'tomcat_instances', 'tomcat_conf', 'tomcat_default', 'jdk' ] tags: ['tomcat', 'tomcat_instances', 'tomcat_conf', 'tomcat_default', 'jdk']
- 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
@ -172,12 +214,12 @@
with_items: '{{ tomcat_m_instances }}' with_items: '{{ tomcat_m_instances }}'
notify: tomcat multiple-instances restart notify: tomcat multiple-instances restart
when: tomcat_m_jndi_pool | bool when: tomcat_m_jndi_pool | bool
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
template: src=tomcat.logrotate.j2 dest=/etc/logrotate.d/tomcat_instance-{{ item.http_port }} owner=root group=root mode=0644 template: src=tomcat.logrotate.j2 dest=/etc/logrotate.d/tomcat_instance-{{ item.http_port }} owner=root group=root mode=0644
with_items: '{{ tomcat_m_instances }}' with_items: '{{ tomcat_m_instances }}'
tags: [ 'tomcat', 'tomcat_instances', 'tomcat_conf' ] tags: ['tomcat', 'tomcat_instances', 'tomcat_conf']
- name: Install the jmx authorization file - name: Install the jmx authorization file
template: src=jmxremote.passwd.j2 dest={{ item.instance_path }}/conf/jmxremote.passwd owner={{ item.user }} group={{ item.user }} mode=0600 template: src=jmxremote.passwd.j2 dest={{ item.instance_path }}/conf/jmxremote.passwd owner={{ item.user }} group={{ item.user }} mode=0600
@ -188,7 +230,7 @@
- item.jmx_enabled | bool - item.jmx_enabled | bool
- item.jmx_auth_enabled | bool - item.jmx_auth_enabled | bool
notify: tomcat multiple-instances restart notify: tomcat multiple-instances restart
tags: [ 'tomcat', 'tomcat_instances', 'tomcat_jmx' ] tags: ['tomcat', 'tomcat_instances', 'tomcat_jmx']
- name: Install the jmx role file - name: Install the jmx role file
copy: src=jmxremote.access dest={{ item.instance_path }}/conf/jmxremote.access owner={{ item.user }} group={{ item.user }} mode=0644 copy: src=jmxremote.access dest={{ item.instance_path }}/conf/jmxremote.access owner={{ item.user }} group={{ item.user }} mode=0644
@ -199,19 +241,24 @@
- item.jmx_enabled | bool - item.jmx_enabled | bool
- item.jmx_auth_enabled | bool - item.jmx_auth_enabled | bool
notify: tomcat multiple-instances restart notify: tomcat multiple-instances restart
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:
with_items: '{{ tomcat_m_instances }}' name: 'tomcat-instance-{{ item.http_port }}'
state: started
sleep: 20
loop: '{{ tomcat_m_instances }}'
when: when:
- tomcat_first_install.changed | bool - tomcat_first_install.changed | bool
- tomcat_m_start_instances | bool - 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:
with_items: '{{ tomcat_m_instances }}' name: 'tomcat-instance-{{ item.http_port }}'
enabled: true
loop: '{{ tomcat_m_instances }}'
when: tomcat_m_enable_instances | bool when: tomcat_m_enable_instances | bool
tags: [ 'tomcat', 'tomcat_instances'] tags: ['tomcat', 'tomcat_instances']