ansible-role-tomcat/tasks/tomcat-pkgs.yml

174 lines
5.6 KiB
YAML

---
- name: tomcat-pkgs | Set the tomcat version for ubuntu Trusy
ansible.builtin.set_fact:
tomcat_version: 7
when:
- ansible_distribution_version is version_compare('16.04', '<')
- tomcat_fixed_version is not defined
tags: ['tomcat', 'tomcat_ver', 'tomcat_conf', 'tomcat_javamelody', 'tomcat_init']
- name: tomcat-pkgs | Set the tomcat version for Ubuntu bionic
ansible.builtin.set_fact:
tomcat_version: 8
when:
- ansible_distribution_version is version_compare('18.04', '==')
- tomcat_fixed_version is not defined
tags: ['tomcat', 'tomcat_ver', 'tomcat_conf', 'tomcat_javamelody', 'tomcat_init']
- name: tomcat-pkgs | Set the tomcat version for Ubuntu 24.04
ansible.builtin.set_fact:
tomcat_version: 10
when:
- ansible_distribution_version is version_compare('24.04', '==')
- tomcat_fixed_version is not defined
tags: ['tomcat', 'tomcat_ver', 'tomcat_conf', 'tomcat_javamelody', 'tomcat_init']
- name: tomcat-pkgs | Impose a tomcat version
ansible.builtin.set_fact:
tomcat_version: '{{ tomcat_fixed_version }}'
when: tomcat_fixed_version is defined
tags: ['tomcat', 'tomcat_ver', 'tomcat_conf', 'tomcat_javamelody', 'tomcat_init']
- name: tomcat-pkgs | Print the Tomcat version
ansible.builtin.debug:
msg: "The Tomcat version we are going to install is {{ tomcat_version }}"
tags: ['tomcat', 'tomcat_ver', 'tomcat_conf', 'tomcat_javamelody']
- name: tomcat-pkgs | Install the tomcat packages
ansible.builtin.apt:
pkg: "{{ tomcat_pkgs }}"
state: "{{ tomcat_pkg_state }}"
cache_valid_time: 1800
tags: tomcat
- name: tomcat-pkgs | Install additional packages needed by tomcat 8+
ansible.builtin.apt:
pkg: "{{ tomcat8_additional_pkgs }}"
state: "{{ tomcat_pkg_state }}"
cache_valid_time: 1800
when: tomcat_version is version_compare('8', '>=')
tags: ['tomcat', 'tomcat_javamelody', 'tomcat_conf', 'tomcat_javamelody']
- name: tomcat-pkgs | Create the tomcat tmp directory
ansible.builtin.file:
dest: "{{ tomcat_tmp_dir }}"
state: directory
owner: "{{ tomcat_user }}"
group: "{{ tomcat_user }}"
mode: "0750"
notify: tomcat restart
tags: tomcat
- name: tomcat-pkgs | Create the catalina temp directory, if different from the default
ansible.builtin.file:
dest: "{{ catalina_tmp_directory }}"
state: directory
owner: "{{ tomcat_user }}"
group: "{{ tomcat_user }}"
mode: "0750"
when: catalina_tmp_directory is defined
notify: tomcat restart
tags: tomcat
- name: tomcat-pkgs | Configure tomcat defaults
ansible.builtin.template:
src: tomcat-default.j2
dest: "/etc/default/tomcat{{ tomcat_version }}"
owner: root
group: "{{ tomcat_user }}"
mode: "0640"
when: tomcat_install_default_conf | bool
notify: tomcat restart
tags: ['tomcat', 'tomcat_default', 'tomcat_conf']
- name: tomcat-pkgs | Configure tomcat server.xml
ansible.builtin.template:
src: tomcat-server.xml.j2
dest: "{{ tomcat_conf_dir }}/server.xml"
owner: root
group: "{{ tomcat_user }}"
mode: "0640"
when: tomcat_install_server_xml | bool
notify: tomcat restart
tags: ['tomcat', 'tomcat_serverxml', 'tomcat_conf']
- name: tomcat-pkgs | Configure tomcat web.xml
ansible.builtin.template:
src: tomcat-web.xml.j2
dest: "{{ tomcat_conf_dir }}/web.xml"
owner: root
group: "{{ tomcat_user }}"
mode: "0640"
notify: tomcat restart
tags: ['tomcat', 'tomcat_serverxml', 'tomcat_conf']
- name: tomcat-pkgs | Install the startup script used by the systemd unit
ansible.builtin.template:
src: tomcat-start.sh.j2
dest: "/usr/libexec/tomcat{{ tomcat_version }}/tomcat-start.sh"
owner: root
group: root
mode: "0755"
notify: tomcat restart
register: reload_systemd
when:
- tomcat_use_systemd_unit
- ansible_distribution_version is version_compare('24.04', '<')
tags: ['tomcat', 'tomcat_serverxml', 'tomcat_conf', 'tomcat_init']
- name: tomcat-pkgs | Reload the systemd daemon if we are running on a systemd-backed server
ansible.builtin.systemd:
daemon-reload: true
when: reload_systemd
tags: ['tomcat', 'tomcat_instances', 'tomcat_init']
- name: tomcat-pkgs | Install the systemd unit
ansible.builtin.template:
src: tomcat-service.j2
dest: "/usr/lib/systemd/system/tomcat{{ tomcat_version }}.service"
owner: root
group: root
mode: "0644"
notify: tomcat restart
when:
- tomcat_use_systemd_unit
- ansible_distribution_version is version_compare('24.04', '<')
tags: ['tomcat', 'tomcat_serverxml', 'tomcat_conf']
- name: tomcat-pkgs | Install a slightly modified catalina.properties
ansible.builtin.template:
src: catalina.properties.j2
dest: "{{ tomcat_conf_dir }}/catalina.properties"
owner: root
group: "{{ tomcat_user }}"
mode: "0644"
when: tomcat_install_default_conf | bool
notify: tomcat restart
tags: ['tomcat', 'tomcat_catalinaprops']
- name: tomcat-pkgs | Create some directories that the package do not creates itself
ansible.builtin.file:
dest: "{{ tomcat_catalina_home_dir }}/{{ item }}"
state: directory
owner: "{{ tomcat_user }}"
group: "{{ tomcat_user }}"
mode: "0755"
with_items:
- common/classes
- server/classes
- shared/classes
tags: tomcat
- name: tomcat-pkgs | On tomcat8, create a link to commons-daemon.jar to avoid exceptions at startup
ansible.builtin.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 is version_compare('8', '>=')
tags: ['tomcat', 'tomcat_conf']