Skip to content

Commit 20ef88b

Browse files
committed
Fix binary installs
1 parent e8b4dbf commit 20ef88b

13 files changed

+90
-119
lines changed

defaults/main.yml

Lines changed: 26 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,24 @@
33
########################################
44
# General Variables
55
########################################
6-
76
tomcat_install_from_repo: false
8-
tomcat_packages: []
7+
tomcat_major_version: 9
8+
9+
# Used with binary installs
10+
tomcat_version: 9.0.33
11+
12+
tomcat_catalina_base: "/opt/tomcat"
13+
tomcat_catalina_home: "{{ tomcat_catalina_home_install_dir }}/tomcat"
14+
tomcat_catalina_home_install_dir: "/usr/local"
15+
tomcat_working_dir: "/home/{{ tomcat_user }}"
16+
17+
tomcat_mirror: "https://archive.apache.org/dist"
18+
tomcat_download_url: "{{ tomcat_mirror }}/tomcat/tomcat-{{ tomcat_major_version }}/v{{ tomcat_version }}/bin/apache-tomcat-{{ tomcat_version }}.tar.gz"
19+
tomcat_checksum_url: "https://downloads.apache.org/tomcat/tomcat-{{ tomcat_major_version }}/v{{ tomcat_version }}/bin/apache-tomcat-{{ tomcat_version }}.tar.gz.sha512"
20+
21+
# Used with RPM installs
22+
tomcat_packages:
23+
- "tomcat{{ tomcat_major_version }}"
924

1025
########################################
1126
# Security Variables
@@ -51,28 +66,21 @@ tomcat_ajp_connector_options: ""
5166
########################################
5267
# Tomcat Variables
5368
########################################
54-
55-
tomcat_contexts: []
56-
5769
tomcat_allow_root_symlinks: false
58-
59-
tomcat_global_context:
60-
jdbc_resources: []
61-
62-
tomcat_preserve_proxy_info: True
63-
64-
tomcat_extra_loggers: []
65-
6670
tomcat_enable_collectd: false
67-
6871
tomcat_enable_manager: false
6972
tomcat_manager_remoteaddr_allow: "127\\.0\\.0\\.1"
7073
tomcat_manager_password: 'SETME'
74+
tomcat_preserve_proxy_info: True
75+
tomcat_shutdown_wait: 20
76+
tomcat_start_service: false
7177

78+
tomcat_contexts: []
79+
tomcat_extra_loggers: []
80+
tomcat_global_context:
81+
jdbc_resources: []
7282
tomcat_local_mapping: {}
73-
7483
tomcat_rewrite_rules: []
7584

76-
tomcat_start_service: false
77-
78-
tomcat_shutdown_wait: 20
85+
# This is only compatible with JDK 8 and older
86+
tomcat_java_endorsed_dirs: []

tasks/install.yml

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
tags: ['tomcat']
2929

3030
- name: check if this tomcat version has been installed before
31-
stat: path="{{ tomcat_catalina_home_install_dir }}/apache-tomcat-{{ tomcat_version }}"
31+
stat: path="{{ _tomcat_catalina_home_install_dir }}/apache-tomcat-{{ tomcat_version }}"
3232
register: tomcat_install_found
3333
tags: ['tomcat']
3434

@@ -44,15 +44,15 @@
4444
- name: extract tomcat to tomcat_home
4545
unarchive:
4646
src: "/usr/src/tomcat-{{ tomcat_version }}.tar.gz"
47-
dest: "{{ tomcat_catalina_home_install_dir }}"
47+
dest: "{{ _tomcat_catalina_home_install_dir }}"
4848
remote_src: true
4949
when: tomcat_install_found.stat.exists == false
5050
tags: ['tomcat']
5151

5252
- name: symlink tomcat location
5353
file:
54-
src: "{{ tomcat_catalina_home_install_dir }}/apache-tomcat-{{ tomcat_version }}"
55-
dest: "{{ tomcat_catalina_home }}"
54+
src: "{{ _tomcat_catalina_home_install_dir }}/apache-tomcat-{{ tomcat_version }}"
55+
dest: "{{ _tomcat_catalina_home }}"
5656
owner: "root"
5757
group: "{{ tomcat_group }}"
5858
state: link
@@ -61,7 +61,7 @@
6161

