-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathroller.yml
214 lines (184 loc) · 5.9 KB
/
roller.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
# This ansible playbook sets up an Apache Roller instance which runs with a Tomcat instance and a PostgreSQL database.
#
# Tested with:
# * Ubuntu 16.04.4 LTS (GNU/Linux 4.4.0-121-generic x86_64) @ http://digitalocean.com
# * Ansible 2.4.3.0
#
# Usage:
# 1. Make sure that you can log into your server with 'ssh [email protected]' without a password
# 2. Download a Roller release package and place the WAR file it contains as "files/roller.war"
# 3. Edit "hosts" file and change the hostname to yours
# 4. Edit vars.yml to suit your needs (especially if you have a SMTP server)
# 5. Run "ansible-playbook roller.yml"
# 6. Open http://yourserver.example.com/ and proceed with setting up Roller
#
# Example:
# $ ansible-playbook roller.yml
# $ ansible-playbook roller.yml --tags war # when you only want to deploy the roller WAR file
#
# Notes:
# It's recommended to set up SSL with https://letsencrypt.org if you want to run your own blog with Roller. It should be super easy as this setup consists of the Apache layer.
#
# Don't forget to set installation.type=manual in roller-custom.properties when you finish the setting up process. You can deploy the file with "ansible-playbook roller.yml --tags roller"
#
# If something goes wrong, you may want to check the following:
# * /var/log/tomcat8/catalina.out
# * /usr/local/rollerdata/roller.log
- name: prepare
hosts: roller_server
gather_facts: false
sudo: True
tasks:
- name: install python 2
raw: test -e /usr/bin/python || (apt -y update && apt install -y python-minimal)
- name: setup roller
vars_files:
- vars.yml
hosts: roller_server
sudo: True
tasks:
# taken from https://stackoverflow.com/a/24765946/3591946
- name: Create swap file
command: dd if=/dev/zero of={{ swap_file_path }} bs=1024 count={{ swap_file_size_mb }}k
creates="{{ swap_file_path }}"
tags:
- swap.file.create
- name: Change swap file permissions
file: path="{{ swap_file_path }}"
owner=root
group=root
mode=0600
tags:
- swap.file.permissions
- name: "Check swap file type"
command: file {{ swap_file_path }}
register: swapfile
tags:
- swap.file.mkswap
- name: Make swap file
command: "sudo mkswap {{ swap_file_path }}"
when: swapfile.stdout.find('swap file') == -1
tags:
- swap.file.mkswap
- name: Write swap entry in fstab
mount: name=none
src={{ swap_file_path }}
fstype=swap
opts=sw
passno=0
dump=0
state=present
tags:
- swap.fstab
- name: Mount swap
command: "swapon {{ swap_file_path }}"
when: ansible_swaptotal_mb < 1
tags:
- swap.file.swapon
- name: install apache2
apt: name=apache2 update_cache=yes state=latest
tags:
- apache
- name: install jdk
apt: name=openjdk-8-jdk
tags:
- tomcat
- name: install tomcat
apt: name=tomcat8
- name: Install list of packages
apt: name={{item}} state=installed
with_items:
- postgresql
- postgresql-contrib
- python-psycopg2
- unzip
- name: download some dependencies
get_url: url={{ item.url }} dest=/usr/share/tomcat8/lib
with_items:
- { url: 'https://repo1.maven.org/maven2/org/postgresql/postgresql/42.2.2/postgresql-42.2.2.jar'}
- { url: 'https://repo1.maven.org/maven2/javax/mail/mail/1.5.0-b01/mail-1.5.0-b01.jar'}
- name: install module for apache
apache2_module:
state: present
name: proxy_ajp
notify: restart apache
- name: enable configuration for apache
template: src=files/000-default.conf.j2 dest=/etc/apache2/sites-available/000-default.conf
notify: restart apache
- name: setup database user
become: true
become_user: postgres
postgresql_user: name={{ db.username }} password={{ db.password }} role_attr_flags=SUPERUSER
- name: Setup postgres database
become: true
become_user: postgres
postgresql_db: name=roller state=present owner=roller
- name: put some files for tomcat
copy: src={{ item.src }} dest={{ item.dest }}
notify: restart tomcat
with_items:
- { src: 'files/server.xml', dest: '/etc/tomcat8' }
- { src: 'files/tomcat8', dest: '/etc/default/tomcat8' }
- name: put context.xml
template: src=files/context.xml.j2 dest=/etc/tomcat8/context.xml
notify: restart tomcat
- name: create rollerdata directory
file:
path: /usr/local/rollerdata
state: directory
owner: tomcat8
- name: copy roller-custom.properties
copy: src=files/roller-custom.properties dest=/usr/share/tomcat8/lib
notify: restart tomcat
tags:
- roller
- name: create mywebapps directory
file:
path: /var/lib/tomcat8/mywebapps
state: directory
owner: tomcat8
- name: upload roller.war
copy: src=files/roller.war dest=/usr/local/rollerdata
register: uploadwar
tags:
- war
- name: Stop service tomcat, if started
service:
name: tomcat8
state: stopped
when: uploadwar.changed
tags:
- war
- name: remove old app
file:
state: absent
path: /var/lib/tomcat8/mywebapps/ROOT/
when: uploadwar.changed
tags:
- war
- name: create app dir
file:
path: /var/lib/tomcat8/mywebapps/ROOT/
state: directory
owner: tomcat8
mode: 0755
when: uploadwar.changed
tags:
- war
- name: Unzip WAR file
unarchive: src=/usr/local/rollerdata/roller.war dest=/var/lib/tomcat8/mywebapps/ROOT/ copy=no mode=0755 owner=tomcat8 group=tomcat8
when: uploadwar.changed
tags:
- war
- name: Start service tomcat, if stopped
service:
name: tomcat8
state: started
when: uploadwar.changed
tags:
- war
handlers:
- name: restart tomcat
service: name=tomcat8 state=restarted
- name: restart apache
service: name=apache2 state=restarted