-
Notifications
You must be signed in to change notification settings - Fork 0
/
deploy.yml
395 lines (347 loc) · 11.8 KB
/
deploy.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
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
---
- hosts: all
roles:
- chrony
- docker
- hosts: vagrantslaves
roles:
- virtualbox
- vagrant
- hosts: all
sudo: True
tasks:
- name: ensure that buildbot dependency packages are installed
apt:
pkg: "{{ item }}"
state: latest
update_cache: yes
cache_valid_time: 600
with_items:
- git
- python-dev
- python-pip
- name: ensure that buildbot group exists
group:
name: buildbot
state: present
- name: ensure that buildbot user exits
user:
name: buildbot
group: buildbot
home: /srv/buildbot
createhome: yes
state: present
- name: ensure that buildbot user is in the docker group
user:
name: buildbot
groups: docker
append: yes
state: present
- hosts: master
sudo: True
tasks:
- name: ensure that buildbot is installed
pip:
name: "{{ item }}"
state: latest
with_items:
- buildbot
- name: update /etc/init.d/buildmaster for each master if necessary
copy:
src: files/etc/init.d/buildmaster
dest: /etc/init.d/buildmaster
owner: root
group: root
mode: 0755
notify:
- restart buildbot master services
- name: ensure that each buildmaster process has a subdirectory
file:
path: /srv/buildbot/masters/{{ item }}
owner: buildbot
group: buildbot
mode: 0755
state: directory
with_items: [ "1" ]
#with_sequence: start=1 end={{ buildbot_master_process_count }}
- name: ensure that each buildmaster subdirectory has been initialized
sudo_user: buildbot
command: buildbot create-master masters/{{ item }}
args:
chdir: /srv/buildbot
creates: /srv/buildbot/masters/{{ item }}/buildbot.tac
with_items: [ "1" ]
#with_sequence: start=1 end={{ buildbot_master_process_count }}
- name: update master.cfg for each master from template if necessary
template:
src: templates/srv/buildbot/masters/master.cfg
dest: /srv/buildbot/masters/{{ item }}/master.cfg
owner: buildbot
group: buildbot
mode: 0600
with_items: [ "1" ]
#with_sequence: start=1 end={{ buildbot_master_process_count }}
notify:
- restart buildbot master services
- name: ensure that buildmasters are enabled in /etc/default/buildmaster
lineinfile:
dest: /etc/default/buildmaster
regexp: ^#?MASTER_ENABLED\[{{ item }}\]=
line: MASTER_ENABLED[{{ item }}]=1
state: present
create: yes
owner: root
group: root
mode: 0644
with_items: [ "1" ]
#with_sequence: start=1 end={{ buildbot_master_process_count }}
notify:
- restart buildbot master services
- name: ensure that buildmaster names are configured in /etc/default/buildmaster
lineinfile:
dest: /etc/default/buildmaster
regexp: ^#?MASTER_NAME\[{{ item }}\]=
line: 'MASTER_NAME[{{ item }}]="buildmaster {{ inventory_hostname_short }} #{{ item }}"'
state: present
with_items: [ "1" ]
#with_sequence: start=1 end={{ buildbot_master_process_count }}
notify:
- restart buildbot master services
- name: ensure that buildmaster users are configured in /etc/default/buildmaster
lineinfile:
dest: /etc/default/buildmaster
regexp: ^#?MASTER_USER\[{{ item }}\]=
line: 'MASTER_USER[{{ item }}]="buildbot"'
state: present
with_items: [ "1" ]
#with_sequence: start=1 end={{ buildbot_master_process_count }}
notify:
- restart buildbot master services
- name: ensure that buildmaster basedirs are configured in /etc/default/buildmaster
lineinfile:
dest: /etc/default/buildmaster
regexp: ^#?MASTER_BASEDIR\[{{ item }}\]=
line: 'MASTER_BASEDIR[{{ item }}]="/srv/buildbot/masters/{{ item }}"'
state: present
with_items: [ "1" ]
#with_sequence: start=1 end={{ buildbot_master_process_count }}
notify:
- restart buildbot master services
- name: ensure that buildmaster options are configured in /etc/default/buildmaster
lineinfile:
dest: /etc/default/buildmaster
regexp: ^#?MASTER_OPTIONS\[{{ item }}\]=
line: 'MASTER_OPTIONS[{{ item }}]=""'
state: present
with_items: [ "1" ]
#with_sequence: start=1 end={{ buildbot_master_process_count }}
notify:
- restart buildbot master services
- name: ensure that buildmaster options are configured in /etc/default/buildmaster
lineinfile:
dest: /etc/default/buildmaster
regexp: ^#?MASTER_PREFIXCMD\[{{ item }}\]=
line: 'MASTER_PREFIXCMD[{{ item }}]=""'
state: present
with_items: [ "1" ]
#with_sequence: start=1 end={{ buildbot_master_process_count }}
notify:
- restart buildbot master services
- name: ensure that buildbot master services are started and enabled
service:
name: "{{ item }}"
pattern: twistd.run()
enabled: yes
state: started
with_items:
- buildmaster
#- name: ensure that nginx packages are installed
# apt:
# pkg: "{{ item }}"
# state: latest
# update_cache: yes
# cache_valid_time: 600
# with_items:
# - nginx
#- name: update /etc/nginx/sites-available/buildbot from template
# template:
# src: templates/etc/nginx/sites-available/buildbot
# dest: /etc/nginx/sites-available/buildbot
# owner: root
# group: root
# mode: 0644
# notify:
# - restart nginx
#- name: ensure /etc/nginx/sites-enabled/buildbot exists and links to ../sites-available/buildbot
# file:
# path: /etc/nginx/sites-enabled/buildbot
# src: ../sites-available/buildbot
# force: yes
# state: link
# notify:
# - restart nginx
#- name: ensure /etc/nginx/sites-enabled/default has been removed
# file:
# path: /etc/nginx/sites-enabled/default
# state: absent
# notify:
# - restart nginx
#- name: ensure that there is not a hostname collision with the nginx default host
# lineinfile:
# dest: /etc/nginx/sites-available/default
# regexp: '^(\s+)(server_name {{ buildbot_hostname }};.*)$'
# backrefs: yes
# line: '\1#\2'
# state: present
# notify:
# - restart nginx
#- name: ensure that nginx is started and enabled
# service:
# name: "{{ item }}"
# pattern: twistd.run()
# enabled: yes
# state: started
# with_items:
# - nginx
handlers:
- name: restart buildbot master services
service:
name: "{{ item }}"
state: restarted
with_items:
- buildmaster
- name: restart nginx
service:
name: "{{ item }}"
state: restarted
with_items:
- nginx
- hosts: slaves:vagrantslaves
sudo: True
tasks:
- name: ensure that buildbot-slave is installed
pip:
name: "{{ item }}"
state: latest
with_items:
- buildbot-slave
- name: update /etc/init.d/buildslave for each slave if necessary
copy:
src: files/etc/init.d/buildslave
dest: /etc/init.d/buildslave
owner: root
group: root
mode: 0755
notify:
- restart buildbot slave services
- name: ensure that each buildslave process has a subdirectory
file:
path: /srv/buildbot/slaves/{{ item }}
owner: buildbot
group: buildbot
mode: 0700
state: directory
with_sequence: start=1 end={{ buildbot_slave_process_count }}
- name: ensure that each buildslave subdirectory has been initialized
sudo_user: buildbot
command: |
buildslave create-slave slaves/{{ item }} {{ buildbot_master_ip }}:9989
slave-{{ inventory_hostname_short }}-{{ item }}
{{ lookup('password', buildbot_run_dir +
'/private/credentials/buildslave-password-' +
inventory_hostname_short + '-' + item +
' length=20 chars=ascii_letters,digits') }}
args:
chdir: /srv/buildbot
creates: /srv/buildbot/slaves/{{ item }}/buildbot.tac
with_sequence: start=1 end={{ buildbot_slave_process_count }}
- name: update admin for each master from template if necessary
template:
src: templates/srv/buildbot/slaves/info/admin
dest: /srv/buildbot/slaves/{{ item }}/info/admin
owner: buildbot
group: buildbot
mode: 0644
with_sequence: start=1 end={{ buildbot_slave_process_count }}
notify:
- restart buildbot slave services
- name: update info for each master from template if necessary
template:
src: templates/srv/buildbot/slaves/info/host
dest: /srv/buildbot/slaves/{{ item }}/info/host
owner: buildbot
group: buildbot
mode: 0644
with_sequence: start=1 end={{ buildbot_slave_process_count }}
notify:
- restart buildbot slave services
- name: ensure that buildslave is enabled in /etc/default/buildslave
lineinfile:
dest: /etc/default/buildslave
regexp: ^#?SLAVE_ENABLED\[{{ item }}\]=
line: SLAVE_ENABLED[{{ item }}]=1
state: present
create: yes
owner: root
group: root
mode: 0644
with_sequence: start=1 end={{ buildbot_slave_process_count }}
- name: ensure that buildslave names are configured in /etc/default/buildslave
lineinfile:
dest: /etc/default/buildslave
regexp: ^#?SLAVE_NAME\[{{ item }}\]=
line: 'SLAVE_NAME[{{ item }}]="buildslave {{ inventory_hostname_short }} #{{ item }}"'
state: present
with_sequence: start=1 end={{ buildbot_slave_process_count }}
- name: ensure that buildslave users are configured in /etc/default/buildslave
lineinfile:
dest: /etc/default/buildslave
regexp: ^#?SLAVE_USER\[{{ item }}\]=
line: 'SLAVE_USER[{{ item }}]="buildbot"'
state: present
with_sequence: start=1 end={{ buildbot_slave_process_count }}
- name: ensure that buildslave basedirs are configured in /etc/default/buildslave
lineinfile:
dest: /etc/default/buildslave
regexp: ^#?SLAVE_BASEDIR\[{{ item }}\]=
line: 'SLAVE_BASEDIR[{{ item }}]="/srv/buildbot/slaves/{{ item }}"'
state: present
with_sequence: start=1 end={{ buildbot_slave_process_count }}
- name: ensure that buildslave options are configured in /etc/default/buildslave
lineinfile:
dest: /etc/default/buildslave
regexp: ^#?SLAVE_OPTIONS\[{{ item }}\]=
line: 'SLAVE_OPTIONS[{{ item }}]=""'
state: present
with_sequence: start=1 end={{ buildbot_slave_process_count }}
- name: ensure that buildslave options are configured in /etc/default/buildslave
lineinfile:
dest: /etc/default/buildslave
regexp: ^#?SLAVE_PREFIXCMD\[{{ item }}\]=
line: 'SLAVE_PREFIXCMD[{{ item }}]=""'
state: present
with_sequence: start=1 end={{ buildbot_slave_process_count }}
- name: ensure that buildbot slave services are started and enabled
service:
name: "{{ item }}"
pattern: "{{ item }}"
enabled: yes
state: started
with_items:
- buildslave
handlers:
- name: restart buildbot slave services
service:
name: "{{ item }}"
state: restarted
with_items:
- buildslave
- hosts: vagrantslaves
tasks:
- name: ensure that ansible is installed
pip:
name: "{{ item }}"
state: latest
with_items:
- ansible
- netaddr