6262
- name: remove noisy files
6363
file:
64-
path: "{{ tomcat_catalina_home }}/{{ item }}"
64+
path: "{{ _tomcat_catalina_home }}/{{ item }}"
6565
state: absent
6666
with_items:
6767
- work
@@ -72,9 +72,14 @@
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+
7580
- name: rename conf dir
7681
command:
77-
mv {{ tomcat_catalina_home }}/conf {{ tomcat_catalina_home }}/conf.dist
82+
mv {{ _tomcat_catalina_home }}/conf {{ _tomcat_catalina_home }}/conf.dist
7883
when: tomcat_conf_dist_found.stat.exists == false
7984
tags: ['tomcat']
8085

@@ -106,7 +111,7 @@
106111
group: root
107112
mode: '0755'
108113
register: tomcat_unit_file
109-
when: ansible_distribution_major_version == '7' or ansible_distribution_major_version == '8'
114+
when: ansible_distribution_major_version >= '7'
110115
tags: ['tomcat']
111116

112117
- name: reload systemd

tasks/install_repo.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
- name: Create unit file override directory if configured
1010
file:
11-
path: "/etc/systemd/system/{{ tomcat_service }}.service.d/"
11+
path: "/etc/systemd/system/{{ _tomcat_service }}.service.d/"
1212
state: directory
1313
owner: root
1414
group: root
@@ -18,7 +18,7 @@
1818
- name: Place unit file overrides if configured
1919
template:
2020
src: etc.systemd.system.tomcat9.service.d.overrides.conf
21-
dest: "/etc/systemd/system/{{ tomcat_service }}.service.d/overrides.conf"
21+
dest: "/etc/systemd/system/{{ _tomcat_service }}.service.d/overrides.conf"
2222
owner: root
2323
group: root
2424
mode: '0644'

tasks/main.yml

Lines changed: 28 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -33,43 +33,43 @@
3333
tags: ['tomcat']
3434

3535
- name: give tomcat group access to read all in CATALINA_HOME
36-
command: "find {{ tomcat_catalina_home }}/ -exec /bin/chgrp {{ tomcat_group }} {} \\;"
36+
command: "find {{ _tomcat_catalina_home }}/ -exec /bin/chgrp {{ tomcat_group }} {} \\;"
3737
tags: ['tomcat']
3838

3939
- name: restrict access to CATALINA_HOME
40-
file: path="{{ tomcat_catalina_home }}" state=directory owner="root" group="{{ tomcat_group }}" mode='0750'
40+
file: path="{{ _tomcat_catalina_home }}" state=directory owner="root" group="{{ tomcat_group }}" mode='0750'
4141
tags: ['tomcat']
4242

4343
- name: ensure logs directory exists in CATALINA_HOME
44-
file: path="{{ tomcat_catalina_home }}/logs" state=directory owner="{{ tomcat_user }}" group="{{ tomcat_group }}" mode='0750'
44+
file: path="{{ _tomcat_catalina_home }}/logs" state=directory owner="{{ tomcat_user }}" group="{{ tomcat_group }}" mode='0750'
4545
tags: ['tomcat']
4646

4747
- name: create CATALINA_BASE dirs
4848
file: path="{{ item }}" state=directory owner="{{ tomcat_user }}" group="{{ tomcat_group }}" mode='0751'
4949
with_items:
50-
- '{{ tomcat_catalina_base }}'
51-
- '{{ tomcat_catalina_base }}/bin'
52-
- '{{ tomcat_catalina_base }}/logs'
53-
- '{{ tomcat_catalina_base }}/conf'
54-
- '{{ tomcat_catalina_base }}/webapps'
55-
- '{{ tomcat_catalina_base }}/temp'
56-
- '{{ tomcat_catalina_base }}/classes'
57-
- '{{ tomcat_catalina_base }}/lib'
50+
- '{{ _tomcat_catalina_base }}'
51+
- '{{ _tomcat_catalina_base }}/bin'
52+
- '{{ _tomcat_catalina_base }}/logs'
53+
- '{{ _tomcat_catalina_base }}/conf'
54+
- '{{ _tomcat_catalina_base }}/webapps'
55+
- '{{ _tomcat_catalina_base }}/temp'
56+
- '{{ _tomcat_catalina_base }}/classes'
57+
- '{{ _tomcat_catalina_base }}/lib'
5858
tags: ['tomcat']
5959

6060
- name: check if tomcat conf dir has been copied before
61-
stat: path={{ tomcat_catalina_base }}/conf/context.xml
61+
stat: path={{ _tomcat_catalina_base }}/conf/context.xml
6262
register: tomcat_conf_found
6363
tags: ['tomcat']
6464

6565
- name: copy tomcat conf.dist folder
66-
shell: "/bin/cp -R /usr/local/tomcat/conf.dist/* {{ tomcat_catalina_base }}/conf"
66+
shell: "/bin/cp -R /usr/local/tomcat/conf.dist/* {{ _tomcat_catalina_base }}/conf"
6767
when: tomcat_conf_found.stat.exists == false
6868
tags: ['tomcat']
6969

