aboutsummaryrefslogtreecommitdiffstats
path: root/roles
diff options
context:
space:
mode:
authorEugene Triguba <hello@eugenetriguba.com>2026-10-03 11:41:33 -0700
committerEugene Triguba <hello@eugenetriguba.com>2026-10-11 18:36:45 -0700
commit024ae3365ffa40b5d0b117577c552587b258ca7a (patch)
treea2907f5a9018009e55b0d1690c3210844b74af30 /roles
downloadsite-configs-024ae3365ffa40b5d0b117577c552587b258ca7a.zip
Initial Commit
Diffstat (limited to 'roles')
-rw-r--r--roles/acme_client/defaults/main.yml1
-rw-r--r--roles/acme_client/files/httpd.d/acme.conf11
-rw-r--r--roles/acme_client/handlers/main.yml6
-rw-r--r--roles/acme_client/tasks/main.yml24
-rw-r--r--roles/acme_client/templates/acme-client.conf.j215
-rw-r--r--roles/obsd_cgit/defaults/main.yml3
-rw-r--r--roles/obsd_cgit/handlers/main.yml2
-rw-r--r--roles/obsd_cgit/meta/main.yml4
-rw-r--r--roles/obsd_cgit/tasks/main.yml29
-rw-r--r--roles/obsd_cgit/templates/cgitrc.j217
-rw-r--r--roles/obsd_cgit/templates/httpd.d/cgit.conf.j224
-rw-r--r--roles/obsd_git/defaults/main.yml4
-rw-r--r--roles/obsd_git/files/git-shell-commands/create27
-rw-r--r--roles/obsd_git/handlers/main.yml2
-rw-r--r--roles/obsd_git/tasks/main.yml59
-rw-r--r--roles/obsd_httpd/defaults/main.yml1
-rw-r--r--roles/obsd_httpd/handlers/main.yml2
-rw-r--r--roles/obsd_httpd/tasks/main.yml55
-rw-r--r--roles/obsd_httpd/templates/httpd.conf.j25
19 files changed, 291 insertions, 0 deletions
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 %}