diff --git a/defaults/main.yml b/defaults/main.yml index 29d9c89..88f0163 100644 --- a/defaults/main.yml +++ b/defaults/main.yml @@ -1,5 +1,5 @@ --- -tomcat_version: 8 +# tomcat_version: 8 # tomcat_catalina_home_dir: '/usr/share/tomcat{{ tomcat_version }}' tomcat_m_instances_install: True diff --git a/tasks/main.yml b/tasks/main.yml index cc02aad..433e532 100644 --- a/tasks/main.yml +++ b/tasks/main.yml @@ -3,20 +3,20 @@ # Note: the library role 'tomcat' is a dependency # - name: Manage the tomcat main instance + when: not tomcat_service_enabled + tags: ['tomcat', 'tomcat_instances'] block: - - name: disable the tomcat main instance - service: + - name: Disable the tomcat main instance + ansible.builtin.service: name: 'tomcat{{ tomcat_version }}' state: stopped enabled: false - when: not tomcat_service_enabled - - tags: ['tomcat', 'tomcat_instances'] - name: Manage the tomcat user and directory tree + tags: ['tomcat', 'tomcat_instances'] block: - name: Create a tomcat user for each instance if needed - user: + ansible.builtin.user: name: '{{ item.user }}' home: '{{ item.user_home }}' createhome: false @@ -24,26 +24,26 @@ loop: '{{ tomcat_m_instances }}' when: - not tomcat_m_use_default_user | bool - - item.user != "tomcat{{ tomcat_version }}" + - item.user != tomcat_user register: tomcat_first_install - name: Create a global tomcat user if needed - user: + ansible.builtin.user: name: '{{ tomcat_m_default_user }}' home: '{{ tomcat_m_instances_base_path }}' createhome: false shell: '{{ tomcat_m_default_user_shell }}' when: - tomcat_m_use_default_user | bool - - tomcat_m_default_user != "tomcat{{ tomcat_version }}" + - tomcat_m_default_user != tomcat_user register: tomcat_first_install - name: Create the instances directory trees - file: + ansible.builtin.file: dest: '{{ item.0.instance_path }}/{{ item[1] }}' owner: '{{ item.0.user }}' group: '{{ item.0.user }}' - mode: 0755 + mode: "0755" state: directory with_nested: - '{{ tomcat_m_instances }}' @@ -51,14 +51,14 @@ register: tomcat_first_install - name: Create the tomcat logs base directory - file: + ansible.builtin.file: dest: '{{ tomcat_m_instances_logdir_base }}' state: directory - mode: 0755 + mode: "0755" tags: ['tomcat', 'tomcat_instances', 'tomcat_log_dir'] - name: Create the instances log dirs - file: + ansible.builtin.file: dest: '{{ tomcat_m_instances_logdir_base }}/{{ item.http_port }}' owner: '{{ item.user }}' group: '{{ item.user }}' @@ -70,7 +70,7 @@ tags: ['tomcat', 'tomcat_instances', 'tomcat_log_dir'] - name: Create log dirs, readable by the user that runs the http service - file: + ansible.builtin.file: dest: '{{ tomcat_m_instances_logdir_base }}/{{ item.http_port }}' owner: '{{ item.user }}' group: 'www-data' @@ -82,17 +82,17 @@ tags: ['tomcat', 'tomcat_instances', 'tomcat_log_dir'] - name: Create the instances work dirs - file: + ansible.builtin.file: dest: '{{ tomcat_m_cache_base }}/{{ item.http_port }}' owner: '{{ item.user }}' group: '{{ item.user }}' - mode: 0755 + mode: "0755" state: directory loop: '{{ tomcat_m_instances }}' register: tomcat_first_install - name: Create links to work dir inside the instances directory tree - file: + ansible.builtin.file: src: '{{ tomcat_m_cache_base }}/{{ item.http_port }}' dest: '{{ item.instance_path }}/work' state: link @@ -100,7 +100,7 @@ register: tomcat_first_install - name: Create links to log dir inside the instances directory tree - file: + ansible.builtin.file: src: '{{ tomcat_m_instances_logdir_base }}/{{ item.http_port }}' dest: '{{ item.instance_path }}/logs' state: link @@ -108,19 +108,22 @@ register: tomcat_first_install - name: Create the catalina tmp directory - file: + ansible.builtin.file: dest: '{{ item.catalina_tmp_directory }}' state: directory owner: '{{ item.user }}' group: '{{ item.user }}' - mode: 0700 + mode: "0700" loop: '{{ tomcat_m_instances }}' when: item.catalina_tmp_directory is defined - tags: ['tomcat', 'tomcat_instances'] - - 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 + ansible.builtin.copy: + src: "{{ item[1] }}" + dest: "{{ item.0.instance_path }}/conf/{{ item[1] }}" + owner: "{{ item.0.user }}" + group: "{{ item.0.user }}" + mode: "0640" with_nested: - '{{ tomcat_m_instances }}' - ['context.xml'] @@ -128,7 +131,12 @@ tags: ['tomcat', 'tomcat_instances'] - 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 + ansible.builtin.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: - '{{ tomcat_m_instances }}' - ['catalina.properties'] @@ -136,7 +144,12 @@ tags: ['tomcat', 'tomcat_instances', 'tomcat_catalina_properties'] - 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 + ansible.builtin.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: - '{{ tomcat_m_instances }}' - ['01system.policy', '02debian.policy', '03catalina.policy', '04webapps.policy', '50local.policy'] @@ -144,7 +157,12 @@ tags: ['tomcat', 'tomcat_instances'] - 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 + ansible.builtin.copy: + src: "{{ item[1] }}" + dest: "{{ item.0.instance_path }}/conf/{{ item[1] }}" + owner: "{{ item.0.user }}" + group: "{{ item.0.user }}" + mode: "0640" with_nested: - '{{ tomcat_m_instances }}' - ['logging.properties'] @@ -155,75 +173,129 @@ tags: ['tomcat', 'tomcat_instances'] - 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 - with_items: '{{ tomcat_m_instances }}' + ansible.builtin.template: + src: tomcat-server.xml.j2 + dest: "{{ item.instance_path }}/conf/server.xml" + owner: "{{ item.user }}" + group: "{{ item.user }}" + mode: "0640" + loop: '{{ tomcat_m_instances }}' notify: tomcat multiple-instances restart tags: ['tomcat', 'tomcat_instances', 'tomcat_conf', 'tomcat_serverxml'] - 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 + ansible.builtin.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 }}' notify: tomcat multiple-instances restart tags: ['tomcat', 'tomcat_instances', 'tomcat_conf', 'tomcat_serverxml'] - 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 + ansible.builtin.apt: + pkg: "tomcat{{ tomcat_version }}-admin" + state: "{{ tomcat_pkg_state }}" + cache_valid_time: 1800 when: tomcat_m_host_manager_install | bool or tomcat_m_manager_install | bool tags: ['tomcat', 'tomcat_instances', 'tomcat_conf', 'tomcat_host_manager', '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 - with_items: '{{ tomcat_m_instances }}' + ansible.builtin.template: + src: tomcat-manager.xml.j2 + dest: "{{ item.instance_path }}/conf/Catalina/localhost/manager.xml" + owner: "{{ item.user }}" + group: "{{ item.user }}" + mode: "0640" + loop: '{{ tomcat_m_instances }}' when: tomcat_m_manager_install | bool notify: tomcat multiple-instances restart tags: ['tomcat', 'tomcat_instances', 'tomcat_conf', 'tomcat_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 - with_items: '{{ tomcat_m_instances }}' + ansible.builtin.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" + loop: '{{ tomcat_m_instances }}' when: tomcat_m_host_manager_install | bool notify: tomcat multiple-instances restart tags: ['tomcat', 'tomcat_instances', 'tomcat_conf', 'tomcat_host_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 - with_items: '{{ tomcat_m_instances }}' + ansible.builtin.template: + src: tomcat-users.xml.j2 + dest: "{{ item.instance_path }}/conf/tomcat-users.xml" + owner: "{{ item.user }}" + group: "{{ item.user }}" + mode: "0640" + loop: '{{ tomcat_m_instances }}' notify: tomcat multiple-instances restart tags: ['tomcat', 'tomcat_instances', 'tomcat_conf', 'tomcat_host_manager', 'tomcat_manager'] - 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 - with_items: '{{ tomcat_m_instances }}' + ansible.builtin.template: + src: tomcat-instance.init.j2 + dest: "/etc/init.d/tomcat-instance-{{ item.http_port }}" + mode: "0755" + owner: root + group: root + loop: '{{ tomcat_m_instances }}' register: reload_systemd tags: ['tomcat', 'tomcat_instances', 'tomcat_init'] - 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 }} - with_items: '{{ tomcat_m_instances }}' + ansible.builtin.template: + src: tomcat-default.j2 + dest: "/etc/default/tomcat-instance-{{ item.http_port }}" + mode: "0640" + owner: root + group: "{{ item.user }}" + loop: '{{ tomcat_m_instances }}' notify: tomcat multiple-instances restart tags: ['tomcat', 'tomcat_instances', 'tomcat_conf', 'tomcat_default', 'jdk'] - name: Reload the systemd daemon if we are running on a systemd-backed server - command: systemctl daemon-reload + ansible.builtin.systemd: + daemon-reload: true when: - ansible_service_mgr == 'systemd' - reload_systemd | bool - 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 - with_items: '{{ tomcat_m_instances }}' + ansible.builtin.template: + src: tomcat-context.xml.j2 + dest: "{{ item.instance_path }}/conf/context.xml" + owner: "{{ item.user }}" + group: "{{ item.user }}" + mode: "0640" + loop: '{{ tomcat_m_instances }}' notify: tomcat multiple-instances restart when: tomcat_m_jndi_pool | bool tags: ['tomcat', 'tomcat_instances', 'tomcat_conf', 'tomcat_contextxml', 'jdk'] - 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 - with_items: '{{ tomcat_m_instances }}' + ansible.builtin.template: + src: tomcat.logrotate.j2 + dest: "/etc/logrotate.d/tomcat_instance-{{ item.http_port }}" + owner: root + group: root + mode: "0644" + loop: '{{ tomcat_m_instances }}' tags: ['tomcat', 'tomcat_instances', 'tomcat_conf'] - 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 - with_items: '{{ tomcat_m_instances }}' + ansible.builtin.template: + src: jmxremote.passwd.j2 + dest: "{{ item.instance_path }}/conf/jmxremote.passwd" + owner: "{{ item.user }}" + group: "{{ item.user }}" + mode: "0600" + loop: '{{ tomcat_m_instances }}' when: - item.jmx_enabled is defined - item.jmx_auth_enabled is defined @@ -233,8 +305,13 @@ tags: ['tomcat', 'tomcat_instances', 'tomcat_jmx'] - 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 - with_items: '{{ tomcat_m_instances }}' + ansible.builtin.copy: + src: jmxremote.access + dest: "{{ item.instance_path }}/conf/jmxremote.access" + owner: "{{ item.user }}" + group: "{{ item.user }}" + mode: "0644" + loop: '{{ tomcat_m_instances }}' when: - item.jmx_enabled is defined - item.jmx_auth_enabled is defined @@ -244,7 +321,7 @@ tags: ['tomcat', 'tomcat_instances', 'tomcat_jmx'] - name: Start all the tomcat instances - service: + ansible.builtin.service: name: 'tomcat-instance-{{ item.http_port }}' state: started sleep: 20 @@ -256,7 +333,7 @@ ignore_errors: true - name: Enable all the tomcat instances - service: + ansible.builtin.service: name: 'tomcat-instance-{{ item.http_port }}' enabled: true loop: '{{ tomcat_m_instances }}'