-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathafsbotcfg.yml
291 lines (259 loc) · 11.2 KB
/
afsbotcfg.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
---
- name: Manage OpenAFS buildbot master
hosts: openafs_buildbot_masters
gather_facts: true
tasks:
- name: "Read worker names."
delegate_to: localhost
ansible.builtin.command:
chdir: "{{ playbook_dir }}/files/workers"
cmd: "ls"
changed_when: false
register: _ls_workers
tags:
- configure
- ansible.builtin.set_fact:
_workers: "{{ _ls_workers.stdout_lines }}"
tags:
- configure
#- debug:
# var: _workers
- name: "Read builder files."
vars:
_builders: []
ansible.builtin.set_fact:
_builders: "{{ _builders + (lookup('file', item) | from_yaml) }}"
with_fileglob: "builders/*.yml"
tags:
- configure
#- debug:
# var: _builders
# Setup role variable default values.
- ansible.builtin.set_fact:
afsbotcfg_master_home: "{{ ansible_user_dir }}"
when: afsbotcfg_master_home is undefined
tags:
- configure
- ansible.builtin.set_fact:
afsbotcfg_master_basedir: "{{ afsbotcfg_master_home }}/master/{{ afsbotcfg_project.name | d('openafs') }}"
when: afsbotcfg_master_basedir is undefined
tags:
- configure
- ansible.builtin.set_fact:
afsbotcfg_master_venv: "{{ afsbotcfg_master_home }}/.venv/buildbot"
when: afsbotcfg_master_venv is undefined
tags:
- configure
- ansible.builtin.set_fact:
afsbotcfg_master_python: "/usr/bin/python3"
when: afsbotcfg_master_python is undefined
tags:
- configure
#--------------------------------------------------------------------------
# Install the ssh keys for gerrit integration.
#
# Install the ssh keys required for gerrit event streaming and be sure
# we have a host key to connect to gerrit without a prompt.
#
# The existing gerrit ssh key is a very old and weak key type. This requires
# requires an ssh configuration setting to allow this weak key type.
#--------------------------------------------------------------------------
- name: "Install the ssh keys for gerrit integration."
when: afsbotcfg_gerrit is defined
block:
- name: "Ensure the .ssh directory exists."
ansible.builtin.file:
state: directory
path: "{{ afsbotcfg_master_home }}/.ssh"
mode: "0700"
- name: "Ensure the ssh keys for gerrit are present."
ansible.builtin.copy:
src: "{{ afsbotcfg_gerrit.keysdir | d('keys') }}/{{ item.src }}"
dest: "{{ afsbotcfg_master_home }}/.ssh/{{ item.src | basename }}"
mode: "{{ item.mode }}"
loop:
- src: "{{ afsbotcfg_gerrit.ident | d('gerrit') }}"
mode: "0600"
- src: "{{ afsbotcfg_gerrit.ident | d('gerrit') }}.pub"
mode: "0644"
- name: "Ensure the known_hosts file contains the gerrit server host key."
vars:
_hostkey_file: "{{ afsbotcfg_gerrit.keysdir | d('keys') }}/{{ afsbotcfg_gerrit.hostkey | d('gerrit.hostkey') }}"
_server: "{{ afsbotcfg_gerrit.server | d('gerrit.openafs.org') }}"
_port: "{{ afsbotcfg_gerrit.ssh_port | d('29418') }}"
ansible.builtin.known_hosts:
state: present
key: "{{ lookup('file', _hostkey_file) }}"
name: "[{{ _server }}]:{{ _port }}"
- name: "Ensure weak ssh key types are accepted."
ansible.builtin.lineinfile:
state: present
path: ".ssh/config"
line: "PubkeyAcceptedKeyTypes=+ssh-dss"
create: yes
mode: "0600"
#--------------------------------------------------------------------------
# Install our buildbot master extensions.
#
# Create the buildbot master Python virtualenv and install our afsbotcfg
# package in the virtualenv before importing the buildbot master role.
#--------------------------------------------------------------------------
- ansible.builtin.assert:
that:
- afsbotcfg_version is defined
- afsbotcfg_version | count > 0
fail_msg: afsbotcfg_version is not set.
success_msg: "afsbotcfg_version is {{ afsbotcfg_version }}"
- name: "Create the buildbot master Python virtual environment."
ansible.builtin.pip:
state: present
name:
- pip
- wheel
virtualenv: "{{ afsbotcfg_master_venv }}"
virtualenv_command: "{{ afsbotcfg_master_python }} -m venv"
- name: "Query afsbotcfg installed version."
vars:
print_version: "import afsbotcfg; print(afsbotcfg.__version__)"
ansible.builtin.command:
cmd: "{{ afsbotcfg_master_venv }}/bin/python -c '{{ print_version }}'"
changed_when: false
failed_when: false
register: results_afsbotcfg_version
- ansible.builtin.set_fact:
installed_afsbotcfg_version: "{{ results_afsbotcfg_version.stdout }}"
- ansible.builtin.debug:
var: installed_afsbotcfg_version
- name: "Upload the afsbotcfg package tarball."
ansible.builtin.copy:
src: "src/dist/afsbotcfg-{{ afsbotcfg_version }}.tar.gz"
dest: "/tmp/afsbotcfg-{{ afsbotcfg_version }}.tar.gz"
mode: "0644"
when: installed_afsbotcfg_version != afsbotcfg_version
- name: "Install the afsbotcfg package."
ansible.builtin.pip:
# Do a forced re-installation in case we changed the code but
# did not bother bumping the version.
state: forcereinstall
name: "file:///tmp/afsbotcfg-{{ afsbotcfg_version }}.tar.gz"
virtualenv: "{{ afsbotcfg_master_venv }}"
virtualenv_command: "{{ afsbotcfg_master_python }} -m venv"
when: installed_afsbotcfg_version != afsbotcfg_version
notify: "restart buildbot master instance"
#--------------------------------------------------------------------------
# Upload build-scripts.
#
# These are extra scripts downloaded by the master to workers to
# facilitate package builds.
#--------------------------------------------------------------------------
- name: "Ensure build-scripts directory exists."
ansible.builtin.file:
state: directory
path: "{{ afsbotcfg_master_basedir }}/build-scripts"
mode: "0755"
- name: "Upload build-scripts."
ansible.builtin.copy:
src: "{{ item }}"
dest: "{{ afsbotcfg_master_basedir }}/build-scripts/{{ item | basename }}"
mode: "0755"
with_fileglob: "scripts/*"
register: upload_results
#--------------------------------------------------------------------------
# Install and configure the buildbot master.
#--------------------------------------------------------------------------
- name: "Determine if buildbot already installed"
ansible.builtin.stat:
path: ".local/bin/buildbot"
register: buildbot_binary
- ansible.builtin.set_fact:
current_buildbot_version: "uninstalled"
when: not buildbot_binary.stat.exists
- name: "Prepare to upgrade buildbot"
when: buildbot_binary.stat.exists
block:
- name: "Query current buildbot version"
ansible.builtin.command:
cmd: .local/bin/buildbot --version
changed_when: false
register: results_buildbot_current_version
- name: "Set current buildbot version"
ansible.builtin.set_fact:
current_buildbot_version: "{{ results_buildbot_current_version.stdout_lines | join(' ') | \
regex_replace('^.*Buildbot version:\\s*(?P<bbversion>[0-9.]+).*$', '==\\g<bbversion>') }}"
- name: "Stop buildbot if upgrading"
ansible.builtin.command:
cmd: .local/bin/buildbotctl stop
changed_when: false
when: afsbotcfg_buildbot_version != current_buildbot_version
notify: "restart buildbot master instance"
- ansible.builtin.import_role:
name: openafs_contrib.buildbot.buildbot_master
tags:
- configure
vars:
buildbot_master_home: "{{ afsbotcfg_master_home }}"
buildbot_master_basedir: "{{ afsbotcfg_master_basedir }}"
buildbot_master_venv: "{{ afsbotcfg_master_venv }}"
buildbot_master_python: "{{ afsbotcfg_master_python }}"
# We do not have sudo access on the upstream buildbot master.
buildbot_master_have_sudo: False
buildbot_master_sqlalchemy_version: "{{ afsbotcfg_sqlalchemy_version }}"
buildbot_master_buildbot_version: "{{ afsbotcfg_buildbot_version }}"
buildbot_project: "{{ afsbotcfg_project.name | d('openafs') }}"
buildbot_master_config_templates:
- "{{ playbook_dir }}/templates/passwords.py.j2"
- "{{ playbook_dir }}/templates/master.cfg.j2"
# Master configuration
afsbotcfg_project: "{{ lookup('file', 'project.yml') | from_yaml }}"
afsbotcfg_admin_passwords: "{{ lookup('file', 'admin_passwords.yml') | from_yaml }}"
afsbotcfg_workers: "{{ _workers }}"
afsbotcfg_builders: "{{ _builders }}"
- name: "Update README file."
ansible.builtin.template:
src: README.j2
dest: README
mode: "0644"
#--------------------------------------------------------------------------
# Show buildbot master status.
#--------------------------------------------------------------------------
post_tasks:
- name: "Query buildbot status."
ansible.builtin.command:
cmd: .local/bin/buildbotctl status
changed_when: false
register: results_buildbotctl_status
- name: "Query buildbot version."
ansible.builtin.command:
cmd: .local/bin/buildbot --version
changed_when: false
register: results_buildbot_version
- name: "Query afsbotcfg version."
vars:
print_version: "import afsbotcfg; print(afsbotcfg.__version__)"
ansible.builtin.command:
cmd: "{{ afsbotcfg_master_venv }}/bin/python -c '{{ print_version }}'"
changed_when: false
register: results_afsbotcfg_version
- name: "Upgraded buildbot version or updated configuration"
vars:
_buildbot_org_vers: "Original buildbot version: {{ current_buildbot_version }}"
_buildbot_new_vers: "Requested buildbot version: {{ afsbotcfg_buildbot_version | d('not specified') }}"
_afsbotcfg_org_vers: "Original afsbotcfg version: {{ installed_afsbotcfg_version | d('not installed') }}"
_afsbotcfg_new_vers: "Requested afsbotcfg version: {{ afsbotcfg_version }}"
ansible.builtin.debug:
msg: |
{{ _buildbot_org_vers }}
{{ _buildbot_new_vers }}
{{ _afsbotcfg_org_vers }}
{{ _afsbotcfg_new_vers }}
when: afsbotcfg_buildbot_version != current_buildbot_version or installed_afsbotcfg_version != afsbotcfg_version
- name: "Print versions."
vars:
_buildbot_status: "{{ results_buildbotctl_status.stdout }}"
_buildbot_version: "{{ results_buildbot_version.stdout }}"
_afsbotcfg_version: "afsbotcfg version: {{ results_afsbotcfg_version.stdout }}"
ansible.builtin.debug:
msg: |
{{ _buildbot_status }}
{{ _buildbot_version }}
{{ _afsbotcfg_version }}