Browse code

Administer gitolite directly on the server

Robert Cranston authored on 22/01/2021 21:17:37
Showing 3 changed files

... ...
@@ -2,8 +2,8 @@
2 2
 
3 3
 An [Ansible][] [role][] for deploying [gitolite][] on [Debian][] >=9.
4 4
 
5
-Installs [gitolite][] and creates a [dedicated user][] to run it (defaults to
6
-`git`).
5
+Installs [gitolite][], creates a [dedicated user][] to run it (defaults to
6
+`git`), and prepares for [administering gitolite directly on the server][].
7 7
 
8 8
 [`ansible-role-gitolite`]: https://git.rcrnstn.net/rcrnstn/ansible-role-gitolite
9 9
 [Ansible]: https://docs.ansible.com/ansible
... ...
@@ -11,6 +11,7 @@ Installs [gitolite][] and creates a [dedicated user][] to run it (defaults to
11 11
 [gitolite]: https://gitolite.com
12 12
 [Debian]: https://www.debian.org
13 13
 [dedicated user]: https://gitolite.com/gitolite/concepts#the-hosting-user
14
+[administering gitolite directly on the server]: https://gitolite.com/gitolite/odds-and-ends#administering-gitolite-directly-on-the-server
14 15
 
15 16
 ## Try out
16 17
 
17 18
new file mode 100644
... ...
@@ -0,0 +1,6 @@
1
+---
2
+
3
+- name: 'gitolite compile'
4
+  become: yes
5
+  become_user: "{{ gitolite_user_name }}"
6
+  shell: "gitolite compile ; gitolite trigger POST_COMPILE"
... ...
@@ -8,8 +8,47 @@
8 8
         name: 'gitolite3'
9 9
         state: 'present'
10 10
 
11
+      # https://docs.ansible.com/ansible/latest/user_guide/become.html#risks-of-becoming-an-unprivileged-user
12
+    - name: "Install acl"
13
+      apt:
14
+        name: 'acl'
15
+        state: 'present'
16
+
11 17
     - name: "Create gitolite user '{{ gitolite_user_name }}'"
12 18
       user:
13 19
         name: "{{ gitolite_user_name }}"
14 20
         home: "{{ gitolite_user_home }}"
15 21
         shell: "/bin/bash"
22
+
23
+- become: yes
24
+  become_user: "{{ gitolite_user_name }}"
25
+  vars:
26
+    default_repos:
27
+      - "gitolite-admin"
28
+      - "testing"
29
+  block:
30
+
31
+    - name: "Run dummy setup"
32
+      command:
33
+        cmd: "gitolite setup -a dummy"
34
+        creates: "{{ gitolite_user_home }}/.gitolite"
35
+
36
+    - name: "Remove directories of default repos"
37
+      file:
38
+        path: "{{ gitolite_user_home }}/repositories/{{ item }}.git"
39
+        state: 'absent'
40
+      notify: 'gitolite compile'
41
+      loop: "{{ default_repos }}"
42
+
43
+    - name: "Remove config of default repos"
44
+      replace:
45
+        path: "{{ gitolite_user_home }}/.gitolite/conf/gitolite.conf"
46
+        regexp: '^[ \t\n]*repo[ \t]+{{ item }}((?!^repo)(.|\n))*'
47
+      notify: 'gitolite compile'
48
+      loop: "{{ default_repos }}"
49
+
50
+    - name: "Create keydir"
51
+      file:
52
+        path: "{{ gitolite_user_home }}/.gitolite/keydir"
53
+        state: 'directory'
54
+      notify: 'gitolite compile'