From 000954f19c9547c97fb87cb49f546a959e736d14 Mon Sep 17 00:00:00 2001 From: Martin Michalec Date: Thu, 22 Oct 2026 23:25:11 +0300 Subject: feat: add gitolite --- provision.yml | 4 + roles/gitolite/defaults/main.yml | 3 + roles/gitolite/tasks/main.yml | 49 +++++++++ roles/gitolite/templates/gitconfig.j2 | 3 + roles/gitolite/templates/gitolite.rc.j2 | 179 ++++++++++++++++++++++++++++++++ 5 files changed, 238 insertions(+) create mode 100644 roles/gitolite/defaults/main.yml create mode 100644 roles/gitolite/tasks/main.yml create mode 100644 roles/gitolite/templates/gitconfig.j2 create mode 100644 roles/gitolite/templates/gitolite.rc.j2 diff --git a/provision.yml b/provision.yml index e7b6602..a5bd229 100644 --- a/provision.yml +++ b/provision.yml @@ -29,6 +29,10 @@ - role: fail2ban + - role: gitolite + vars: + admin_pubkey: "ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIJRy2xTx1XiYIsphsrJyZtQ3qguTFxwIfHOY+v7/j7yB martin@michalec.dev" + - role: acme_client vars: setup: true diff --git a/roles/gitolite/defaults/main.yml b/roles/gitolite/defaults/main.yml new file mode 100644 index 0000000..a818ae7 --- /dev/null +++ b/roles/gitolite/defaults/main.yml @@ -0,0 +1,3 @@ +--- +user: "git" +home: "/var/lib/{{ user }}" diff --git a/roles/gitolite/tasks/main.yml b/roles/gitolite/tasks/main.yml new file mode 100644 index 0000000..fa4b435 --- /dev/null +++ b/roles/gitolite/tasks/main.yml @@ -0,0 +1,49 @@ +--- +- block: + - name: Ensure gitolite package is installed + community.general.apk: + name: + - gitolite + state: present + + - name: Create gitolite system user ({{ user }}) + ansible.builtin.user: + name: "{{ user }}" + home: "{{ home }}" + shell: /bin/sh + create_home: true + system: true + + - name: Deploy admin SSH public key + ansible.builtin.copy: + content: "{{ admin_pubkey }}\n" + dest: "{{ home }}/admin.pub" + owner: "{{ user }}" + group: "{{ user }}" + mode: '0444' + + - name: Initialize gitolite setup for {{ user }} + ansible.builtin.command: + cmd: "gitolite setup -pk {{ home }}/admin.pub" + creates: "{{ home }}/.gitolite" + become: true + become_user: "{{ user }}" + + - name: Deploy .gitolite.rc + ansible.builtin.template: + src: "gitolite.rc.j2" + dest: "{{ home }}/.gitolite.rc" + owner: "{{ user }}" + group: "{{ user }}" + mode: '0444' + + - name: Deploy .gitconfig + ansible.builtin.template: + src: "gitconfig.j2" + dest: "{{ home }}/.gitconfig" + owner: "{{ user }}" + group: "{{ user }}" + mode: '0444' + + tags: + - gitolite diff --git a/roles/gitolite/templates/gitconfig.j2 b/roles/gitolite/templates/gitconfig.j2 new file mode 100644 index 0000000..ab5a8df --- /dev/null +++ b/roles/gitolite/templates/gitconfig.j2 @@ -0,0 +1,3 @@ +# {{ ansible_managed }} +[init] + defaultBranch = master diff --git a/roles/gitolite/templates/gitolite.rc.j2 b/roles/gitolite/templates/gitolite.rc.j2 new file mode 100644 index 0000000..e34f72b --- /dev/null +++ b/roles/gitolite/templates/gitolite.rc.j2 @@ -0,0 +1,179 @@ +# -*- Perl -*- +# {{ ansible_managed }} + +%RC = ( + UMASK => 0077, + GIT_CONFIG_KEYS => 'cgit\..*', + LOG_EXTRA => 1, + # logging options + # 1. leave this section as is for 'normal' gitolite logging (default) + # 2. uncomment this line to log ONLY to syslog: + # LOG_DEST => 'syslog', + # 3. uncomment this line to log to syslog and the normal gitolite log: + # LOG_DEST => 'syslog,normal', + # 4. prefixing "repo-log," to any of the above will **also** log just the + # update records to "gl-log" in the bare repo directory: + LOG_DEST => 'repo-log,normal', + # LOG_DEST => 'repo-log,syslog', + # LOG_DEST => 'repo-log,syslog,normal', + # syslog 'facility': defaults to 'local0', uncomment if needed. For example: + # LOG_FACILITY => 'local4', + + # roles. add more roles (like MANAGER, TESTER, ...) here. + # WARNING: if you make changes to this hash, you MUST run 'gitolite + # compile' afterward, and possibly also 'gitolite trigger POST_COMPILE' + ROLES => { + READERS => 1, + WRITERS => 1, + }, + + # enable caching (currently only Redis). PLEASE RTFM BEFORE USING!!! + # CACHE => 'Redis', + + # ------------------------------------------------------------------ + + # rc variables used by various features + + # the 'info' command prints this as additional info, if it is set + SITE_INFO => 'Please see https://git.cosmos.party for more help', + + # the CpuTime feature uses these + # display user, system, and elapsed times to user after each git operation + # DISPLAY_CPU_TIME => 1, + # display a warning if total CPU times (u, s, cu, cs) crosses this limit + # CPU_TIME_WARN_LIMIT => 0.1, + + # the Mirroring feature needs this + # HOSTNAME => "foo", + + # TTL for redis cache; PLEASE SEE DOCUMENTATION BEFORE UNCOMMENTING! + # CACHE_TTL => 600, + + # ------------------------------------------------------------------ + + # suggested locations for site-local gitolite code (see cust.html) + + # this one is managed directly on the server + LOCAL_CODE => "$ENV{HOME}/local", + + # or you can use this, which lets you put everything in a subdirectory + # called "local" in your gitolite-admin repo. For a SECURITY WARNING + # on this, see http://gitolite.com/gitolite/non-core.html#using-the-gitolite-admin-repo-to-manage-non-core-code + # LOCAL_CODE => "$rc{GL_ADMIN_BASE}/local", + + # ------------------------------------------------------------------ + + # List of commands and features to enable + + ENABLE => [ + + # COMMANDS + + # These are the commands enabled by default + 'help', + 'desc', + 'info', + 'perms', + 'writable', + + # Uncomment or add new commands here. + 'create', + 'fork', + 'mirror', + 'readme', + # 'sskm', + 'D', + 'config', + 'creator', + 'access', + 'motd', + 'option', + + # These FEATURES are enabled by default. + + # essential (unless you're using smart-http mode) + 'ssh-authkeys', + + # creates git-config entries from gitolite.conf file entries like 'config foo.bar = baz' + 'git-config', + + # creates git-daemon-export-ok files; if you don't use git-daemon, comment this out + 'daemon', + + # These FEATURES are disabled by default; uncomment to enable. If you + # need to add new ones, ask on the mailing list :-) + + # user-visible behaviour + + # prevent wild repos auto-create on fetch/clone + 'no-create-on-read', + # no auto-create at all (don't forget to enable the 'create' command!) + # 'no-auto-create', + + # access a repo by another (possibly legacy) name + 'Alias', + + # give some users direct shell access. See documentation in + # sts.html for details on the following two choices. + # "Shell $ENV{HOME}/.gitolite.shell-users", + # 'Shell alice bob', + + # set default roles from lines like 'option default.roles-1 = ...', etc. + # 'set-default-roles', + + # show more detailed messages on deny + 'expand-deny-messages', + + # show a message of the day + # 'Motd', + + # system admin stuff + + # enable mirroring (don't forget to set the HOSTNAME too!) + 'Mirroring', + + # allow people to submit pub files with more than one key in them + # 'ssh-authkeys-split', + + # selective read control hack + # 'partial-copy', + + # manage local, gitolite-controlled, copies of read-only upstream repos + # 'upstream', + + # updates 'description' file instead of 'gitweb.description' config item + 'cgit', + + # allow repo-specific hooks to be added + 'repo-specific-hooks', + + # performance, logging, monitoring... + + # be nice + 'renice 10', + + # log CPU times (user, system, cumulative user, cumulative system) + # 'CpuTime', + + # syntactic_sugar for gitolite.conf and included files + + # allow backslash-escaped continuation lines in gitolite.conf + # 'continuation-lines', + + # create implicit user groups from directory names in keydir/ + # 'keysubdirs-as-groups', + + # allow simple line-oriented macros + # 'macros', + + # Kindergarten mode + + # disallow various things that sensible people shouldn't be doing anyway + # 'Kindergarten', + ], + +); + +# ------------------------------------------------------------------------------ +# per perl rules, this should be the last line in such a file: +1; -- cgit v1.3.1