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 | |
| download | site-configs-024ae3365ffa40b5d0b117577c552587b258ca7a.zip | |
Initial Commit
25 files changed, 414 insertions, 0 deletions
@@ -0,0 +1,15 @@ +ISC License + +Copyright (c) 2026 Eugene Triguba + +Permission to use, copy, modify, and/or distribute this software for any +purpose with or without fee is hereby granted, provided that the above +copyright notice and this permission notice appear in all copies. + +THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH +REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY +AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, +INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM +LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR +OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR +PERFORMANCE OF THIS SOFTWARE. diff --git a/README.md b/README.md new file mode 100644 index 0000000..20edb57 --- /dev/null +++ b/README.md @@ -0,0 +1,22 @@ +# git.eugenetriguba.com Configurations + +This Ansible playbook sets up my git server at https://git.eugenetriguba.com. + +It is intended to be run against an OpenBSD server. It will then: +- Setup a web server with OpenBSD's `httpd` +- Setup a SSL certificate for the host with OpenBSD's `acme-client` and Let's + Encrypt +- Setup a git user to own the git data +- Setup cgit as the UI for the git data + +## Usage + +If you want to use this playbook for your own git server, you'll want to update +`inventory/git.yml` to give the details of your own server that you want to run +against. + +Once that is done, you may run: + +```sh +./bootstrap.sh +``` diff --git a/ansible.cfg b/ansible.cfg new file mode 100644 index 0000000..f522d9f --- /dev/null +++ b/ansible.cfg @@ -0,0 +1,8 @@ +[defaults] +inventory = inventory/git.yml +roles_path = roles +interpreter_python = auto_silent + +[privilege_escalation] +become = true +become_method = doas diff --git a/bootstrap.sh b/bootstrap.sh new file mode 100755 index 0000000..6fe4797 --- /dev/null +++ b/bootstrap.sh @@ -0,0 +1,56 @@ +#!/bin/sh +set -e + +PLAYBOOK_DIR="$(cd "$(dirname "$0")" && pwd)" +PLAYBOOK="${PLAYBOOK_DIR}/site.yml" + +main() { + ensure_ansible_installed + ensure_ansible_collections_installed + run_playbook "$@" +} + +ensure_ansible_installed() { + log_step "Checking for Ansible" + if ! bin_exists ansible-playbook; then + log_step "Installing Ansible" + if bin_exists brew; then + brew install ansible + else + log_err "brew (homebrew) not found. Unsupported package manager. Install Ansible manually." + exit 1 + fi + else + log_step "Ansible already installed" + fi +} + +ensure_ansible_collections_installed() { + log_step "Checking for required ansible collections" + if ! ansible-galaxy collection list 2>/dev/null | grep --quiet community.general; then + log_step "Installing required Ansible collections..." + ansible-galaxy collection install community.general + else + log_step "Ansible collections already installed" + fi +} + +run_playbook() { + log_step "Running playbook" + ansible-playbook --ask-become-pass "$PLAYBOOK" "$@" + log_step "Done!" +} + +bin_exists() { + command -v "$1" >/dev/null 2>&1 +} + +log_step() { + echo "==> $1" +} + +log_err() { + echo "[ERROR] $1" >&2 +} + +main "$@" diff --git a/inventory/git.yml b/inventory/git.yml new file mode 100644 index 0000000..5ae9041 --- /dev/null +++ b/inventory/git.yml @@ -0,0 +1,10 @@ +all: + hosts: + git.eugenetriguba.com: + acme_domain: git.eugenetriguba.com + cgit_domain: git.eugenetriguba.com + vars: + ansible_user: admin + ansible_python_interpreter: /usr/local/bin/python3 + git_authorized_keys: + - "ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABgQC31SiCeUZSJN3CueH6/+7UQvxwxkT/QkaDK6ZGdnkdpCWxRVp+0CTO4WG3u0PVEVd9DvSd81CEqrFaKxtKyiSh+4Va0A/mqY27tX7NZzEQLM/zLQrdESmaHY6EyQM0wlCtBKfNzuQqCa9QEw4TwkyMLOJzyI+bRsfeSHNCfxqnqGIMKKFiaF0ygakvQz57nWuKLOgqWsWkzFTuJKGI0OhefFBcZ4VzoCLV8i1zbB2AebhsmbyMza9OUF3px44atSM3o33Jto3gy7LTWtxU83NZU+wLEqY6IvcWx9BbSQZxAwEwXxUFmnzcX+FTkTiOs/Q2nXiLl2ggsGJffAq9Z1SGMCNGxT+Syyta5UtfBVVQdn6xtUxpppHwrdGC+TR8C5F9U12gsZRzvKkz0SSt5M4WHG2gna5rDgTisDbrEAsrqpmUqY9iSBzgAyk5xOi6fdI+r67gpjRSs+PNvDle3gImfIkPnEQg4eWJ54iKjfH+yd8vBk25T/ahu3J9rGgxp18= eugene@laptop" diff --git a/roles/acme_client/defaults/main.yml b/roles/acme_client/defaults/main.yml new file mode 100644 index 0000000..d530d0e --- /dev/null +++ b/roles/acme_client/defaults/main.yml @@ -0,0 +1 @@ +acme_domain: "{{ acme_domain }}" diff --git a/roles/acme_client/files/httpd.d/acme.conf b/roles/acme_client/files/httpd.d/acme.conf new file mode 100644 index 0000000..558a8bd --- /dev/null +++ b/roles/acme_client/files/httpd.d/acme.conf @@ -0,0 +1,11 @@ +server "{{ acme_domain }}" { + listen on * port 80 + location "/.well-known/acme-challenge/*" { + root "/acme" + request strip 2 + } + location * { + block return 302 "https://$HTTP_HOST$REQUEST_URI" + } +} + diff --git a/roles/acme_client/handlers/main.yml b/roles/acme_client/handlers/main.yml new file mode 100644 index 0000000..ca566a6 --- /dev/null +++ b/roles/acme_client/handlers/main.yml @@ -0,0 +1,6 @@ +- name: run acme-client + ansible.builtin.command: acme-client {{ acme_domain }} + changed_when: true + +- name: restart httpd + ansible.builtin.command: rcctl restart httpd diff --git a/roles/acme_client/tasks/main.yml b/roles/acme_client/tasks/main.yml new file mode 100644 index 0000000..54cd70c --- /dev/null +++ b/roles/acme_client/tasks/main.yml @@ -0,0 +1,24 @@ +- name: Deploy acme challenge vhost fragment + ansible.builtin.copy: + src: httpd.d/acme.conf + dest: "{{ httpd_conf_d | default('/etc/httpd.d') }}/acme.conf" + owner: root + group: wheel + mode: "0644" + notify: restart httpd + +- name: Deploy acme-client.conf + ansible.builtin.template: + src: acme-client.conf.j2 + dest: /etc/acme-client.conf + owner: root + group: wheel + mode: "0600" + +- name: Flush handlers so httpd restarts before issuing cert + ansible.builtin.meta: flush_handlers + +- name: Ensure certificates exist + ansible.builtin.command: acme-client {{ acme_domain }} + args: + creates: "/etc/ssl/{{ acme_domain }}.fullchain.pem" diff --git a/roles/acme_client/templates/acme-client.conf.j2 b/roles/acme_client/templates/acme-client.conf.j2 new file mode 100644 index 0000000..a9bccfc --- /dev/null +++ b/roles/acme_client/templates/acme-client.conf.j2 @@ -0,0 +1,15 @@ +authority letsencrypt { + api url "https://acme-v02.api.letsencrypt.org/directory" + account key "/etc/acme/letsencrypt-privkey.pem" +} + +authority letsencrypt-staging { + api url "https://acme-staging-v02.api.letsencrypt.org/directory" + account key "/etc/acme/letsencrypt-staging-privkey.pem" +} + +domain "{{ acme_domain }}" { + domain key "/etc/ssl/private/{{ acme_domain }}.key" + domain full chain certificate "/etc/ssl/{{ acme_domain }}.fullchain.pem" + sign with letsencrypt +} diff --git a/roles/obsd_cgit/defaults/main.yml b/roles/obsd_cgit/defaults/main.yml new file mode 100644 index 0000000..185edab --- /dev/null +++ b/roles/obsd_cgit/defaults/main.yml @@ -0,0 +1,3 @@ +cgit_domain: "{{ cgit_domain }}" +cgit_cache_dir: /var/www/cgit/cache +cgit_repos_dir: /var/www/pub/git diff --git a/roles/obsd_cgit/handlers/main.yml b/roles/obsd_cgit/handlers/main.yml new file mode 100644 index 0000000..3af955f --- /dev/null +++ b/roles/obsd_cgit/handlers/main.yml @@ -0,0 +1,2 @@ +- name: restart httpd + ansible.builtin.command: rcctl restart httpd diff --git a/roles/obsd_cgit/meta/main.yml b/roles/obsd_cgit/meta/main.yml new file mode 100644 index 0000000..13c7372 --- /dev/null +++ b/roles/obsd_cgit/meta/main.yml @@ -0,0 +1,4 @@ +dependencies: + - role: obsd_httpd + - role: acme_client + - role: obsd_git diff --git a/roles/obsd_cgit/tasks/main.yml b/roles/obsd_cgit/tasks/main.yml new file mode 100644 index 0000000..3bb2593 --- /dev/null +++ b/roles/obsd_cgit/tasks/main.yml @@ -0,0 +1,29 @@ +- name: Install cgit + community.general.openbsd_pkg: + name: cgit + state: present + +- name: Deploy cgit vhost fragment + ansible.builtin.template: + src: httpd.d/cgit.conf.j2 + dest: "{{ httpd_conf_d | default('/etc/httpd.d') }}/cgit.conf" + owner: root + group: wheel + mode: "0644" + notify: restart httpd + +- name: Deploy cgitrc + ansible.builtin.template: + src: cgitrc.j2 + dest: /var/www/conf/cgitrc + owner: www + group: daemon + mode: "0644" + +- name: Create cgit cache directory + ansible.builtin.file: + path: "{{ cgit_cache_dir }}" + state: directory + owner: www + group: daemon + mode: "0755" diff --git a/roles/obsd_cgit/templates/cgitrc.j2 b/roles/obsd_cgit/templates/cgitrc.j2 new file mode 100644 index 0000000..9633092 --- /dev/null +++ b/roles/obsd_cgit/templates/cgitrc.j2 @@ -0,0 +1,17 @@ +css=/cgit.css +logo=/cgit.png + +enable-git-config=1 + +cache-root={{ cgit_cache_dir }} +cache-size=1000 + +# Set the title and heading of the repository index page +root-title=Eugene Triguba's Git Repositories + +## Search for these files in the root of the default branch of repositories +## for coming up with the about page: +readme=:README + +virtual-root=/ +scan-path={{ cgit_repos_dir }} diff --git a/roles/obsd_cgit/templates/httpd.d/cgit.conf.j2 b/roles/obsd_cgit/templates/httpd.d/cgit.conf.j2 new file mode 100644 index 0000000..a7d0385 --- /dev/null +++ b/roles/obsd_cgit/templates/httpd.d/cgit.conf.j2 @@ -0,0 +1,24 @@ +server "{{ cgit_domain }}" { + listen on egress tls port 443 + tls { + certificate "/etc/ssl/{{ cgit_domain }}.fullchain.pem" + key "/etc/ssl/private/{{ cgit_domain }}.key" + } + + # Serve cgit static files (cgit.css, cgit.png) directly from disk + location "/cgit.*" { + root "/cgit" + no fastcgi + } + + # Explicitly route root (/) to cgit via fastcgi + location "/" { + root "/cgi-bin/cgit.cgi" + fastcgi socket "/run/slowcgi.sock" + } + + # Route any other cgit paths/actions via fastcgi + root "/cgi-bin/cgit.cgi" + fastcgi socket "/run/slowcgi.sock" +} + 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" diff --git a/roles/obsd_httpd/defaults/main.yml b/roles/obsd_httpd/defaults/main.yml new file mode 100644 index 0000000..48406cb --- /dev/null +++ b/roles/obsd_httpd/defaults/main.yml @@ -0,0 +1 @@ +httpd_conf_d: /etc/httpd.d diff --git a/roles/obsd_httpd/handlers/main.yml b/roles/obsd_httpd/handlers/main.yml new file mode 100644 index 0000000..3af955f --- /dev/null +++ b/roles/obsd_httpd/handlers/main.yml @@ -0,0 +1,2 @@ +- name: restart httpd + ansible.builtin.command: rcctl restart httpd diff --git a/roles/obsd_httpd/tasks/main.yml b/roles/obsd_httpd/tasks/main.yml new file mode 100644 index 0000000..36ff9fb --- /dev/null +++ b/roles/obsd_httpd/tasks/main.yml @@ -0,0 +1,55 @@ +- name: Create httpd conf include directory + ansible.builtin.file: + path: "{{ httpd_conf_d }}" + state: directory + owner: root + group: wheel + mode: "0755" + +- name: Deploy httpd.conf + ansible.builtin.template: + src: httpd.conf.j2 + dest: /etc/httpd.conf + owner: root + group: wheel + mode: "0600" + notify: restart httpd + +- name: Ensure all registered httpd fragment files exist + # If they don't exist, httpd validate will fail. So we want to create them, + # even if empty for now. + ansible.builtin.copy: + content: "" + dest: "{{ httpd_conf_d }}/{{ item }}" + force: false # If it already exists, don't overwrite it. + owner: root + group: wheel + mode: "0644" + loop: "{{ httpd_fragments }}" + +- name: Validate httpd config + ansible.builtin.command: httpd -n + changed_when: false + +- name: Enable httpd and slowcgi + ansible.builtin.command: "rcctl enable {{ item }}" + args: + creates: "/etc/rc.conf.d/{{ item }}" + loop: + - httpd + - slowcgi + changed_when: true + +- name: Check service status + ansible.builtin.command: rcctl check {{ item }} + register: httpd_check + changed_when: false + failed_when: false # rc 1 exit code means "not running" + loop: + - httpd + - slowcgi + +- name: Start services that are not running + ansible.builtin.command: rcctl start {{ item.item }} + loop: "{{ httpd_check.results }}" + when: item.rc != 0 diff --git a/roles/obsd_httpd/templates/httpd.conf.j2 b/roles/obsd_httpd/templates/httpd.conf.j2 new file mode 100644 index 0000000..beec99c --- /dev/null +++ b/roles/obsd_httpd/templates/httpd.conf.j2 @@ -0,0 +1,5 @@ +types { include "/usr/share/misc/mime.types" } + +{% for fragment in httpd_fragments %} +include "{{ httpd_conf_d }}/{{ fragment }}" +{% endfor %} diff --git a/site.yml b/site.yml new file mode 100644 index 0000000..47a5f15 --- /dev/null +++ b/site.yml @@ -0,0 +1,12 @@ +- name: OpenBSD Git Server + hosts: all + become: true + vars: + httpd_fragments: + - acme.conf + - cgit.conf + roles: + - obsd_httpd + - acme_client + - obsd_git + - obsd_cgit |