Skip to content

Commit 8db84d1

Browse files
authored
Merge pull request #14 from rhythmictech/rpm
Add support for installing from package manager
2 parents d3d7faa + c4a4f9d commit 8db84d1

File tree

8 files changed

+141
-63
lines changed

8 files changed

+141
-63
lines changed

defaults/main.yml

Lines changed: 5 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,8 @@
44
# General Variables
55
########################################
66

7-
### THIS MUST BE SET!
8-
9-
########################################
10-
# Version/URLs
11-
########################################
12-
13-
tomcat_major_version: 9
14-
tomcat_version: 9.0.33
15-
tomcat_mirror: "https://archive.apache.org/dist"
16-
tomcat_download_url: "{{ tomcat_mirror }}/tomcat/tomcat-{{ tomcat_major_version }}/v{{ tomcat_version }}/bin/apache-tomcat-{{ tomcat_version }}.tar.gz"
17-
tomcat_checksum_url: "https://downloads.apache.org/tomcat/tomcat-{{ tomcat_major_version }}/v{{ tomcat_version }}/bin/apache-tomcat-{{ tomcat_version }}.tar.gz.sha512"
7+
tomcat_install_from_repo: false
8+
tomcat_packages: []
189

1910
########################################
2011
# Security Variables
@@ -28,25 +19,12 @@ tomcat_umask: '0022'
2819
# This will be randomly generated every ansible run if not set
2920
tomcat_shutdown_value: 'SETME'
3021

31-
########################################
32-
# Path/FS Variables
33-
########################################
34-
35-
tomcat_catalina_base_install_dir: "/opt"
36-
tomcat_catalina_base: "{{ tomcat_catalina_base_install_dir }}/tomcat"
37-
tomcat_catalina_home_install_dir: "/usr/local"
38-
tomcat_catalina_home: "{{ tomcat_catalina_home_install_dir }}/tomcat"
39-
tomcat_working_dir: "/home/{{ tomcat_user }}"
40-
# This is only compatible with JDK 8 and older
41-
tomcat_java_endorsed_dirs: []
42-
43-
4422
########################################
4523
# Java Variables
4624
########################################
4725

4826
# Set to false if you will separately install a JDK. JDK must be installed before Tomcat runs.
49-
tomcat_install_jdk: true
27+
tomcat_install_jdk: false
5028
tomcat_install_jdk_version: "11"
5129

5230
tomcat_extra_java_opts: ''
@@ -94,3 +72,5 @@ tomcat_local_mapping: {}
9472
tomcat_rewrite_rules: []
9573

9674
tomcat_start_service: false
75+
76+
tomcat_shutdown_wait: 20

tasks/install.yml

Lines changed: 2 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -72,30 +72,12 @@
7272
- RUNNING.txt
7373
tags: ['tomcat']
7474

75-
- name: check if tomcat conf dir has been copied before
76-
stat: path={{ tomcat_catalina_home }}/conf.dist
77-
register: tomcat_conf_dist_found
78-
tags: ['tomcat']
79-
8075
- name: rename conf dir
8176
command:
8277
mv {{ tomcat_catalina_home }}/conf {{ tomcat_catalina_home }}/conf.dist
8378
when: tomcat_conf_dist_found.stat.exists == false
8479
tags: ['tomcat']
8580

86-
- name: give tomcat group access to read all in CATALINA_HOME
87-
command: "find {{ tomcat_catalina_home }}/ -exec /bin/chgrp {{ tomcat_group }} {} \\;"
88-
when: tomcat_conf_dist_found.stat.exists == false
89-
tags: ['tomcat']
90-
91-
- name: restrict access to CATALINA_HOME
92-
file: path="{{ tomcat_catalina_home }}" state=directory owner="root" group="{{ tomcat_group }}" mode='0750'
93-
tags: ['tomcat']
94-
95-
- name: ensure logs directory exists in CATALINA_HOME
96-
file: path="{{ tomcat_catalina_home }}/logs" state=directory owner="{{ tomcat_user }}" group="{{ tomcat_group }}" mode='0750'
97-
tags: ['tomcat']
98-
9981
- name: ensure /etc/init.d/tomcat exists
10082
template:
10183
src: etc.init.d.tomcat.j2
@@ -128,10 +110,7 @@
128110
tags: ['tomcat']
129111

130112
- name: reload systemd
131-
shell: '/bin/systemctl daemon-reload'
113+
systemd_service:
114+
daemon_reload: true
132115
when: tomcat_unit_file.changed | default(False)
133116
tags: ['tomcat']
134-
135-
- name: ensure tomcat is enabled
136-
service: name=tomcat enabled=yes
137-
tags: ['tomcat']

