Compare commits

...
21 Commits
Author SHA1 Message Date
trey cd2fb6651f Moved playbooks here; zsh dotfiles distro; new config logs 2026-09-13 14:16:38 -04:00
trey 386e165f6b fixes: ghost image upgrades and smartctl exporter 2026-07-27 12:51:28 -04:00
trey b3fdf181a1 Add smartctl_exporter role 2026-07-22 04:28:20 -04:00
trey 1feb8f77cb Last commit of abandoned Claude check 2026-07-21 23:30:04 -04:00
trey 9b5af60157 Added logic and script to test for PKGBUILD poisoning 2026-06-20 17:23:40 -04:00
trey acaefd404c Initial commit after reviewing this with Claude Opus. 2026-06-08 10:14:50 -04:00
trey 16ae02bd33 Added jinja2 variable aur_helper 2026-05-18 08:36:59 -04:00
trey 93924970ba Added logic to only consider upgrade failed when it actually failed 2026-05-18 08:35:38 -04:00
trey a6947c3c55 Added task listing .pacnew files 2026-05-18 08:33:25 -04:00
trey 8e205d77ea Added task listing .pacnew files 2026-05-18 08:26:52 -04:00
trey 8aea5f0077 Refactored for proper docker and mailcow setup 2026-04-13 09:28:25 -04:00
trey d78a3d9133 Added build: always, so custom Dockerfile will be built 2026-04-13 09:27:01 -04:00
trey 29b1e5eb02 Initial commit of Docker and mailcow updates 2026-04-12 12:16:48 -04:00
trey c0e96f2543 Allowed python version check to run in check mode 2026-04-06 16:50:09 -04:00
trey 7104111ac4 Deleted non-role playbooks, and fixed up role tasks 2026-04-06 12:27:23 -04:00
trey 56a93411de Initial commit of roles-refactor branch 2026-04-06 10:13:20 -04:00
trey c5217c1a0f Added 'change_when: false' to Python version checks 2026-04-05 09:20:50 -04:00
trey b693daec8b Refactor to make more general 2026-03-19 23:57:36 -04:00
trey 2523ab8a28 Initial commit 2026-03-19 23:56:54 -04:00
trey f5c6d28095 Refactor to be a bit more modular 2026-03-11 14:15:40 -04:00
trey 601954fe7c Refactor to be a bit more modular 2026-03-11 14:15:04 -04:00
36 changed files with 841 additions and 105 deletions

No files matched your search