7070
- name: secure catalina base config files
7171
file:
72-
path: '{{ tomcat_catalina_base }}/conf/{{ item }}'
72+
path: '{{ _tomcat_catalina_base }}/conf/{{ item }}'
7373
owner: '{{ tomcat_user }}'
7474
group: '{{ tomcat_group }}'
7575
mode: '0640'
@@ -83,15 +83,15 @@
8383
- name: ensure tomcat server.xml exists
8484
template:
8585
src: catalina_base.conf.server.xml.j2
86-
dest: "{{ tomcat_catalina_base }}/conf/server.xml"
86+
dest: "{{ _tomcat_catalina_base }}/conf/server.xml"
8787
owner: "{{ tomcat_user }}"
8888
group: "{{ tomcat_group }}"
8989
mode: '0640'
9090
tags: ['tomcat']
9191

9292
- name: create host config directory for tomcat rewrite rules (if applicable)
9393
file:
94-
path: "{{ tomcat_catalina_base }}/conf/Catalina/{{ tomcat_default_host }}"
94+
path: "{{ _tomcat_catalina_base }}/conf/Catalina/{{ tomcat_default_host }}"
9595
state: directory
9696
owner: "{{ tomcat_user }}"
9797
group: "{{ tomcat_group }}"
@@ -102,21 +102,21 @@
102102
- name: ensure tomcat rewrite rules are placed (if applicable)
103103
copy:
104104
content: "{{ tomcat_rewrite_rules | join('\n')}}"
105-
dest: "{{ tomcat_catalina_base }}/conf/Catalina/{{ tomcat_default_host }}/rewrite.config"
105+
dest: "{{ _tomcat_catalina_base }}/conf/Catalina/{{ tomcat_default_host }}/rewrite.config"
106106
owner: "{{ tomcat_user }}"
107107
group: "{{ tomcat_group }}"
108108
mode: '0640'
109109
when: tomcat_rewrite_rules|length > 0
110110
tags: ['tomcat']
111111

112112
- name: create defaultHost directory
113-
file: path="{{ tomcat_catalina_base }}/conf/Catalina/{{ tomcat_default_host }}" state=directory owner="{{ tomcat_user }}" group="{{ tomcat_group }}" mode='0750'
113+
file: path="{{ _tomcat_catalina_base }}/conf/Catalina/{{ tomcat_default_host }}" state=directory owner="{{ tomcat_user }}" group="{{ tomcat_group }}" mode='0750'
114114
tags: ['tomcat']
115115

116116
- name: ensure tomcat manager.xml exists
117117
template:
118118
src: catalina_base.conf.Catalina.defaultHost.manager.xml.j2
119-
dest: "{{ tomcat_catalina_base }}/conf/Catalina/{{ tomcat_default_host }}/manager.xml"
119+
dest: "{{ _tomcat_catalina_base }}/conf/Catalina/{{ tomcat_default_host }}/manager.xml"
120120
owner: "{{ tomcat_user }}"
121121
group: "{{ tomcat_group }}"
122122
mode: '0640'
@@ -126,7 +126,7 @@
126126
- name: ensure tomcat-users.xml exists
127127
template:
128128
src: catalina_base.conf.tomcat-users.xml.j2
129-
dest: "{{ tomcat_catalina_base }}/conf/tomcat-users.xml"
129+
dest: "{{ _tomcat_catalina_base }}/conf/tomcat-users.xml"
130130
owner: "{{ tomcat_user }}"
131131
group: "{{ tomcat_group }}"
132132
mode: '0640'
@@ -135,7 +135,7 @@
135135
- name: ensure logging.properties exists
136136
template:
137137
src: catalina_base.conf.logging.properties.j2
138-
dest: "{{ tomcat_catalina_base }}/conf/logging.properties"
138+
dest: "{{ _tomcat_catalina_base }}/conf/logging.properties"
139139
owner: "{{ tomcat_user }}"
140140
group: "{{ tomcat_group }}"
141141
mode: 0600
@@ -149,14 +149,14 @@
149149
group: "{{ tomcat_group }}"
150150
mode: '0750'
151151
with_items:
152-
- "{{ tomcat_catalina_base }}/conf/Catalina/"
153-
- "{{ tomcat_catalina_base }}/conf/Catalina/{{ tomcat_default_host }}"
152+
- "{{ _tomcat_catalina_base }}/conf/Catalina/"
153+
- "{{ _tomcat_catalina_base }}/conf/Catalina/{{ tomcat_default_host }}"
154154
tags: ['tomcat']
155155

