-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathxwiki.yml
309 lines (252 loc) · 9.16 KB
/
xwiki.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
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
---
# Playbook: xwiki
# Author: Shahriar Shafiullah
# Date: 03-08-2015
# Description: Creates LXC containers and installs Xwiki on top of a tomcat7 and Postgressql stack
- hosts: nodes
user: ubuntu
sudo: yes
sudo_user: root
vars:
app1: 10.0.3.101
app2: 10.0.3.102
db1: 10.0.3.103
gateway: 10.0.3.1
range1: 10.0.3.2
range2: 10.0.3.254
netmask: 255.255.255.0
network: 10.0.3.0/24
tasks:
# Create LXC containers
- name: Install LXC
apt:
name: lxc
update_cache: yes
state: installed
# Configure LXC to send fixed IP to app1, app2 and db1
- name: Configure LXC default
template:
src: lxc/lxc-net
dest: /etc/default/lxc-net
- name: Configure LXC dnsmasq
template:
src: lxc/dnsmasq.conf
dest: /etc/lxc/dnsmasq.conf
# Restart required to recognize dnsmasq new settings.
# We only want to do this once so the service module was not used.
# A handler was not appropriate for this as the next few stanzas depend
# on the dnsmasq settings working (handlers only execute once the tasks
# section runs all the way through
- name: Restart lxc-net
shell: /usr/sbin/service lxc-net restart; /usr/bin/touch /opt/lxc
args:
creates: /opt/lxc
# Install requirements for lxc_container module
- apt: name={{item}}
with_items:
- python-setuptools
- unzip
- git
- build-essential
- python-dev
- lxc-dev
# Supposed 'stable' version of python-pip on the Ubuntu repository does not function
# Latest easy_install version used instead
- easy_install: name=pip
# pip module appears to run everytime regardless of if the package already exists
- pip: name=git+https://github.com/lxc/python2-lxc.git#egg=python2-lxc
# lxc_container is new to version 1.8 of ansible and seems to be a bit buggy
- name: app1_container
lxc_container:
name: app1
template: ubuntu
state: started
template_options: --release trusty
container_command: |
apt-get update
apt-get install tomcat7 -y
- name: app2_container
lxc_container:
name: app2
template: ubuntu
state: started
template_options: --release trusty
container_command: |
apt-get update
apt-get install tomcat7 -y
- name: ensure_tomcat_app1
lxc_container:
name: app1
container_command: apt-get install tomcat7 -y
- name: ensure_tomcat_app2
lxc_container:
name: app2
container_command: apt-get install tomcat7 -y
- name: db1_container
lxc_container:
name: db1
template: ubuntu
state: started
template_options: --release trusty
container_command: |
apt-get update
apt-get install postgresql-9.3 -y
- name: create interfaces app1
template:
src: lxc/app1_interfaces
dest: /var/lib/lxc/app1/rootfs/etc/network/interfaces
- name: create interfaces app2
template:
src: lxc/app2_interfaces
dest: /var/lib/lxc/app2/rootfs/etc/network/interfaces
- name: create interfaces db1
template:
src: lxc/db1_interfaces
dest: /var/lib/lxc/db1/rootfs/etc/network/interfaces
# Tomcat7 configuration
- name: create setenv.sh file app1
copy:
src: tomcat/setenv.sh
dest: /var/lib/lxc/app1/rootfs/usr/share/tomcat7/bin/setenv.sh
- name: create setenv.sh file app2
copy:
src: tomcat/setenv.sh
dest: /var/lib/lxc/app2/rootfs/usr/share/tomcat7/bin/setenv.sh
- name: change attributes on setenv.sh app1
file:
path: /var/lib/lxc/app1/rootfs/usr/share/tomcat7/bin/setenv.sh
owner: root
mode: 0755
- name: change attributes on setenv.sh app2
file:
path: /var/lib/lxc/app2/rootfs/usr/share/tomcat7/bin/setenv.sh
owner: root
mode: 0755
- name: install postgres JDBC library app1
get_url:
dest: /var/lib/lxc/app1/rootfs/usr/share/tomcat7/lib/postgresql-9.4-1201.jdbc4.jar
url: https://jdbc.postgresql.org/download/postgresql-9.4-1201.jdbc4.jar
validate_certs: no
force: no
- name: install postgres JDBC library app2
get_url:
dest: /var/lib/lxc/app2/rootfs/usr/share/tomcat7/lib/postgresql-9.4-1201.jdbc4.jar
url: https://jdbc.postgresql.org/download/postgresql-9.4-1201.jdbc4.jar
validate_certs: no
force: no
# Postgres database configuration
- name: Give ansible permission to access postgres
template:
src: postgres/pg_hba.conf
dest: /var/lib/lxc/db1/rootfs/etc/postgresql/9.3/main/pg_hba.conf
- name: Open port to app servers
copy:
src: postgres/postgresql.conf
dest: /var/lib/lxc/db1/rootfs/etc/postgresql/9.3/main/postgresql.conf
- name: Create DB sql script
copy:
src: postgres/xwiki.sql
dest: /var/lib/lxc/db1/rootfs/opt/xwiki.sql
- name: db1_container
lxc_container:
name: db1
template: ubuntu
state: started
template_options: --release trusty
container_command: |
chown postgres:postgres /etc/postgresql/9.3/main/pg_hba.conf
service postgresql restart
/usr/bin/psql -U postgres -f /opt/xwiki.sql
# Deploy the Xwiki application
# - name: Copy war to app1
# copy:
# src: tomcat/xwiki-enterprise-web-7.1.2-20150725.161333-26.war
# dest: /var/lib/lxc/app1/rootfs/opt/xwiki-enterprise-web-7.1.2-20150725.161333-26.war
# - name: Copy war to app2
# copy:
# src: tomcat/xwiki-enterprise-web-7.1.2-20150725.161333-26.war
# dest: /var/lib/lxc/app2/rootfs/opt/xwiki-enterprise-web-7.1.2-20150725.161333-26.war
# Temporarily commented out for brevity
- name: Download Xwiki war file app1
get_url:
dest: /var/lib/lxc/app1/rootfs/opt/xwiki-enterprise-web-7.1.2-20150725.161333-26.war
url: http://maven.xwiki.org/snapshots/org/xwiki/enterprise/xwiki-enterprise-web/7.1.2-SNAPSHOT/xwiki-enterprise-web-7.1.2-20150725.161333-26.war
force: no
- name: Download Xwiki war file app2
get_url:
dest: /var/lib/lxc/app2/rootfs/opt/xwiki-enterprise-web-7.1.2-20150725.161333-26.war
url: http://maven.xwiki.org/snapshots/org/xwiki/enterprise/xwiki-enterprise-web/7.1.2-SNAPSHOT/xwiki-enterprise-web-7.1.2-20150725.161333-26.war
force: no
# Check if the default ROOT application for tomcat7 exists. Remove it if it does
- stat: path=/var/lib/lxc/app1/rootfs/var/lib/tomcat7/webapps/ROOT/index.html
register: app1_root
- stat: path=/var/lib/lxc/app2/rootfs/var/lib/tomcat7/webapps/ROOT/index.html
register: app2_root
- shell: "rm -rf /var/lib/lxc/app1/rootfs/var/lib/tomcat7/webapps/ROOT/*"
when: app1_root.stat.exists == True
- shell: "rm -rf /var/lib/lxc/app2/rootfs/var/lib/tomcat7/webapps/ROOT/*"
when: app2_root.stat.exists == True
- name: deploy xwiki app1
command: /usr/bin/unzip /var/lib/lxc/app1/rootfs/opt/xwiki-enterprise-web-7.1.2-20150725.161333-26.war
args:
chdir: /var/lib/lxc/app1/rootfs/var/lib/tomcat7/webapps/ROOT
creates: /var/lib/lxc/app1/rootfs/var/lib/tomcat7/webapps/ROOT/templates
- name: deploy xwiki app2
command: /usr/bin/unzip /var/lib/lxc/app2/rootfs/opt/xwiki-enterprise-web-7.1.2-20150725.161333-26.war
args:
chdir: /var/lib/lxc/app2/rootfs/var/lib/tomcat7/webapps/ROOT
creates: /var/lib/lxc/app2/rootfs/var/lib/tomcat7/webapps/ROOT/templates
- name: Configure hibernate file app1
template:
src: tomcat/hibernate.cfg.xml
dest: /var/lib/lxc/app1/rootfs/var/lib/tomcat7/webapps/ROOT/WEB-INF/hibernate.cfg.xml
- name: Configure hibernate file app2
template:
src: tomcat/hibernate.cfg.xml
dest: /var/lib/lxc/app2/rootfs/var/lib/tomcat7/webapps/ROOT/WEB-INF/hibernate.cfg.xml
# Bug in lxc_container will not let us reload the configurations so a stop/start is required
- name: app1_container_stop
lxc_container:
name: app1
state: stopped
- name: app1_container_start
lxc_container:
name: app1
state: started
- name: app2_container_stop
lxc_container:
name: app2
state: stopped
- name: app2_container_start
lxc_container:
name: app2
state: started
- name: db1_container_stop
lxc_container:
name: db1
state: stopped
- name: db1_container_start
lxc_container:
name: db1
state: started
# Install nginx as a loadbalancer
- name: Creat nginx user
user: name=nginx
- name: Install nginx service
apt:
name: nginx
update_cache: yes
state: installed
- name: Create nginx.conf config
copy:
src: nginx/nginx.conf
dest: /etc/nginx/nginx.conf
notify: Reload nginx
- name: Configure nginx defaults
template:
src: nginx/default.conf
dest: /etc/nginx/conf.d/default.conf
notify: Reload nginx
handlers:
- name: Reload nginx
action: service name=nginx state=restarted