tasks/install_repo.yml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
---
2+
3+
- name: Install tomcat from rpm
4+
package:
5+
name: "{{ tomcat_packages }}"
6+
state: present
7+
tags: ['tomcat']

tasks/main.yml

Lines changed: 56 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,40 @@
11
---
2-
- name: ensure tomcat is installed
3-
include: install.yml
2+
- name: include variables relevant to install type ( binary )
3+
include_vars: binary_install.yml
4+
when: not tomcat_install_from_repo
45
tags: ['tomcat']
56

7+
- name: include variables relevant to install type ( rpm )
8+
include_vars: package_install.yml
9+
when: tomcat_install_from_repo
10+
tags: ['tomcat']
11+
12+
- name: ensure tomcat is installed (binary)
13+
include_tasks: install.yml
14+
when: not tomcat_install_from_repo
15+
tags: ['tomcat']
16+
17+
- name: ensure tomcat is installed (rpm)
18+
include_tasks: install_repo.yml
19+
when: tomcat_install_from_repo
20+
621
- set_fact:
722
tomcat_shutdown_value: "{{ lookup('password', '/dev/null length=20 chars=ascii_letters') }}"
823
when: tomcat_shutdown_value == "SETME"
924
tags: ['tomcat']
1025

26+
- name: give tomcat group access to read all in CATALINA_HOME
27+
command: "find {{ tomcat_catalina_home }}/ -exec /bin/chgrp {{ tomcat_group }} {} \\;"
28+
tags: ['tomcat']
29+
30+
- name: restrict access to CATALINA_HOME
31+
file: path="{{ tomcat_catalina_home }}" state=directory owner="root" group="{{ tomcat_group }}" mode='0750'
32+
tags: ['tomcat']
33+
34+
- name: ensure logs directory exists in CATALINA_HOME
35+
file: path="{{ tomcat_catalina_home }}/logs" state=directory owner="{{ tomcat_user }}" group="{{ tomcat_group }}" mode='0750'
36+
tags: ['tomcat']
37+
1138
- name: create CATALINA_BASE dirs
1239
file: path="{{ item }}" state=directory owner="{{ tomcat_user }}" group="{{ tomcat_group }}" mode='0751'
1340
with_items:
@@ -87,15 +114,6 @@
87114
when: tomcat_enable_manager
88115
tags: ['tomcat']
89116

90-
- name: ensure tomcat setenv.sh exists
91-
template:
92-
src: catalina_base.bin.setenv.sh.j2
93-
dest: "{{ tomcat_catalina_base }}/bin/setenv.sh"
94-
owner: "{{ tomcat_user }}"
95-
group: "{{ tomcat_group }}"
96-
mode: 0600
97-
tags: ['tomcat']
98-
99117
- name: ensure tomcat-users.xml exists
100118
template:
101119
src: catalina_base.conf.tomcat-users.xml.j2
@@ -174,7 +192,33 @@
174192
template: src=etc.logrotate.tomcat.j2 dest=/etc/logrotate.d/tomcat owner=root group=root mode=0644
175193
tags: ['tomcat', 'logrotate']
176194

195+
# binary only tasks
196+
- name: ensure tomcat setenv.sh exists
197+
template:
198+
src: catalina_base.bin.setenv.sh.j2
199+
dest: "{{ tomcat_catalina_base }}/bin/setenv.sh"
200+
owner: "{{ tomcat_user }}"
201+
group: "{{ tomcat_group }}"
202+
mode: 0600
203+
when: not tomcat_install_from_repo
204+
tags: ['tomcat']
205+
206+
# rpm only tasks
207+
208+
- name: ensure tomcat env var file exists
209+
template:
210+
src: etc.sysconfig.tomcat.j2
211+
dest: "/etc/sysconfig/{{ tomcat_service }}"
212+
owner: "{{ tomcat_user }}"
213+
group: "{{ tomcat_group }}"
214+
mode: 0600
215+
when: tomcat_install_from_repo
216+
tags: ['tomcat']
217+
177218
- name: ensure tomcat is started
178-
service: name=tomcat state=started
219+
service:
220+
name: "{{ tomcat_service }}"
221+
enabled: true
222+
state: started
179223
when: tomcat_start_service
180224
tags: ['tomcat']

