aboutsummaryrefslogtreecommitdiffstats
path: root/roles/host
diff options
context:
space:
mode:
authorJan Tuomi <jan@jantuomi.fi>2026-05-17 13:35:43 +0300
committerJan Tuomi <jan@jantuomi.fi>2026-05-17 19:32:16 +0300
commitb38e910899bad2d6ae2049b599dcdd525420c53d (patch)
treec6b277aafe1e6e278368dc5ca25a4acd624b20d2 /roles/host
parentc1a39b7e43bed135cb1832b2b5da7c82bf7a4c78 (diff)
Fix postgres
Diffstat (limited to 'roles/host')
-rw-r--r--roles/host/tasks/main.yml126
-rw-r--r--roles/host/templates/etc_crontab.j26
-rw-r--r--roles/host/templates/usr_local_bin_logto.sh.j247
3 files changed, 80 insertions, 99 deletions
diff --git a/roles/host/tasks/main.yml b/roles/host/tasks/main.yml
index 7f2567c..d1f710e 100644
--- a/roles/host/tasks/main.yml
+++ b/roles/host/tasks/main.yml
@@ -16,7 +16,7 @@
- name: Install packages
package:
- name: "{{ item }}"
+ name: "{{ pkg_name }}"
state: present
loop:
- rsync
@@ -24,9 +24,13 @@
- jq
- curl
- bash
+ - git
- python
- py311-pip
+ - py311-wheel
- fastfetch
+ loop_control:
+ loop_var: pkg_name
- name: Set up sshd
template:
@@ -42,40 +46,6 @@
name: sshd
state: started
-- name: Deploy logto script
- template:
- src: usr_local_bin_logto.sh.j2
- dest: /usr/local/bin/logto
- owner: root
- group: wheel
- mode: "0755"
-
-- name: Check if pylogsentinel is installed
- shell: pip show pylogsentinel
- register: pylogsentinel_check
- failed_when: false
- changed_when: false
-
-- name: Install pylogsentinel
- shell: pip install pylogsentinel==0.3.0 --force --no-input
- when: pylogsentinel_check.rc != 0
-
-- name: Deploy pylogsentinel.conf
- template:
- src: usr_local_etc_pylogsentinel.conf.j2
- dest: /usr/local/etc/pylogsentinel.conf
- owner: root
- group: wheel
- mode: "0644"
-
-- name: Deploy pylogsentinel-batch-email.sh
- template:
- src: usr_local_bin_pylogsentinel-batch-email.sh.j2
- dest: /usr/local/bin/pylogsentinel-batch-email.sh
- owner: root
- group: wheel
- mode: "0755"
-
- name: Start syslogd
service:
name: syslogd
@@ -94,15 +64,6 @@
group: wheel
mode: "0644"
-- name: Set up crontab
- template:
- src: etc_crontab.j2
- dest: /etc/crontab
- owner: root
- group: wheel
- mode: "0644"
- notify: Restart cron
-
- name: Install .bashrc
copy:
src: root_bashrc
@@ -112,6 +73,15 @@
mode: "0644"
# Jail infrastructure
+- name: Fetch ports tree
+ shell: |
+ if [ ! -d /usr/ports/.git ]; then
+ git clone --depth 1 https://git.FreeBSD.org/ports.git /usr/ports
+ else
+ git -C /usr/ports pull --ff-only
+ fi
+ register: _ports_fetch
+ changed_when: "'Already up to date' not in _ports_fetch.stdout"
- name: Discover jail directories
find:
paths: "{{ playbook_dir }}/roles/jails"
@@ -148,15 +118,64 @@
- { name: "zroot/jails/templates" }
- { name: "zroot/jails/containers" }
- { name: "zroot/jails/volumes", mountpoint: "none" }
- - { name: "zroot/jails/volumes/goaccess_www", mountpoint: "/usr/local/jails/volumes/goaccess_www" }
- - { name: "zroot/jails/volumes/postgres_data", mountpoint: "/usr/local/jails/containers/postgres/var/db/postgres" }
- - { name: "zroot/jails/volumes/irc_thelounge", mountpoint: "/usr/local/jails/containers/irc_thelounge/var/db/thelounge" }
- - { name: "zroot/jails/volumes/taulubot", mountpoint: "/usr/local/jails/containers/taulubot/usr/local/taulubot/photos" }
- - { name: "zroot/jails/volumes/komga_data", mountpoint: "/usr/local/jails/containers/komga/root/.komga" }
+ - {
+ name: "zroot/jails/volumes/goaccess_www",
+ mountpoint: "/usr/local/jails/volumes/goaccess_www",
+ }
+ - {
+ name: "zroot/jails/volumes/postgres_data",
+ mountpoint: "/usr/local/jails/containers/postgres/var/db/postgres",
+ }
+ - {
+ name: "zroot/jails/volumes/irc_thelounge",
+ mountpoint: "/usr/local/jails/containers/irc_thelounge/var/db/thelounge",
+ }
+ - {
+ name: "zroot/jails/volumes/taulubot",
+ mountpoint: "/usr/local/jails/containers/taulubot/usr/local/taulubot/photos",
+ }
+ - {
+ name: "zroot/jails/volumes/komga_data",
+ mountpoint: "/usr/local/jails/containers/komga/root/.komga",
+ }
- { name: "zroot/storage", mountpoint: "/usr/local/jails/volumes/storage" }
+ - { name: "zroot/my-ports", mountpoint: "/usr/local/my-ports" }
loop_control:
label: "{{ item.name }}"
+- name: Sync custom ports tree to host
+ synchronize:
+ src: "{{ playbook_dir }}/ports/"
+ dest: /usr/local/my-ports/
+ delete: true
+ recursive: true
+ rsync_opts:
+ - "--exclude=work-*"
+
+- name: Install custom ports
+ shell: make -C /usr/local/my-ports/{{ item }} install clean BATCH=yes
+ loop:
+ - pylogsentinel
+ register: _port_install
+ failed_when: "_port_install.rc != 0 and 'already installed' not in _port_install.stdout"
+ changed_when: "'already installed' not in _port_install.stdout"
+
+- name: Deploy pylogsentinel.conf
+ template:
+ src: usr_local_etc_pylogsentinel.conf.j2
+ dest: /usr/local/etc/pylogsentinel.conf
+ owner: root
+ group: wheel
+ mode: "0644"
+
+- name: Deploy pylogsentinel-batch-email.sh
+ template:
+ src: usr_local_bin_pylogsentinel-batch-email.sh.j2
+ dest: /usr/local/bin/pylogsentinel-batch-email.sh
+ owner: root
+ group: wheel
+ mode: "0755"
+
- name: Create storage group
group:
name: storage
@@ -215,3 +234,12 @@
owner: root
group: wheel
mode: "0644"
+
+- name: Set up crontab
+ template:
+ src: etc_crontab.j2
+ dest: /etc/crontab
+ owner: root
+ group: wheel
+ mode: "0644"
+ notify: Restart cron
diff --git a/roles/host/templates/etc_crontab.j2 b/roles/host/templates/etc_crontab.j2
index de1f3c6..5cd0d86 100644
--- a/roles/host/templates/etc_crontab.j2
+++ b/roles/host/templates/etc_crontab.j2
@@ -22,11 +22,11 @@ PATH=/sbin:/bin:/usr/sbin:/usr/bin:/usr/local/sbin:/usr/local/bin
1,31 0-5 * * * root adjkerntz -a
# Take snapshots every day at 3:05 AM
-5 3 * * * root logto /var/log/backup /usr/local/bin/backup snapshot prune-local
+5 3 * * * root /usr/local/bin/backup snapshot prune-local >>/var/log/backup 2>&1
# Send backup snapshots to remote every third day at 4:05 AM
-5 4 */3 * * root logto /var/log/backup /usr/local/bin/backup send-to-remote prune-remote notify
+5 4 */3 * * root /usr/local/bin/backup send-to-remote prune-remote notify >>/var/log/backup 2>&1
-# Run pylogmonitor
+# Run pylogsentinel
*/10 * * * * root python -m pylogsentinel
# Run pylogsentinel batch job once a day
5 6 * * * root /usr/local/bin/pylogsentinel-batch-email.sh
diff --git a/roles/host/templates/usr_local_bin_logto.sh.j2 b/roles/host/templates/usr_local_bin_logto.sh.j2
deleted file mode 100644
index 9bb5aa1..0000000
--- a/roles/host/templates/usr_local_bin_logto.sh.j2
+++ /dev/null
@@ -1,47 +0,0 @@
-#!/bin/sh
-
-set -ue
-
-# Wrapper for logging to file and prepending a timestamp.
-# By default writes both stdout and stderr to the log file.
-
-usage() {
- echo "Usage: logto [-s|-e] <log_file> <command>"
- echo "Flags:"
- echo " -s: Write only stdout to the log file."
- echo " -e: Write only stderr to the log file."
- echo ""
- echo "Example usage:"
- echo " logto /var/log/my.log run some command"
- exit 1
-}
-
-mode="all"
-
-while getopts "se" opt; do
- case $opt in
- s) mode="stdout" ;;
- e) mode="stderr" ;;
- *) usage ;;
- esac
-done
-shift $((OPTIND-1))
-
-if [ $# -lt 2 ]; then
- usage
-fi
-
-log_file="$1"
-shift
-
-if [ "$mode" = "stdout" ]; then
- out=$(2>/dev/null $@)
-elif [ "$mode" = "stderr" ]; then
- out=$(2>&1 >/dev/null $@)
-else
- out=$(2>&1 $@)
-fi
-
-if [ ! -z "$out" ]; then
- echo "$(date +"%Y-%m-%dT%H:%M:%S%z")" "$out" >>"$log_file"
-fi