156156
- name: create pre-defined global contexts
157157
template:
158158
src: catalina_base.conf.context.xml.j2
159-
dest: "{{ tomcat_catalina_base }}/conf/context.xml"
159+
dest: "{{ _tomcat_catalina_base }}/conf/context.xml"
160160
owner: "{{ tomcat_user }}"
161161
group: "{{ tomcat_group }}"
162162
mode: '0640'
@@ -165,7 +165,7 @@
165165
- name: create pre-defined webapp contexts
166166
template:
167167
src: catalina_base.conf.Catalina.context.xml.j2
168-
dest: "{{ tomcat_catalina_base }}/conf/Catalina/{{ tomcat_default_host }}/{{ item.name }}.xml"
168+
dest: "{{ _tomcat_catalina_base }}/conf/Catalina/{{ tomcat_default_host }}/{{ item.name }}.xml"
169169
owner: "{{ tomcat_user }}"
170170
group: "{{ tomcat_group }}"
171171
mode: '0750'
@@ -205,7 +205,7 @@
205205
- name: ensure tomcat setenv.sh exists
206206
template:
207207
src: catalina_base.bin.setenv.sh.j2
208-
dest: "{{ tomcat_catalina_base }}/bin/setenv.sh"
208+
dest: "{{ _tomcat_catalina_base }}/bin/setenv.sh"
209209
owner: "{{ tomcat_user }}"
210210
group: "{{ tomcat_group }}"
211211
mode: 0600
@@ -217,7 +217,7 @@
217217
- name: ensure tomcat env var file exists
218218
template:
219219
src: etc.sysconfig.tomcat.j2
220-
dest: "/etc/sysconfig/{{ tomcat_service }}"
220+
dest: "/etc/sysconfig/{{ _tomcat_service }}"
221221
owner: "{{ tomcat_user }}"
222222
group: "{{ tomcat_group }}"
223223
mode: 0600
@@ -226,7 +226,7 @@
226226

227227
- name: ensure tomcat is started
228228
service:
229-
name: "{{ tomcat_service }}"
229+
name: "{{ _tomcat_service }}"
230230
enabled: true
231231
state: started
232232
when: tomcat_start_service

templates/catalina_base.bin.setenv.sh.j2

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,4 +22,4 @@ if [ $1 == "start" ] ; then
2222
{%- endfor %}"
2323
fi
2424

25-
CATALINA_BASE={{ tomcat_catalina_base }}
25+
CATALINA_BASE={{ _tomcat_catalina_base }}

templates/catalina_base.conf.Catalina.defaultHost.manager.xml.j2

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<!-- {{ ansible_managed }} -->
22

3-
<Context docBase="{{ tomcat_catalina_home }}/webapps/manager"
3+
<Context docBase="{{ _tomcat_catalina_home }}/webapps/manager"
44
privileged="true" antiResourceLocking="false" antiJARLocking="false">
55

66
<!-- Link to the user database we will get roles from -->

templates/etc.init.d.tomcat.j2

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@ prog=tomcat
1212
[ -r /etc/java/java.conf ] && . /etc/java/java.conf
1313
export JAVA_HOME
1414

15-
CATALINA_HOME={{ tomcat_catalina_home }}
16-
CATALINA_BASE={{ tomcat_catalina_base }}
15+
CATALINA_HOME={{ _tomcat_catalina_home }}
16+
CATALINA_BASE={{ _tomcat_catalina_base }}
1717
TOMCAT_USER={{ tomcat_user }}
1818
SHUTDOWN_WAIT=20
1919

templates/etc.logrotate.tomcat.j2

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
{{ tomcat_catalina_base }}/logs/catalina.out {
1+
{{ _tomcat_catalina_base }}/logs/catalina.out {
22
daily
33
rotate 14
44
compress

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_service }} *, /bin/systemctl stop {{ tomcat_service }}, /bin/systemctl start {{ tomcat_service }}
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: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
# {{ ansible_managed }}
22

33
#CATALINA_HOME is the location of the bin files of Tomcat
4-
CATALINA_HOME={{ tomcat_catalina_home }}
4+
CATALINA_HOME={{ _tomcat_catalina_home }}
55

66
#CATALINA_BASE is the location of the configuration files of this instance of Tomcat
7-
CATALINA_BASE={{ tomcat_catalina_base }}
7+
CATALINA_BASE={{ _tomcat_catalina_base }}
88

99
#TOMCAT_USER is the default user of tomcat
1010
TOMCAT_USER={{ tomcat_user }}

0 commit comments

Comments
 (0)