main.yml 7.61 KB
Newer Older
David Nowell's avatar
David Nowell committed
1
---
2
# tasks file for Gitlab build
David Nowell's avatar
David Nowell committed
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17

  - name: Install LVM
    yum:
      name: lvm2
      state: present

  - name: Create VG
    lvg:
      vg: uservg00
      pvs: "{{ device_name | regex_replace('sd','xvd') }}"

  - name: Create lv-varlog-gitlab
    lvol:
      vg: uservg00
      lv: lv-varlog-gitlab
David Nowell's avatar
David Nowell committed
18
      size: 5g
David Nowell's avatar
David Nowell committed
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40

  - name: Create filesystem /var/log/gitlab
    filesystem:
      fstype: xfs
      dev: /dev/uservg00/lv-varlog-gitlab

  - name: Create mount point for /var/log/gitlab
    file:
      path: /var/log/gitlab
      state: directory

  - name: Mount filesystem /var/log/gitlab
    mount:
      fstype: xfs
      path: /var/log/gitlab
      src: /dev/uservg00/lv-varlog-gitlab
      state: mounted

  - name: Create lv-varopt-gitlab
    lvol:
      vg: uservg00
      lv: lv-varopt-gitlab
David Nowell's avatar
David Nowell committed
41
      size: 60g
David Nowell's avatar
David Nowell committed
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59

  - name: Create filesystem /var/opt/gitlab
    filesystem:
      fstype: xfs
      dev: /dev/uservg00/lv-varopt-gitlab

  - name: Create mount point for /var/opt/gitlab
    file:
      path: /var/opt/gitlab
      state: directory

  - name: Mount /var/opt/gitlab
    mount:
      fstype: xfs
      path: /var/opt/gitlab
      src: /dev/uservg00/lv-varopt-gitlab
      state: mounted

David Nowell's avatar
David Nowell committed
60

David Nowell's avatar
David Nowell committed
61
62
63
64
65

  - name: Create lv-opt-gitlab
    lvol:
      vg: uservg00
      lv: lv-opt-gitlab
David Nowell's avatar
David Nowell committed
66
      size: 10g
David Nowell's avatar
David Nowell committed
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

  - name: Create filesystem /opt/gitlab
    filesystem:
      fstype: xfs
      dev: /dev/uservg00/lv-opt-gitlab

  - name: Create mount point for /opt/gitlab
    file:
      path: /opt/gitlab
      state: directory

  - name: Mount /opt/gitlab
    mount:
      fstype: xfs
      path: /opt/gitlab
      src: /dev/uservg00/lv-opt-gitlab
      state: mounted

  - name: Install useful packages
    yum:
      name: "{{ item }}"
      state: present
    with_items:
      - mailx
      - psmisc
92
      - fail2ban
David Nowell's avatar
David Nowell committed
93
94
95
96
97

  - name: Load secret variables
    include_vars:
      file: vars/secret-vars.yml

98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
  - name: Create /root/.aws directory
    file:
      path: "/root/.aws"
      state: "directory"
      mode: '750'

  - name: AWS Config
    copy:
      src: "aws-config"
      dest: "/root/.aws/config"
      mode: '600'

  - name: AWS Credentials
    template:
      src: "aws-credentials.j2"
      dest: "/root/.aws/credentials"
      mode: '600'
      owner: "root"

  - name: Find latest Gitlab backup version
David Nowell's avatar
David Nowell committed
118
    shell: aws s3 ls umich-vdc-gitlab | grep ee_gitlab_backup.tar | tail -1 | awk '{print $4}' | cut -d'_' -f5
119
120
121
    register: GitVersion


David Nowell's avatar
David Nowell committed
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
  - name: Set firewall rules
    copy:
      src: "{{ item }}"
      dest: "/etc/firewalld/zones/{{ item }}"
      mode: '644'
      owner: root
    with_items:
      - public.xml
      - umich.xml
    register: firewall

  - name: Container Registry Firewall Service
    copy:
      src: "{{ item }}"
      dest: "/etc/firewalld/services/{{ item }}"
      mode: '644'
      owner: root
    with_items:
      - container-reg.xml

  - name: Reload Firewalld
    service: 
      name: firewalld
      state: reloaded
    when: firewall.changed

148
149
150
151
152
153
  - name: Start Fail2ban
    service:
      name: fail2ban
      state: started
      enabled: yes

David Nowell's avatar
David Nowell committed
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
  - name: Check if GitLab configuration file already exists.
    stat: path=/etc/gitlab/gitlab.rb

  - name: Add Gitlab Repo
    yum_repository:
      name: gitlab_gitlab-ee
      description: GitLab EE Repo
      baseurl: https://packages.gitlab.com/gitlab/gitlab-ee/el/7/$basearch
      gpgcheck: yes
      gpgkey: "https://packages.gitlab.com/gitlab/gitlab-ee/gpgkey\nhttps://packages.gitlab.com/gitlab/gitlab-ee/gpgkey/gitlab-gitlab-ee-3D645A26AB9FBD22.pub.gpg"
      enabled: yes
      sslcacert: /etc/pki/tls/certs/ca-bundle.crt
      sslverify: yes
      state: present
      
  - name: Install GitLab GPG Key 1
    rpm_key:
      key: https://packages.gitlab.com/gitlab/gitlab-ee/gpgkey
      state: present

  - name: Install GitLab GPG Key 2
    rpm_key:
      key: https://packages.gitlab.com/gitlab/gitlab-ee/gpgkey/gitlab-gitlab-ee-3D645A26AB9FBD22.pub.gpg
      state: present

  - name: Install GitLab EE
    yum:
