diff options
| author | Eugene Triguba <hello@eugenetriguba.com> | 2026-10-03 11:41:33 -0700 |
|---|---|---|
| committer | Eugene Triguba <hello@eugenetriguba.com> | 2026-10-11 18:36:45 -0700 |
| commit | 024ae3365ffa40b5d0b117577c552587b258ca7a (patch) | |
| tree | a2907f5a9018009e55b0d1690c3210844b74af30 /roles/obsd_git | |
| download | site-configs-024ae3365ffa40b5d0b117577c552587b258ca7a.zip | |
Initial Commit
Diffstat (limited to 'roles/obsd_git')
| -rw-r--r-- | roles/obsd_git/defaults/main.yml | 4 | ||||
| -rw-r--r-- | roles/obsd_git/files/git-shell-commands/create | 27 | ||||
| -rw-r--r-- | roles/obsd_git/handlers/main.yml | 2 | ||||
| -rw-r--r-- | roles/obsd_git/tasks/main.yml | 59 |
4 files changed, 92 insertions, 0 deletions
diff --git a/roles/obsd_git/defaults/main.yml b/roles/obsd_git/defaults/main.yml new file mode 100644 index 0000000..19018f2 --- /dev/null +++ b/roles/obsd_git/defaults/main.yml @@ -0,0 +1,4 @@ +git_user: git +git_home: /var/www/pub/git +git_packages: + - git diff --git a/roles/obsd_git/files/git-shell-commands/create b/roles/obsd_git/files/git-shell-commands/create new file mode 100644 index 0000000..db38900 --- /dev/null +++ b/roles/obsd_git/files/git-shell-commands/create @@ -0,0 +1,27 @@ +#!/bin/sh +set -e + +main() { + repo="$1" + desc="$2" + if [ -z "$repo" ]; then + echo "Usage: provide a repository name" >&2 + exit 1 + fi + + repo_name=$(basename "$repo" .git) + repo_path="/var/www/pub/git/$repo_name.git" + + if [ ! -d "$repo_path" ]; then + echo "Creating bare repository: $repo_name.git" + git init --bare --initial-branch=main "$repo_path" + chown -R git:git "$repo_path" + + if [ -n "$desc" ]; then + # cgit will lookup the git repository description via the git config. + git -C "$repo_path" config gitweb.description "$desc" + fi + fi +} + +main "$@" diff --git a/roles/obsd_git/handlers/main.yml b/roles/obsd_git/handlers/main.yml new file mode 100644 index 0000000..3af955f --- /dev/null +++ b/roles/obsd_git/handlers/main.yml @@ -0,0 +1,2 @@ +- name: restart httpd + ansible.builtin.command: rcctl restart httpd diff --git a/roles/obsd_git/tasks/main.yml b/roles/obsd_git/tasks/main.yml new file mode 100644 index 0000000..a5d9e69 --- /dev/null +++ b/roles/obsd_git/tasks/main.yml @@ -0,0 +1,59 @@ +- name: Install git + community.general.openbsd_pkg: + name: "{{ git_packages }}" + state: present + +- name: Create git user + ansible.builtin.user: + name: "{{ git_user }}" + home: "{{ git_home }}" + shell: /usr/local/bin/git-shell + system: true + +- name: Create git home directory + ansible.builtin.file: + path: "{{ git_home }}" + state: directory + owner: "{{ git_user }}" + group: "{{ git_user }}" + mode: "0755" + +- name: Silence message of the day for git user + ansible.builtin.file: + path: "{{ git_home }}/.hushlogin" + state: touch + owner: "{{ git_user }}" + group: "{{ git_user }}" + mode: "0644" + +- name: Create .ssh directory + ansible.builtin.file: + path: "{{ git_home }}/.ssh" + state: directory + owner: "{{ git_user }}" + group: "{{ git_user }}" + mode: "0700" + +- name: Deploy authorized_keys + ansible.builtin.copy: + content: "{{ git_authorized_keys | join('\n') }}\n" + dest: "{{ git_home }}/.ssh/authorized_keys" + owner: "{{ git_user }}" + group: "{{ git_user }}" + mode: "0600" + +- name: Create git-shell-commands directory + ansible.builtin.file: + path: "{{ git_home }}/git-shell-commands" + state: directory + owner: "{{ git_user }}" + group: "{{ git_user }}" + mode: "0755" + +- name: Deploy git-shell create-repo helper script + ansible.builtin.copy: + src: git-shell-commands/create + dest: "{{ git_home }}/git-shell-commands/create" + owner: "{{ git_user }}" + group: "{{ git_user }}" + mode: "0755" |