templates/etc.sudoers.d.tomcat.j2

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
{{ tomcat_user }} ALL=(ALL) NOPASSWD: /sbin/service tomcat *, /bin/systemctl stop tomcat, /bin/systemctl start tomcat
1+
{{ tomcat_user }} ALL=(ALL) NOPASSWD: /sbin/service {{ tomcat_service }} *, /bin/systemctl stop {{ tomcat_service }}, /bin/systemctl start {{ tomcat_service }}

templates/etc.sysconfig.tomcat.j2

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,22 @@ CATALINA_BASE={{ tomcat_catalina_base }}
99
#TOMCAT_USER is the default user of tomcat
1010
TOMCAT_USER={{ tomcat_user }}
1111

12-
#SHUTDOWN_WAIT is wait time in seconds for java proccess to stop
13-
SHUTDOWN_WAIT=60
12+
{% for sysenvvar in tomcat_system_envvars|default([]) %}
13+
{{ sysenvvar.name }}="{{ sysenvvar.value }}"
14+
export {{ sysenvvar.name }}
15+
{% endfor %}
16+
17+
{% if tomcat_java_endorsed_dirs|length > 0 %}
18+
JAVA_ENDORSED_DIRS={{ tomcat_java_endorsed_dirs|join(':') }}
19+
export JAVA_ENDORSED_DIRS
20+
{% endif %}
21+
22+
23+
CATALINA_OPTS="-Xmx{{ tomcat_max_heap }} -XX:-DisableExplicitGC -Djava.awt.headless=true -Dcom.sun.management.jmxremote -Dcom.sun.management.jmxremote.port=8090 -Dcom.sun.management.jmxremote.authenticate=false -Dcom.sun.management.jmxremote.ssl=false -Dsun.security.ssl.allowUnsafeRenegotiation=true {{ tomcat_extra_java_opts }}
24+
{%- for envvar in tomcat_envvars|default([]) %}
25+
-D{{ envvar.name }}={{ envvar.value }}
26+
{%- endfor %}"
27+
28+
#SHUTDOWN_WAIT is wait time in seconds for java process to stop
29+
SHUTDOWN_WAIT={{ tomcat_shutdown_wait }}
1430

vars/binary_install.yml

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
---
2+
########################################
3+
# Version/URLs
4+
########################################
5+
6+
tomcat_major_version: 9
7+
tomcat_version: 9.0.33
8+
tomcat_mirror: "https://archive.apache.org/dist"
9+
tomcat_download_url: "{{ tomcat_mirror }}/tomcat/tomcat-{{ tomcat_major_version }}/v{{ tomcat_version }}/bin/apache-tomcat-{{ tomcat_version }}.tar.gz"
10+
tomcat_checksum_url: "https://downloads.apache.org/tomcat/tomcat-{{ tomcat_major_version }}/v{{ tomcat_version }}/bin/apache-tomcat-{{ tomcat_version }}.tar.gz.sha512"
11+
tomcat_service: tomcat
12+
13+
########################################
14+
# Path/FS Variables
15+
########################################
16+
17+
tomcat_catalina_base_install_dir: "/opt"
18+
tomcat_catalina_base: "{{ tomcat_catalina_base_install_dir }}/tomcat"
19+
tomcat_catalina_home_install_dir: "/usr/local"
20+
tomcat_catalina_home: "{{ tomcat_catalina_home_install_dir }}/tomcat"
21+
tomcat_working_dir: "/home/{{ tomcat_user }}"
22+
# This is only compatible with JDK 8 and older
23+
tomcat_java_endorsed_dirs: []
24+

vars/package_install.yml

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
---
2+
########################################
3+
# Version/URLs
4+
########################################
5+
6+
tomcat_major_version: 9
7+
tomcat_packages:
8+
- tomcat9
9+
10+
# not used
11+
tomcat_version:
12+
tomcat_mirror:
13+
tomcat_download_url:
14+
tomcat_checksum_url:
15+
tomcat_service: tomcat9
16+
17+
########################################
18+
# Path/FS Variables
19+
########################################
20+
21+
tomcat_catalina_base_install_dir: "/usr/share"
22+
tomcat_catalina_base: "{{ tomcat_catalina_base_install_dir }}/tomcat9"
23+
tomcat_catalina_home_install_dir: "/usr/share"
24+
tomcat_catalina_home: "{{ tomcat_catalina_home_install_dir }}/tomcat9"
25+
tomcat_working_dir: "/home/{{ tomcat_user }}"
26+
# This is only compatible with JDK 8 and older
27+
tomcat_java_endorsed_dirs: []
28+

0 commit comments

Comments
 (0)