181
      name: gitlab-ee-{{ GitVersion.stdout }}.0.el7
David Nowell's avatar
David Nowell committed
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
      state: present

  - name: Git is picky about authorized keys file location - ensure it is in default location
    blockinfile:
      path: /etc/ssh/sshd_config
      block: |
        Match User git
        AuthorizedKeysFile .ssh/authorized_keys
        Banner none
    register: gitssh

  - name: Restart sshd if changed
    service:
      name: sshd
      state: restarted
      enabled: yes
    when: gitssh.changed

  - name: Create gitadmin group
    group:
      name: gitadmin
      gid: 663663
      state: present

  - name: Add git user to gitadmin group
    user:
      name: git
      groups: gitadmin
      state: present

  - name: Grant sudo to gitadmin group
    copy:
      src: "80-umadmins"
      dest: "/etc/sudoers.d/80-umadmins"
      mode: '644'

  - name: Cron job to backup Gitlab
    copy:
      src: "gitback-cron"
      dest: "/etc/cron.d/gitback"
      mode: '644'

  - name: Script to backup Git configurations
    copy:
      src: "gitbackup.sh"
      dest: "/usr/local/bin/gitbackup.sh"
      mode: '744'

David Nowell's avatar
David Nowell committed
230
231
232
233
234
235
236
  - name: Script to restore Git from backup
    template:
      src: "restore-gitlab.sh.j2"
      dest: "/usr/local/bin/restore-gitlab.sh"
      mode: '744'
      owner: "root"

David Nowell's avatar
David Nowell committed
237
238
239
240
241
242
243
244
245
246
  - name: update /etc/gitlab/gitlab.rb
    template:
      src: "gitlab.rb.j2"
      dest: "/etc/gitlab/gitlab.rb"
      mode: '600'
      owner: "root"
    notify:
      - Reconfigure Gitlab
      - Restart Gitlab

247
248
  - name: Create backups directory
    file:
David Nowell's avatar
David Nowell committed
249
      path: /var/opt/gitlab/backups
250
251
252
253
      state: directory
      owner: "git"
      group: "git"

David Nowell's avatar
David Nowell committed
254
255
256
257
258
  - name: Create /etc/gitlab/ssl
    file:
      path: "/etc/gitlab/ssl"
      state: "directory"
      mode: '750'
259
      owner: "git"
David Nowell's avatar
David Nowell committed
260
261
262
263
264
265
266

  - name: Copy Gitlab keys
    copy:
      src: "{{ item }}"
      dest: "/etc/gitlab/ssl/{{ item }}"
      mode: '640'
    with_items:
267
268
      - "{{ KEYFILE }}"
      - "{{ CRTFILE }}"
David Nowell's avatar
David Nowell committed
269
270
271
272
273
274
275
276
277
278
279
280


  - name: Custom NRPE check
    copy:
      src: "gitlab-nrpe.cfg"
      dest: "/etc/nrpe.d/"
      owner: nrpe
      group: nrpe
      mode: "640"
    notify:
      - Restart NRPE

281
282
283
  #############################################################################
  - block:
  #############################################################################
284
285
286
    # This should kick off the reconfigure / restart before running the restore
    - meta: flush_handlers

287
288
    - name: Restore Gitlab
      command: /usr/local/bin/restore-gitlab.sh
289

David Nowell's avatar
Revert    
David Nowell committed
290
      when: restore is defined and restore == "yes"
David Nowell's avatar
David Nowell committed
291

292
293
294
295
296
297
298
  - name: upgrade all packages
    yum:
      name: '*'
      state: latest 
    notify:
      - Restart Gitlab

David Nowell's avatar
David Nowell committed
299
300


301
302

# This is how to do a restore (as root).  In /usr/local/bin/restore-gitlab.sh
David Nowell's avatar
David Nowell committed
303
304
305
306
307
308
309
310
311
# gitlab-ctl stop unicorn
# gitlab-ctl stop sidekiq
#
# aws s3 ls umich-vdc-gitlab
#
# aws s3 cp s3://umich-vdc-gitlab/1529568076_2018_06_21_10.8.4-ee_gitlab_backup.tar /var/opt/gitlab/backups/
#
# chown git:git /var/opt/gitlab/backups/*.tar
#
312
# 
David Nowell's avatar
David Nowell committed
313
# aws s3 cp s3://umich-vdc-gitlab/gitback-config.20180620.tar /etc/gitlab/
314
# Be careful about this - It should all be in our Ansible playbook, so might not need it
David Nowell's avatar
David Nowell committed
315
316
# cd /etc/gitlab; tar -xf gitback-config.20180620.tar .
#
317
# This is important to do, but not when setting up a new Gitlab instance.  Would do if rebuilding gitlab.umich.edu and want same host key
David Nowell's avatar
David Nowell committed
318
319
320
# aws s3 cp s3://umich-vdc-gitlab/gitback-ssh-host-keys.20180620.tar /etc/ssh/
# cd /etc/ssh; tar -xf gitback-ssh-host-keys.20180620.tar
#
321
322
#
#
David Nowell's avatar
David Nowell committed
323
324
325
326
327
328
329
330
331
332
333
334
335
336
# gitlab-rake gitlab:backup:restore BACKUP=1529568076_2018_06_21_10.8.4-ee force=yes
#
# gitlab-ctl start unicorn
# gitlab-ctl start sidekiq
#
# usermod -G gitadmin git
#
# systemctl restart sshd.service
#
# gitlab-ctl restart
#
# gitlab-rake gitlab:check SANITIZE=true
#
#