-26
View File
@@ -1,26 +0,0 @@
- name: All Arch hosts up-to-date
hosts: arch
tasks:
- name: Get current Python minor version
ansible.builtin.shell:
cmd: python --version | grep -Po '\d+\.\d+'
register: orig_python
- name: Full repository upgrade
become: true
community.general.pacman:
update_cache: true
upgrade: true
- name: Get new Python minor version
ansible.builtin.shell:
cmd: python --version | grep -Po '\d+\.\d+'
register: new_python
- name: AUR upgrade
aur:
use: pikaur
upgrade: true
aur_only: true
- import_tasks: ../tasks/aur_rebuild.yml
vars:
package_pattern: python
when:
- new_python.stdout is version(orig_python.stdout, '>', version_type='strict')
-14
View File
@@ -1,14 +0,0 @@
- name: Get list of AUR Python packages that need to be rebuilt
ansible.builtin.shell:
cmd:
comm -12 <(pactree -lrud1 {{ package_pattern }} | sort -u) <(pacman -Qqm | sort -u)
register: aur_packages
- name: Rebuild AUR Python packages
aur:
use: pikaur
name: '{{ item }}'
aur_only: true
extra_args: --rebuild
loop: '{{ aur_packages.stdout.split() }}'
-22
View File
@@ -1,22 +0,0 @@
- name: Create test script to determine if reboot is necessary
hosts: all
tasks:
- name: Create ~/bin if it doesn't already exist
ansible.builtin.shell:
cmd: mkdir ~/bin
args:
creates: ~/bin/
- name: Build needs_reboot
ansible.builtin.shell:
cmd: |
print '#!/usr/bin/env zsh' > needs_reboot
source ~/.zsh_functions
declare -f kernel_func >> needs_reboot
perl -pi -e 'if (/OK/) { $_ = "false\n" }' needs_reboot
perl -pi -e 'if (/needs reboot/) { $_ = "true\n" }' needs_reboot
printf "\n\n\nkernel_func\n" >> needs_reboot
chmod +x needs_reboot
args:
creates: needs_reboot
executable: /usr/bin/zsh
chdir: ~/bin/
-11
View File
@@ -1,11 +0,0 @@
- name: All Debian hosts up-to-date
hosts: debian
tasks:
- name: Full system upgrade
become: true
ansible.builtin.apt:
#executable: /usr/bin/pikaur
update_cache: true
name: "*"
state: latest
#upgrade: true
+12
View File
@@ -0,0 +1,12 @@
---
- name: Upgrade Arch systems
hosts: firewall
roles:
- arch_update
- dotfiles
- name: Process any reboots
hosts: "firewall, !control"
roles:
- reboot
+29
View File
@@ -0,0 +1,29 @@
---
- name: Upgrade Arch systems
hosts: arch
#strategy: free
roles:
- arch_update
- dotfiles
- name: Upgrade Debian systems
hosts: debian
roles:
- debian_update
- dotfiles
- name: Update Docker Stacks
hosts: docker
roles:
- docker_update
- name: Update mailcow Stacks
hosts: mailcow
roles:
- mailcow_update
- name: Process any reboots
hosts: "arch, debian, !control"
roles:
- reboot
-13
View File
@@ -1,13 +0,0 @@
kernel_func () {
machine_id=$(cat /etc/machine-id)
current_kernel=$(uname -r)
current_ucode=$(awk -F'[[:space:]]*:[[:space:]]*' '/microcode/ {print $2}' /proc/cpuinfo | uniq)
[[ -f /run/next_kernel ]] && next_kernel="$(sudo cat /run/next_kernel)"
next_ucode=$(iucode_tool -lqS /lib/firmware/intel-ucode/ | grep -Po 'rev 0x\d+' | tr -d '[rev ]' | tail -1)
if [[ "${current_kernel}" == ${next_kernel} ]] && [[ "${current_ucode}" == ${next_ucode} ]] || [[ -z "${next_kernel}" ]]
then
print -P "[%F{#00ff00}OK%f]"
else
print -P "[%F{yellow}needs reboot%f]"
fi
}
+5
View File
@@ -0,0 +1,5 @@
---
- name: Deploy node_exporter
hosts: arch,debian,barbican
roles:
- node_exporter
-13
View File
@@ -1,13 +0,0 @@
- name: Stop mollyguard if active
ansible.builtin.script: stop_mollyguard
register: mg
- name: Determine if a reboot is necessary
ansible.builtin.command:
cmd: ~/bin/needs_reboot
register: needs_reboot
- name: Conditionally reboot
ansible.builtin.reboot:
when:
- inventory_hostname not in group['controller']
- mgc succeeded
- needs_reboot succeeded
+2
View File
@@ -0,0 +1,2 @@
---
aur_helper: pikaur
+162
View File
@@ -0,0 +1,162 @@
#!/usr/bin/env python3
import urllib.request
import urllib.parse
import json
import subprocess
import os
import re
import tempfile
import sys
import shutil
def run_cmd(cmd, cwd=None):
return subprocess.run(cmd, cwd=cwd, stdout=subprocess.PIPE, stderr=subprocess.PIPE, text=True)
def get_local_foreign_packages():
res = run_cmd(['pacman', '-Qm'])
if res.returncode != 0:
return {}
pkgs = {}
for line in res.stdout.strip().split('\n'):
if line:
parts = line.split()
if len(parts) == 2:
pkgs[parts[0]] = parts[1]
return pkgs
def get_aur_info(pkgnames):
if not pkgnames:
return {}
results = {}
chunk_size = 100
pkgs = list(pkgnames)
for i in range(0, len(pkgs), chunk_size):
chunk = pkgs[i:i+chunk_size]
url = "https://aur.archlinux.org/rpc/v5/info?" + "&".join([f"arg[]={urllib.parse.quote(p)}" for p in chunk])
try:
req = urllib.request.urlopen(url, timeout=10)
data = json.loads(req.read().decode('utf-8'))
if data.get('type') == 'multiinfo':
for item in data.get('results', []):
results[item['Name']] = item
except Exception:
pass
return results
def needs_upgrade(local_ver, aur_ver):
res = run_cmd(['vercmp', local_ver, aur_ver])
try:
return int(res.stdout.strip()) < 0
except Exception:
return False
def extract_ver(content):
pkgver, pkgrel = None, None
for line in content.split('\n'):
line = line.strip()
if line.startswith('pkgver='):
pkgver = line.split('=', 1)[1].strip('"\'')
elif line.startswith('pkgrel='):
pkgrel = line.split('=', 1)[1].strip('"\'')
return pkgver, pkgrel
def strip_volatile_fields(content):
content = re.sub(r'^pkgver=.*$', '', content, flags=re.MULTILINE)
content = re.sub(r'^pkgrel=.*$', '', content, flags=re.MULTILINE)
content = re.sub(r'^arch=\(.*?\)', '', content, flags=re.MULTILINE | re.DOTALL)
source_vars = set()
source_matches = re.finditer(r'^source(?:_[a-zA-Z0-9_]+)?=\((.*?)\)', content, flags=re.MULTILINE | re.DOTALL)
for match in source_matches:
source_content = match.group(1)
vars_in_source = re.findall(r'\$(?:\{(_[a-zA-Z0-9_]+)\}|(_[a-zA-Z0-9_]+))', source_content)
for v1, v2 in vars_in_source:
if v1: source_vars.add(v1)
if v2: source_vars.add(v2)
for var in source_vars:
content = re.sub(r'^' + re.escape(var) + r'=.*$', '', content, flags=re.MULTILINE)
sum_patterns = [
r'md5sums', r'sha1sums', r'sha224sums', r'sha256sums',
r'sha384sums', r'sha512sums', r'b2sums', r'cksums'
]
for sp in sum_patterns:
pattern = r'^' + sp + r'(?:_[a-zA-Z0-9_]+)?=\(.*?\)'
content = re.sub(pattern, '', content, flags=re.MULTILINE | re.DOTALL)
lines = [line.rstrip() for line in content.split('\n') if line.strip()]
return '\n'.join(lines)
def main():
local_pkgs = get_local_foreign_packages()
if not local_pkgs:
sys.exit(0)
aur_info = get_aur_info(list(local_pkgs.keys()))
upgrades = []
for pkg, local_ver in local_pkgs.items():
if pkg in aur_info:
aur_ver = aur_info[pkg]['Version']
if needs_upgrade(local_ver, aur_ver):
upgrades.append((pkg, local_ver, aur_ver))
if not upgrades:
sys.exit(0)
print(f"Checking PKGBUILD diffs for {len(upgrades)} upgrades...")
temp_dir = tempfile.mkdtemp()
try:
for pkg, local_ver, aur_ver in upgrades:
print(f"Checking {pkg} ({local_ver} -> {aur_ver})")
repo_dir = os.path.join(temp_dir, pkg)
res = run_cmd(['git', 'clone', '--quiet', f'https://aur.archlinux.org/{pkg}.git', repo_dir])
if res.returncode != 0:
print(f"Failed to clone {pkg}", file=sys.stderr)
sys.exit(1)
res = run_cmd(['git', 'log', '--pretty=format:%H'], cwd=repo_dir)
commits = res.stdout.strip().split('\n')
old_pkgbuild_content = None
new_pkgbuild_content = None
with open(os.path.join(repo_dir, 'PKGBUILD'), 'r', encoding='utf-8', errors='ignore') as f:
new_pkgbuild_content = f.read()
local_ver_no_epoch = local_ver.split(':', 1)[-1]
parts = local_ver_no_epoch.rsplit('-', 1)
expected_ver, expected_rel = parts if len(parts) == 2 else (parts[0], "")
for commit in commits:
res = run_cmd(['git', 'show', f"{commit}:PKGBUILD"], cwd=repo_dir)
if res.returncode == 0:
content = res.stdout
p_ver, p_rel = extract_ver(content)
if p_ver == expected_ver and p_rel == expected_rel:
old_pkgbuild_content = content
break
if old_pkgbuild_content is None:
print(f"ERROR: Could not find old PKGBUILD for {pkg} version {local_ver}. Cannot safely verify diff.", file=sys.stderr)
sys.exit(1)
old_stripped = strip_volatile_fields(old_pkgbuild_content)
new_stripped = strip_volatile_fields(new_pkgbuild_content)
if old_stripped != new_stripped:
print(f"ERROR: Unsafe changes detected in PKGBUILD for {pkg}!", file=sys.stderr)
with open(os.path.join(temp_dir, 'old'), 'w') as f:
f.write(old_stripped)
with open(os.path.join(temp_dir, 'new'), 'w') as f:
f.write(new_stripped)
subprocess.run(['diff', '-u', os.path.join(temp_dir, 'old'), os.path.join(temp_dir, 'new')])
sys.exit(1)
finally:
shutil.rmtree(temp_dir)
if __name__ == '__main__':
main()
+17
View File
@@ -0,0 +1,17 @@
- name: Get list of AUR Python packages that need to be rebuilt
ansible.builtin.shell:
cmd:
comm -12 <(pactree -lrud1 {{ package_pattern }} | sort -u) <(pacman -Qqm | sort -u)
executable: /bin/bash
register: aur_packages
changed_when: false
failed_when: false
- name: Rebuild AUR Python packages
aur:
use: "{{ aur_helper }}"
name: '{{ item }}'
aur_only: true
extra_args: --rebuild
loop: '{{ aur_packages.stdout_lines | default([]) }}'
when: aur_packages.stdout_lines | default([]) | length > 0
+18
View File
@@ -0,0 +1,18 @@
---
- name: Check AUR package diffs for poisoning
ansible.builtin.script: aur_diff_check.py
changed_when: false
- name: AUR upgrade
aur:
use: "{{ aur_helper }}"
upgrade: true
aur_only: true
- name: Rebuild AUR Python packages if version changed
ansible.builtin.import_tasks: aur_rebuild.yaml
check_mode: false
vars:
package_pattern: python
when: new_python is version(orig_python, '>', version_type='strict')
+20
View File
@@ -0,0 +1,20 @@
---
- name: Get original Python version
ansible.builtin.include_tasks: python_check.yaml
vars:
target_var: orig_python
- name: Perform official repository updates
ansible.builtin.import_tasks: repo_upgrade.yaml
- name: Get new Python version
ansible.builtin.include_tasks: python_check.yaml
vars:
target_var: new_python
- name: Perform AUR updates and rebuilds
ansible.builtin.import_tasks: aur_upgrade.yaml
- name: Report on any .pacnew files that need to be merged
ansible.builtin.include_tasks: pacnew.yaml
+37
View File
@@ -0,0 +1,37 @@
- name: Check for pending .pacnew files
ansible.builtin.find:
paths: /etc
patterns: "*.pacnew"
recurse: yes
register: pacnew_files
- name: Ensure pacnew.logs directory exists locally
ansible.builtin.file:
path: "{{ playbook_dir }}/pacnew.logs"
state: directory
mode: '0755'
delegate_to: localhost
run_once: true
become: no
- name: Save .pacnew list to file
ansible.builtin.copy:
content: "{{ pacnew_files.files | map(attribute='path') | join('\n') }}\n"
dest: "{{ playbook_dir }}/pacnew.logs/{{ inventory_hostname }}.pacnew"
mode: '0644'
delegate_to: localhost
become: no
when: pacnew_files.matched > 0
- name: Clean up old .pacnew list file if no .pacnew files exist
ansible.builtin.file:
path: "{{ playbook_dir }}/pacnew.logs/{{ inventory_hostname }}.pacnew"
state: absent
delegate_to: localhost
become: no
when: pacnew_files.matched == 0
- name: Alert if .pacnew files exist
ansible.builtin.debug:
msg: "Warning: The following .pacnew files require merging: {{ pacnew_files.files | map(attribute='path') | list }}"
when: pacnew_files.matched > 0
+12
View File
@@ -0,0 +1,12 @@
---
- name: Run Python version command
ansible.builtin.shell:
cmd: python --version | grep -Po '\d+\.\d+'
register: _temp_python_version
changed_when: false
check_mode: false
- name: Assign version to dynamic variable
ansible.builtin.set_fact:
"{{ target_var }}": "{{ _temp_python_version.stdout }}"
+15
View File
@@ -0,0 +1,15 @@
---
- name: Perform full system upgrade
become: true
community.general.pacman:
update_cache: true
upgrade: true
extra_args: "--noconfirm"
register: arch_upgrade_result
failed_when:
- arch_upgrade_result.failed == true
- "'there is nothing to do' not in (arch_upgrade_result.stdout | default('') | lower)"
- name: Debug full Arch upgrade output
ansible.builtin.debug:
var: arch_upgrade_result
+42
View File
@@ -0,0 +1,42 @@
---
- name: Check for pending dpkg/ucf config files
ansible.builtin.find:
paths: /etc
patterns:
- "*.dpkg-dist"
- "*.dpkg-new"
- "*.ucf-dist"
- "*.ucf-new"
recurse: yes
register: debnew_files
- name: Ensure debnew.logs directory exists locally
ansible.builtin.file:
path: "{{ playbook_dir }}/debnew.logs"
state: directory
mode: '0755'
delegate_to: localhost
run_once: true
become: no
- name: Save debnew config list to file
ansible.builtin.copy:
content: "{{ debnew_files.files | map(attribute='path') | join('\n') }}\n"
dest: "{{ playbook_dir }}/debnew.logs/{{ inventory_hostname }}.debnew"
mode: '0644'
delegate_to: localhost
become: no
when: debnew_files.matched > 0
- name: Clean up old debnew config list file if none exist
ansible.builtin.file:
path: "{{ playbook_dir }}/debnew.logs/{{ inventory_hostname }}.debnew"
state: absent
delegate_to: localhost
become: no
when: debnew_files.matched == 0
- name: Alert if debnew config files exist
ansible.builtin.debug:
msg: "Warning: The following Debian config files require merging: {{ debnew_files.files | map(attribute='path') | list }}"
when: debnew_files.matched > 0
+9
View File
@@ -0,0 +1,9 @@
---
- name: Full system upgrade
become: true
ansible.builtin.apt:
update_cache: true
upgrade: full
- name: Report on any Debian config files that need to be merged
ansible.builtin.include_tasks: debnew.yaml
+26
View File
@@ -0,0 +1,26 @@
---
- name: Pre-build images to ensure base images are pulled
become: true
ansible.builtin.command:
cmd: docker compose build --pull
chdir: "{{ item }}"
loop: "{{ docker_compose_dirs | default([]) }}"
changed_when: false
register: _build_result
- name: Pull latest non-buildable service images
become: true
ansible.builtin.command:
cmd: docker compose pull --ignore-buildable --ignore-pull-failures
chdir: "{{ item }}"
loop: "{{ docker_compose_dirs | default([]) }}"
changed_when: false
- name: Update Docker Compose stacks
become: true
community.docker.docker_compose_v2:
project_src: "{{ item }}"
state: present
pull: never
build: always
loop: "{{ docker_compose_dirs | default([]) }}"
+12
View File
@@ -0,0 +1,12 @@
# Gruvbox colors for zsh (fallback)
export MATUGEN_PRIMARY="#83a598"
export MATUGEN_ON_PRIMARY="#282828"
export MATUGEN_SECONDARY="#8ec07c"
export MATUGEN_ON_SECONDARY="#282828"
export MATUGEN_TERTIARY="#d3869b"
export MATUGEN_ON_TERTIARY="#282828"
export MATUGEN_BACKGROUND="#282828"
export MATUGEN_FOREGROUND="#ebdbb2"
export MATUGEN_ERROR="#fb4934"
export MATUGEN_OUTLINE="#928374"
export MATUGEN_SURFACE_CONTAINER="#3c3836"
+20
View File
@@ -0,0 +1,20 @@
# Tmux colors generated by Matugen (Gruvbox fallback)
set -g status-justify "left"
set -g status "on"
set -g status-left-style "none"
set -g message-command-style "fg=#282828,bg=#83a598"
set -g status-right-style "none"
set -g pane-active-border-style "fg=#83a598"
set -g status-style "none,bg=#3c3836"
set -g message-style "fg=#282828,bg=#83a598"
set -g pane-border-style "fg=#504945"
set -g status-right-length "100"
set -g status-left-length "100"
setw -g window-status-activity-style "none"
setw -g window-status-separator ""
setw -g window-status-style "none,fg=#ebdbb2,bg=#3c3836"
set -g status-left "#[fg=#282828,bg=#83a598] #S #[fg=#83a598,bg=#3c3836,nobold,nounderscore,noitalics]"
set -g status-right "#[fg=#504945,bg=#3c3836,nobold,nounderscore,noitalics]#[fg=#ebdbb2,bg=#504945] %Y-%m-%d  %H:%M #[fg=#83a598,bg=#504945,nobold,nounderscore,noitalics]#[fg=#282828,bg=#83a598] #h "
setw -g window-status-format "#[fg=#ebdbb2,bg=#3c3836] #I #[fg=#ebdbb2,bg=#3c3836] #W "
setw -g window-status-current-format "#[fg=#3c3836,bg=#504945,nobold,nounderscore,noitalics]#[fg=#ebdbb2,bg=#504945] #I #[fg=#ebdbb2,bg=#504945] #W #[fg=#504945,bg=#3c3836,nobold,nounderscore,noitalics]"
+94
View File
@@ -0,0 +1,94 @@
---
- name: "Ensure target config directories exist for {{ target_user.user }}"
ansible.builtin.file:
path: "{{ item }}"
state: directory
mode: '0755'
owner: "{{ target_user.user }}"
loop:
- "{{ target_user.home }}/.config/tmux"
- "{{ target_user.home }}/.config/zsh"
- "{{ target_user.home }}/.vim"
become: yes
- name: "Sync tmux config directory for {{ target_user.user }}"
ansible.posix.synchronize:
src: /home/trey/.config/tmux/
dest: "{{ target_user.home }}/.config/tmux/"
archive: yes
delete: no
rsync_opts:
- "--exclude=matugen.conf"
become: yes
become_user: "{{ target_user.user }}"
- name: "Sync zsh config directory for {{ target_user.user }}"
ansible.posix.synchronize:
src: /home/trey/.config/zsh/
dest: "{{ target_user.home }}/.config/zsh/"
archive: yes
delete: no
rsync_opts:
- "--exclude=colors.zsh"
become: yes
become_user: "{{ target_user.user }}"
- name: "Sync vim directory for {{ target_user.user }}"
ansible.posix.synchronize:
src: /home/trey/.vim/
dest: "{{ target_user.home }}/.vim/"
archive: yes
delete: no
rsync_opts:
- "--exclude=.git/"
- "--exclude=.netrwhist"
- "--exclude=swap/"
- "--exclude=vimrc"
become: yes
become_user: "{{ target_user.user }}"
- name: "Deploy static fallback gruvbox colors for zsh for {{ target_user.user }}"
ansible.builtin.copy:
src: colors.zsh
dest: "{{ target_user.home }}/.config/zsh/colors.zsh"
mode: '0644'
owner: "{{ target_user.user }}"
become: yes
- name: "Deploy static fallback gruvbox colors for tmux for {{ target_user.user }}"
ansible.builtin.copy:
src: matugen.conf
dest: "{{ target_user.home }}/.config/tmux/matugen.conf"
mode: '0644'
owner: "{{ target_user.user }}"
become: yes
- name: "Copy .zshrc and modify prompt for root user"
ansible.builtin.copy:
content: |
{% set zshrc_content = lookup('file', '/home/trey/.zshrc') %}
{% if target_user.user == 'root' %}
{{ zshrc_content | replace("export PS1='%F{$MATUGEN_PRIMARY}%n%F{$MATUGEN_SECONDARY}@%F{$MATUGEN_TERTIARY}%m%f", "export PS1='%F{red}%m%f") }}
{% else %}
{{ zshrc_content }}
{% endif %}
dest: "{{ target_user.home }}/.zshrc"
mode: '0644'
owner: "{{ target_user.user }}"
become: yes
- name: "Copy vimrc without matugen for {{ target_user.user }}"
ansible.builtin.copy:
content: "{{ lookup('file', '/home/trey/.vim/vimrc') | regex_replace('(?m)^colorscheme matugen', 'colorscheme gruvbox') }}"
dest: "{{ target_user.home }}/.vim/vimrc"
mode: '0644'
owner: "{{ target_user.user }}"
become: yes
- name: "Ensure .vimrc symlink exists for {{ target_user.user }}"
ansible.builtin.file:
src: "{{ target_user.home }}/.vim/vimrc"
dest: "{{ target_user.home }}/.vimrc"
state: link
owner: "{{ target_user.user }}"
become: yes
+10
View File
@@ -0,0 +1,10 @@
---
- name: Deploy dotfiles for users
ansible.builtin.include_tasks: deploy_user.yml
loop:
- user: "{{ 'admin' if inventory_hostname == 'bastion' else 'trey' }}"
home: "{{ '/home/admin' if inventory_hostname == 'bastion' else '/home/trey' }}"
- user: 'root'
home: '/root'
loop_control:
loop_var: target_user
+19
View File
@@ -0,0 +1,19 @@
---
- name: Tear down Mailcow and main Docker stack(s) (LIFO)
become: true
community.docker.docker_compose_v2:
project_src: "{{ item }}"
state: absent
# Drops Mailcow first, THEN loops through your main stacks
loop: "{{ [mailcow_dir | default('/data/mailcow')] + (docker_compose_dirs | default([])) }}"
listen: Restart main Docker stack
- name: Bring main Docker stack(s) and Mailcow back up (FIFO)
become: true
community.docker.docker_compose_v2:
project_src: "{{ item }}"
state: present
# Brings your main stacks up first (recreating the network), THEN Mailcow
loop: "{{ (docker_compose_dirs | default([])) + [mailcow_dir | default('/data/mailcow')] }}"
listen: Restart main Docker stack
+25
View File
@@ -0,0 +1,25 @@
---
- name: Execute unattended Mailcow update
become: true
ansible.builtin.command:
cmd: ./update.sh --force
chdir: "{{ mailcow_dir | default('/data/mailcow') }}"
register: mailcow_first_pass
# Exit code 2 means "modules updated, run me again". Anything else is a real failure.
failed_when: mailcow_first_pass.rc not in [0, 2]
changed_when:
- mailcow_first_pass.rc == 0
- "'Updated code is available' in mailcow_first_pass.stdout or 'Pulling' in mailcow_first_pass.stdout or 'Upgrading' in mailcow_first_pass.stdout"
notify: Restart main Docker stack
- name: Re-run unattended Mailcow update (if modules changed)
become: true
ansible.builtin.command:
cmd: ./update.sh --force
chdir: "{{ mailcow_dir | default('/data/mailcow') }}"
# Only trigger this second pass if the first pass threw the specific restart code
when: mailcow_first_pass.rc == 2
register: mailcow_second_pass
changed_when:
- "'Updated code is available' in mailcow_second_pass.stdout or 'Pulling' in mailcow_second_pass.stdout or 'Upgrading' in mailcow_second_pass.stdout"
notify: Restart main Docker stack
+15
View File
@@ -0,0 +1,15 @@
---
node_exporter_base_flags: >-
--collector.systemd
--collector.processes
--collector.tcpstat
--no-collector.infiniband
--no-collector.tapestats
--no-collector.zfs
# Disable ARP collector by default unless this is the bastion router in barbican
node_exporter_disable_arp: "{{ not (inventory_hostname == 'bastion' and 'barbican' in group_names) }}"
node_exporter_flags: >-
{{ node_exporter_base_flags }}
{% if node_exporter_disable_arp %}--no-collector.arp{% endif %}
+6
View File
@@ -0,0 +1,6 @@
---
- name: Restart node_exporter
ansible.builtin.systemd:
name: prometheus-node-exporter
state: restarted
become: true
+59
View File
@@ -0,0 +1,59 @@
---
- name: Install node_exporter (Debian)
ansible.builtin.apt:
name: prometheus-node-exporter
state: present
when: ansible_facts["os_family"] == "Debian"
become: true
- name: Install node_exporter (Arch)
community.general.pacman:
name: prometheus-node-exporter
state: present
when: ansible_facts["os_family"] == "Archlinux"
become: true
- name: Configure node_exporter flags (Debian)
ansible.builtin.copy:
dest: /etc/default/prometheus-node-exporter
content: |
ARGS="{{ node_exporter_flags }}"
owner: root
group: root
mode: '0644'
when: ansible_facts["os_family"] == "Debian"
become: true
notify: Restart node_exporter
- name: Configure node_exporter flags (Arch)
ansible.builtin.copy:
dest: /etc/conf.d/prometheus-node-exporter
content: |
NODE_EXPORTER_ARGS="{{ node_exporter_flags }}"
owner: root
group: root
mode: '0644'
when: ansible_facts["os_family"] == "Archlinux"
become: true
notify: Restart node_exporter
- name: Enable and start node_exporter service
ansible.builtin.systemd:
name: prometheus-node-exporter
state: started
enabled: true
become: true
- name: Populate service facts
ansible.builtin.service_facts:
- name: Open port 9100 for prometheus scraping
ansible.posix.firewalld:
port: 9100/tcp
permanent: true
state: enabled
immediate: true
become: true
when: >
ansible_facts.services['firewalld.service'] is defined and
ansible_facts.services['firewalld.service'].state == 'running'
+94
View File
@@ -0,0 +1,94 @@
#!/usr/bin/env bash
# Exit code 0 = Reboot required
# Exit code 1 = System is up to date / No reboot needed
# 1. Branch based on detected distro
if [[ -f /etc/os-release ]]; then
source /etc/os-release
else
echo "Cannot determine OS."
exit 1
fi
# ==========================================
# DEBIAN LOGIC
# ==========================================
if [[ "$ID" == "debian" || "$ID_LIKE" == *"debian"* ]]; then
# Debian automatically creates this file when a kernel, microcode,
# or core library update requires a reboot.
if [[ -f /var/run/reboot-required ]]; then
exit 0
else
exit 1
fi
# ==========================================
# ARCH LINUX LOGIC
# ==========================================
elif [[ "$ID" == "arch" || "$ID_LIKE" == *"arch"* ]]; then
# --- KERNEL CHECK ---
# Get the currently running kernel version
current_kernel=$(uname -r)
# Determine the installed kernel package based on the running kernel's name
# e.g., "6.1.60-1-lts" -> "linux-lts", "6.5.9-arch1-1" -> "linux"
if [[ "$current_kernel" == *"-lts" ]]; then
kernel_pkg="linux-lts"
elif [[ "$current_kernel" == *"-zen" ]]; then
kernel_pkg="linux-zen"
elif [[ "$current_kernel" == *"-hardened" ]]; then
kernel_pkg="linux-hardened"
else
kernel_pkg="linux"
fi
# Get the installed version from pacman.
# Note: pacman uses periods (6.5.9.arch1-1) while uname uses dashes (6.5.9-arch1-1).
# We strip the package name and format it to match `uname -r` for a clean comparison.
installed_kernel=$(pacman -Q "$kernel_pkg" | awk '{print $2}' | sed 's/\./-/g' | sed 's/-\([^-]*\)$/.\1/')
# In some UKI setups or specific Arch versions, the sed replacement above might not
# perfectly match `uname -r` format. A bulletproof fallback is checking if the
# modules directory for the currently running kernel has been removed by a pacman update.
if [[ ! -d "/usr/lib/modules/$current_kernel" ]]; then
exit 0
fi
# --- MICROCODE CHECK ---
# Check CPU vendor to determine which microcode package to look for
vendor=$(grep -m 1 'vendor_id' /proc/cpuinfo | awk '{print $3}')
if [[ "$vendor" == "GenuineIntel" ]]; then
ucode_pkg="intel-ucode"
elif [[ "$vendor" == "AuthenticAMD" ]]; then
ucode_pkg="amd-ucode"
else
ucode_pkg=""
fi
if [[ -n "$ucode_pkg" ]]; then
# Check if the microcode package was updated recently by looking at the
# build date of the installed package vs the boot time of the system.
# Get system boot time in seconds since epoch
boot_time=$(awk '{print int($1)}' /proc/uptime)
boot_epoch=$(( $(date +%s) - boot_time ))
# Get the install time of the microcode package
ucode_install_epoch=$(expac '%time' "$ucode_pkg" 2>/dev/null || echo 0)
# If the microcode was installed AFTER the system booted, reboot needed
if (( ucode_install_epoch > boot_epoch )); then
exit 0
fi
fi
# If we made it this far, neither kernel nor microcode triggered a reboot
exit 1
else
# Fallback for unsupported OS
exit 1
fi
+16
View File
@@ -0,0 +1,16 @@
---
- name: Temporarily stop Mollyguard to allow reboot
become: true
ansible.builtin.systemd:
name: mollyguard.service
state: stopped
listen: Reboot system
failed_when: false
- name: Execute System Reboot
become: true
ansible.builtin.reboot:
msg: "Reboot initiated by Ansible"
reboot_timeout: 600
listen: Reboot system
+12
View File
@@ -0,0 +1,12 @@
---
- name: Check if kernel or microcode update requires reboot
ansible.builtin.script: check_reboot.sh # Your script placed in files/
register: reboot_check
# Prevent Ansible from failing if the script returns false (exit code 1)
failed_when: false
# Trigger the handler ONLY if the script returns true (exit code 0)
changed_when: reboot_check.rc == 0
# Forces this specific task to run during a dry run
check_mode: false
notify: Reboot system
+21
View File
@@ -0,0 +1,21 @@
---
- name: Install smartctl_exporter (Debian)
ansible.builtin.apt:
name: prometheus-smartctl-exporter
state: present
when: ansible_facts["os_family"] == "Debian"
become: true
- name: Install smartctl_exporter (Arch)
aur:
name: prometheus-smartctl-exporter
use: "{{ aur_helper }}"
state: present
when: ansible_facts["os_family"] == "Archlinux"
- name: Enable and start smartctl_exporter service
ansible.builtin.systemd:
name: prometheus-smartctl-exporter
state: started
enabled: true
become: true
+5
View File
@@ -0,0 +1,5 @@
---
- name: Deploy smartctl_exporter
hosts: smartd
roles:
- smartctl_exporter
-6
View File
@@ -1,6 +0,0 @@
#!/bin/sh
if systemctl is-active mollyguard; then
systemctl stop mollyguard
fi
+27
View File
@@ -0,0 +1,27 @@
- name: Establish systemd-creds for use with multiple services
hosts: arch debian
become: true
vars_prompt:
- name: passphrase
prompt: "Enter password manager passphrase"
private: true
confirm: true
- name: creds_var
prompt: "Enter the environment variable where systemd will store the credential PATH"
private: false
- name: creds_name
prompt: "Enter the credential name"
private: false
tasks:
- name: Create shared systemd runtime override directory
ansible.builtin.command:
cmd: mkdir /etc/systemd/system/shared.d
creates: /etc/systemd/system/shared.d
- name: Create override
ansible.builtin.shell:
cmd: |
printf '%s' {{ passphrase | quote }} | (echo "[Service]"; systemd-creds encrypt --name={{ creds_name }} --pretty - -) >> /etc/systemd/system/shared.d/00-systemd-creds.conf
printf "Environment=%s=%%d/%s\n" {{ creds_var }} {{ creds_name }} >> /etc/systemd/system/shared.d/00-systemd-creds.conf
#creates: /etc/systemd/system/shared.d/00-systemd-creds.conf