main.yml 7.03 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
60
61
62
63
64

  - 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


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

  - 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
91
      - fail2ban
David Nowell's avatar
David Nowell committed
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

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

  - 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

123
124
125
126
127
128
  - name: Start Fail2ban
    service:
      name: fail2ban
      state: started
      enabled: yes

David Nowell's avatar
David Nowell committed
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
  - 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:
      name: gitlab-ee
      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
205
206
207
208
209
210
211
  - 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
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
  - 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

  - name: Create /etc/gitlab/ssl
    file:
      path: "/etc/gitlab/ssl"
      state: "directory"
      mode: '750'

  - name: Copy Gitlab keys
    copy:
      src: "{{ item }}"
      dest: "/etc/gitlab/ssl/{{ item }}"
      mode: '640'
    with_items:
234
235
      - "{{ KEYFILE }}"
      - "{{ CRTFILE }}"
David Nowell's avatar
David Nowell committed
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

  - 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: Custom NRPE check
    copy:
      src: "gitlab-nrpe.cfg"
      dest: "/etc/nrpe.d/"
      owner: nrpe
      group: nrpe
      mode: "640"
    notify:
      - Restart NRPE

266
267
268
269
270
271
  #############################################################################
  - block:
  #############################################################################
    - name: Restore Gitlab
      command: /usr/local/bin/restore-gitlab.sh
      when: restore is defined and restore == "yes"
David Nowell's avatar
David Nowell committed
272

273
   
David Nowell's avatar
David Nowell committed
274
275


276
277

# This is how to do a restore (as root).  In /usr/local/bin/restore-gitlab.sh
David Nowell's avatar
David Nowell committed
278
279
280
281
282
283
284
285
286
# 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
#
287
# 
David Nowell's avatar
David Nowell committed
288
# aws s3 cp s3://umich-vdc-gitlab/gitback-config.20180620.tar /etc/gitlab/
289
# Be careful about this - It should all be in our Ansible playbook, so might not need it
David Nowell's avatar
David Nowell committed
290
291
# cd /etc/gitlab; tar -xf gitback-config.20180620.tar .
#
292
# 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
293
294
295
# 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
#
296
297
#
#
David Nowell's avatar
David Nowell committed
298
299
300
301
302
303
304
305
306
307
308
309
310
311
# 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
#
#