Author SHA1 Message Date
kris 533dd40722 Upgrade Nextcloud setup to use compose files
- Integrated MariaDB role into Dockerbox configuration
- Moved proxy role to the end to avoid early endpoint activation
- Temporarily disabled select roles for future re-evaluation
- Introduced flush_handlers task for early MariaDB restart
- Moved a few Nextcloud tasks to handlers
- Configured Nextcloud to utilize the host's MariaDB instance
- Enhanced overall code linting quality
2024-04-21 21:45:33 -04:00
74 changed files with 305 additions and 2015 deletions
+2 -3
View File
@@ -3,9 +3,8 @@ name: homelab-ci
on:
push:
branches:
- github_actions
# - main
# - testing
- main
- testing
jobs:
homelab-ci:
+1 -2
View File
@@ -1,5 +1,4 @@
.ansible*
/environments/
.playbook
.vagrant*
.vscode
/environments/
Vendored
+5 -5
View File
@@ -9,16 +9,16 @@ if File.exist?(settings_path)
settings = YAML.load_file(settings_path)
end
VAGRANT_BOX = settings['VAGRANT_BOX'] || 'krislamo.org/debian13'
VAGRANT_BOX = settings['VAGRANT_BOX'] || 'debian/bookworm64'
VAGRANT_CPUS = settings['VAGRANT_CPUS'] || 2
VAGRANT_MEM = settings['VAGRANT_MEM'] || 2048
SSH_FORWARD = settings['SSH_FORWARD'] || false
# Default to shell environment variable: PLAYBOOK (priority #1)
playbook=ENV["PLAYBOOK"]
if !playbook || playbook.empty?
PLAYBOOK=ENV["PLAYBOOK"]
if !PLAYBOOK || PLAYBOOK.empty?
# PLAYBOOK setting in .vagrant.yml (priority #2)
playbook = settings['PLAYBOOK'] || 'default'
PLAYBOOK = settings['PLAYBOOK'] || 'default'
end
Vagrant.configure("2") do |config|
@@ -42,7 +42,7 @@ Vagrant.configure("2") do |config|
config.vm.provision "ansible" do |ansible|
ENV['ANSIBLE_ROLES_PATH'] = File.dirname(__FILE__) + "/roles"
ansible.compatibility_mode = "2.0"
ansible.playbook = "dev/" + playbook + ".yml"
ansible.playbook = "dev/" + PLAYBOOK + ".yml"
ansible.raw_arguments = ["--diff"]
end
end
+2 -2
View File
@@ -1,6 +1,6 @@
# base
base_allow_reboot: false
base_manage_network: false
allow_reboot: false
manage_network: false
# docker
docker_users:
+2 -2
View File
@@ -1,6 +1,6 @@
# base
base_allow_reboot: false
base_manage_network: false
allow_reboot: false
manage_network: false
# Import my GPG key for git signature verification
root_gpgkeys:
+3 -7
View File
@@ -1,15 +1,11 @@
# base
base_allow_reboot: false
base_manage_network: false
allow_reboot: false
manage_network: false
# Import my GPG key for git signature verification
root_gpgkeys:
- name: kris@lamoureux.io
id: 42A3A92C5DA0F3E5F71A3710105B748C1362EB96
# Older key, but still in use
- name: kris@lamoureux.io
id: FBF673CEEC030F8AECA814E73EDA9C3441EDA925
server: keyserver.ubuntu.com
# proxy
proxy:
@@ -37,7 +33,7 @@ docker_compose_deploy:
# Nextcloud
- name: nextcloud
url: https://github.com/krislamo/nextcloud
version: fe6d349749f178e91ae7ff726d557f48ebf84356
version: 0abc5cc6ba64ed94b7ddc6fd934f0fd62b8a6d11
env:
DATA: ./data
+2 -2
View File
@@ -1,6 +1,6 @@
# base
base_allow_reboot: false
base_manage_network: false
allow_reboot: false
manage_network: false
users:
git:
+2 -2
View File
@@ -1,8 +1,8 @@
debian_version: 10.5.0
# base
base_allow_reboot: false
base_manage_network: false
allow_reboot: false
manage_network: false
# libvirt
libvirt_users: vagrant
+2 -2
View File
@@ -1,8 +1,8 @@
base_domain: local.krislamo.org
# base
base_allow_reboot: false
base_manage_network: false
allow_reboot: false
manage_network: false
users:
jellyfin:
+2 -2
View File
@@ -1,6 +1,6 @@
# base
base_allow_reboot: false
base_manage_network: false
allow_reboot: false
manage_network: false
# minecraft
# Agree to EULA to start service in Vagrant
+2 -2
View File
@@ -1,6 +1,6 @@
# base
base_allow_reboot: false
base_manage_network: false
allow_reboot: false
manage_network: false
# docker
docker_users:
-60
View File
@@ -1,60 +0,0 @@
##############
#### base ####
##############
selinux:
state: enforcing
base_allow_reboot: true
base_manage_network: false
root_gpgkeys:
- id: 42A3A92C5DA0F3E5F71A3710105B748C1362EB96
scripts:
trusted_keys:
- id: 42A3A92C5DA0F3E5F71A3710105B748C1362EB96
repos:
- name: dotfiles
url: https://github.com/krislamo/dotfiles
version: 999d745710b9db500e82d1a0d0107ac5d623a669
scripts:
- src: gotify/.local/bin/gotify
dest: /usr/local/bin/gotify
################
#### proxy #####
################
proxy:
servers:
- domain: music.local.krislamo.org
proxy_pass: http://127.0.0.1:4533
################
#### podman ####
################
podman_label:
- path: /home/vagrant/navidrome
label: system_u:object_r:container_file_t:s0
owner: vagrant
group: vagrant
podman_compose:
vagrant:
root: /opt/oci
trusted_keys:
- id: 42A3A92C5DA0F3E5F71A3710105B748C1362EB96
compose:
- name: navidrome
url: https://github.com/krislamo/navidrome
version: 305f92cff143c0d497d21277145f605d9da830de
enabled: true
accept_newhostkey: true # Consider verifying manually instead
env:
VERSION: latest
BASEURL: https://music.local.krislamo.org
MUSIC: /home/vagrant/navidrome
LASTFM_ENABLED: "false"
LASTFM_APIKEY: "n/a"
LASTFM_SECRET: "n/a"
+2 -2
View File
@@ -1,8 +1,8 @@
base_domain: local.krislamo.org
# base
base_allow_reboot: false
base_manage_network: false
allow_reboot: false
manage_network: false
users:
git:
+2 -2
View File
@@ -1,6 +1,6 @@
# base
base_allow_reboot: false
base_manage_network: false
allow_reboot: false
manage_network: false
#mail:
# host: smtp.gmail.com
+2 -2
View File
@@ -1,6 +1,6 @@
# base
base_allow_reboot: false
base_manage_network: false
allow_reboot: false
manage_network: false
# UniFi version
unifi_version: 6.1.71
-92
View File
@@ -1,92 +0,0 @@
##############
#### base ####
##############
base_allow_reboot: true
base_manage_network: false
selinux:
state: enforcing
permissive_domains:
# logind drops its D-Bus connection under enforcing on trixie and never
# reconnects; pidfs/refpolicy gap. https://trello.com/c/x49s4EdL
- systemd_logind_t
users:
git:
uid: 1001
gid: 1001
home: true
system: true
bitwarden:
uid: 1002
gid: 1002
home: true
system: true
root_gpgkeys:
- name: kris@lamoureux.io
id: 42A3A92C5DA0F3E5F71A3710105B748C1362EB96
fail2ban_ignoreip:
- ::1
- 127.0.0.1/8
- 10.89.0.0/16
###############
#### proxy ####
###############
base_domain: local.krislamo.org
proxy:
servers:
- domain: "vault.{{ base_domain }}"
proxy_pass: "http://127.0.0.1:9080"
- domain: "git.{{ base_domain }}"
proxy_pass: "http://127.0.0.1:3000"
################
#### podman ####
################
podman_compose:
bitwarden:
root: /srv/bitwarden
api_keepalive: true
compose: []
git:
root: /opt/oci
trusted_keys:
- id: 42A3A92C5DA0F3E5F71A3710105B748C1362EB96
compose:
- name: gitea
url: https://github.com/krislamo/gitea
version: 84e5880484e803fdcf53c7f70b699988d28021d0
enabled: true
env:
DATA: "{{ gitea_data }}"
SSH_DIR: "{{ gitea_data }}/git/.ssh"
USER_UID: "{{ gitea_uid }}"
USER_GID: "{{ gitea_uid }}"
SE_LEVEL: "{{ gitea_se_level }}"
DOMAIN: "git.{{ base_domain }}"
PROXY_TRUSTED_PROXIES: "{{ gitea_trusted_proxies }}"
DB_HOST: "{{ gitea.DB_HOST }}"
DB_NAME: "{{ gitea.DB_NAME }}"
DB_USER: "{{ gitea.DB_USER }}"
DB_PASSWD: "{{ gitea.DB_PASSWD }}"
###################
#### bitwarden ####
###################
bitwarden:
domain: "vault.{{ base_domain }}"
install_id: 4ea840a3-532e-4cb6-a472-abd900728b23
install_key: 1yB3Z2gRI0KnnH90C6p
###############
#### gitea ####
###############
gitea:
DB_HOST: host.containers.internal
DB_NAME: gitea
DB_USER: gitea
DB_PASSWD: password
+3 -2
View File
@@ -1,6 +1,6 @@
# base
base_allow_reboot: false
base_manage_network: false
allow_reboot: false
manage_network: false
# docker
docker_users:
@@ -22,6 +22,7 @@ wordpress_multisite: true
# database settings
wordpress_dbversion: latest
wordpress_dbpass: password
# multisite (enable in admin panel then uncomment)
#wordpress_rule: "Host(`{{ wordpress_domain }}`) ||
# Host(`site1.{{ wordpress_domain }}`) ||
-9
View File
@@ -1,9 +0,0 @@
- name: Install Podman server
hosts: all
become: true
vars_files:
- host_vars/podman.yml
roles:
- base
- proxy
- podman
-12
View File
@@ -1,12 +0,0 @@
- name: Install VPS Server
hosts: all
become: true
vars_files:
- host_vars/vps.yml
roles:
- base
- proxy
- mariadb
- podman
- bitwarden
- gitea
+1 -1
View File
@@ -1,4 +1,4 @@
#!/usr/bin/env bash
#!/bin/bash
# Finds the SSH private key under ./.vagrant and connects to
# the Vagrant box, port forwarding localhost ports: 8443, 443, 80, 22
-1
View File
@@ -4,5 +4,4 @@
roles:
- base
- jenkins
- proxy
- docker
+3 -3
View File
@@ -3,9 +3,9 @@
become: true
roles:
- base
- jenkins
- docker
- mariadb
- traefik
- nextcloud
- proxy
- jenkins
- prometheus
- nginx
-7
View File
@@ -1,7 +0,0 @@
- name: Install Podman server
hosts: "{{ PLAYBOOK_HOST | default('none') }}"
become: true
roles:
- base
- proxy
- podman
-10
View File
@@ -1,10 +0,0 @@
- name: Install VPS Server
hosts: "{{ PLAYBOOK_HOST | default('none') }}"
become: true
roles:
- base
- proxy
- mariadb
- podman
- bitwarden
- gitea
+6 -11
View File
@@ -1,10 +1,10 @@
base_allow_reboot: true
base_manage_firewall: true
base_manage_network: false
base_network_type: static
base_locale_default: en_US.UTF-8
allow_reboot: true
manage_firewall: true
manage_network: false
network_type: static
locale_default: en_US.UTF-8
base_packages:
packages:
- apache2-utils
- cryptsetup
- curl
@@ -20,8 +20,3 @@ base_packages:
- tree
- vim
- wget
base_scripts: /srv/.scripts
base_ssh_ufw_rule: limit
base_swapfile_path: /swapfile
base_swap_sysctl_file: /etc/sysctl.d/70-swap.conf
+1 -3
View File
@@ -3,13 +3,11 @@
msg: "Reboot initiated by Ansible"
connect_timeout: 5
listen: reboot_host
when: base_allow_reboot
when: allow_reboot
- name: Reconfigure locales
ansible.builtin.command: dpkg-reconfigure -f noninteractive locales
changed_when: false
listen: reconfigure_locales
when: not ansible_check_mode
- name: Restart WireGuard
ansible.builtin.service:
+2 -13
View File
@@ -8,17 +8,6 @@
name: fail2ban
state: present
- name: Ensure Fail2ban's log file is correctly labelled
ansible.builtin.file:
path: /var/log/fail2ban.log
state: touch
mode: "0640"
access_time: preserve
modification_time: preserve
setype: fail2ban_log_t
when: selinux is defined and selinux is not false
notify: restart_fail2ban
- name: Deny incoming traffic by default
community.general.ufw:
default: deny
@@ -29,10 +18,10 @@
default: allow
direction: outgoing
- name: "{{ base_ssh_ufw_rule | capitalize }} OpenSSH"
- name: Allow OpenSSH with rate limiting
community.general.ufw:
name: ssh
rule: "{{ base_ssh_ufw_rule | default('limit') }}"
rule: limit
- name: Remove Fail2ban defaults-debian.conf
ansible.builtin.file:
+2 -7
View File
@@ -6,20 +6,15 @@
ansible.builtin.import_tasks: system.yml
tags: system
- name: Import swap tasks
ansible.builtin.import_tasks: swap.yml
tags: swap
when: swap is defined
- name: Import Firewall tasks
ansible.builtin.import_tasks: firewall.yml
tags: firewall
when: base_manage_firewall
when: manage_firewall
- name: Import Network tasks
ansible.builtin.import_tasks: network.yml
tags: network
when: base_manage_network
when: manage_network
- name: Import Mail tasks
ansible.builtin.import_tasks: mail.yml
+2 -2
View File
@@ -26,7 +26,7 @@
ansible.builtin.template:
src: smb.conf.j2
dest: /etc/samba/smb.conf
mode: "644"
mode: "700"
notify: restart_samba
- name: Start smbd and enable on boot
@@ -43,4 +43,4 @@
from: "{{ item }}"
state: enabled
loop: "{{ samba.firewall }}"
when: base_manage_firewall
when: manage_firewall
-117
View File
@@ -1,117 +0,0 @@
- name: Install the zram generator
ansible.builtin.apt:
name: systemd-zram-generator
state: present
register: base_zram_pkg
when: swap.zram | default({}) | length > 0
- name: Create the zram generator drop-in directory
ansible.builtin.file:
path: /etc/systemd/zram-generator.conf.d
state: directory
owner: root
group: root
mode: "0755"
when: swap.zram | default({}) | length > 0
- name: Configure zram swap devices
ansible.builtin.template:
src: zram-generator.conf.j2
dest: "/etc/systemd/zram-generator.conf.d/{{ item.key }}.conf"
owner: root
group: root
mode: "0644"
loop: "{{ swap.zram | default({}) | dict2items }}"
loop_control:
label: "{{ item.key }}"
register: base_zram_conf
- name: Reload systemd to run the zram generator
ansible.builtin.systemd_service:
daemon_reload: true
when: >-
base_zram_conf is changed
or base_zram_pkg is changed
- name: Start zram swap devices
ansible.builtin.systemd_service:
name: "systemd-zram-setup@{{ item.key }}.service"
state: started
loop: "{{ swap.zram | default({}) | dict2items }}"
loop_control:
label: "{{ item.key }}"
- name: Allocate the swapfile
ansible.builtin.command:
cmd: >-
dd if=/dev/zero of={{ base_swapfile_path }}
bs=1M count={{ swap.file.size_mb }}
creates: "{{ base_swapfile_path }}"
when: swap.file is defined
- name: Secure and label the swapfile
ansible.builtin.file:
path: "{{ base_swapfile_path }}"
owner: root
group: root
mode: "0600"
setype: >-
{{ (selinux is defined and selinux is not false)
| ternary('swapfile_t', omit) }}
when: swap.file is defined
- name: Check the swapfile for a swap signature
ansible.builtin.command:
cmd: "blkid -p -s TYPE -o value {{ base_swapfile_path }}"
register: base_swapfile_sig
changed_when: false
failed_when: false
when: swap.file is defined
- name: Format the swapfile
ansible.builtin.command:
cmd: "mkswap {{ base_swapfile_path }}"
register: base_mkswap
changed_when: base_mkswap.rc == 0
when:
- swap.file is defined
- (base_swapfile_sig.stdout | default('')) != 'swap'
- name: Add the swapfile to fstab
ansible.posix.mount:
path: none
src: "{{ base_swapfile_path }}"
fstype: swap
opts: "sw,pri={{ swap.file.priority | default(10) }}"
state: present
when: swap.file is defined
- name: List active swap devices
ansible.builtin.command:
cmd: swapon --show=NAME --noheadings
register: base_swap_active
changed_when: false
when: swap.file is defined
- name: Enable the swapfile
ansible.builtin.command:
cmd: >-
swapon --priority {{ swap.file.priority | default(10) }}
{{ base_swapfile_path }}
register: base_swapon
changed_when: base_swapon.rc == 0
when:
- swap.file is defined
- base_swapfile_path not in (base_swap_active.stdout_lines | default([]))
- name: Configure virtual memory sysctls
ansible.posix.sysctl:
name: "{{ item.key }}"
value: "{{ item.value }}"
sysctl_file: "{{ base_swap_sysctl_file }}"
sysctl_set: true
reload: true
state: present
loop: "{{ swap.sysctls | default({}) | dict2items }}"
loop_control:
label: "{{ item.key }}"
+7 -160
View File
@@ -1,68 +1,16 @@
- name: Install useful software
ansible.builtin.apt:
name: "{{ base_packages }}"
name: "{{ packages }}"
state: present
update_cache: true
- name: Get the default policy and basic SELinux utilities
ansible.builtin.apt:
name: ["selinux-basics", "selinux-policy-default", "auditd"]
state: present
when: selinux is defined and selinux is not false
- name: Configure SELinux
ansible.posix.selinux:
state: "{{ selinux.state | default('permissive') }}"
policy: "{{ selinux.policy | default('default') }}"
when: selinux is defined and selinux is not false
- name: Set SELinux permissive domains
community.general.selinux_permissive:
domain: "{{ item }}"
permissive: true
loop: "{{ selinux.permissive_domains | default([]) }}"
when: selinux is defined and selinux is not false
- name: Check for GRUB
ansible.builtin.stat:
path: /etc/default/grub
register: grub_config
when: selinux is defined and selinux is not false
- name: Check if SELinux is already activated in GRUB
ansible.builtin.command: grep -q 'security=selinux' /etc/default/grub
register: selinux_grub
changed_when: false
failed_when: false
when:
- selinux is defined
- selinux is not false
- grub_config.stat.exists
- name: Activate SELinux
ansible.builtin.command: selinux-activate
changed_when: true
when:
- selinux is defined
- selinux is not false
- grub_config.stat.exists
- selinux_grub.rc != 0
register: selinux_activated
- name: Reboot after SELinux activation
ansible.builtin.reboot:
when:
- selinux_activated is changed
- base_allow_reboot
- name: Install GPG
ansible.builtin.apt:
name: gpg
state: present
- name: Check for existing GPG keys
ansible.builtin.command: >-
gpg --list-keys {{ item.id }} 2>/dev/null
ansible.builtin.command: "gpg --list-keys {{ item.id }} 2>/dev/null"
register: gpg_check
loop: "{{ root_gpgkeys }}"
failed_when: false
@@ -70,9 +18,8 @@
when: root_gpgkeys is defined
- name: Import GPG keys
ansible.builtin.command: >-
gpg --keyserver {{ item.item.server | default('keys.openpgp.org') }}
--recv-key {{ item.item.id }}
ansible.builtin.command:
"gpg --keyserver {{ item.item.server | default('keys.openpgp.org') }} --recv-key {{ item.item.id }}"
register: gpg_check_import
loop: "{{ gpg_check.results }}"
loop_control:
@@ -86,85 +33,7 @@
loop: "{{ gpg_check_import.results }}"
loop_control:
label: "{{ item.item.item }}"
when:
- root_gpgkeys is defined
- not item.skipped | default(false)
- "'imported' not in item.stderr"
- name: Create scripts directories
ansible.builtin.file:
path: "{{ item }}"
state: directory
mode: "700"
owner: root
group: root
loop:
- "{{ base_scripts }}"
- "{{ base_scripts }}/.keys"
when: scripts is defined
- name: Generate OpenSSH deploy keys for script clones
community.crypto.openssh_keypair:
path: "{{ base_scripts }}/.keys/id_ed25519"
type: ed25519
comment: "{{ ansible_facts['hostname'] }}-deploy-key"
mode: "400"
state: present
when: scripts is defined
- name: Check for git installation
ansible.builtin.apt:
name: git
state: present
when: scripts is defined
- name: Clone external scripts projects
ansible.builtin.git:
repo: "{{ item.url }}"
dest: "{{ base_scripts }}/{{ item.name }}"
version: "{{ item.version }}"
accept_newhostkey: "{{ item.accept_newhostkey | default(false) }}"
gpg_allowlist: >-
{{ (item.trusted_keys | default(scripts.trusted_keys) | default([]))
| map(attribute='id')
| list }}
verify_commit: >-
{{ true if
((item.trusted_keys | default(scripts.trusted_keys)) is defined
and (item.trusted_keys | default(scripts.trusted_keys)))
else false }}
key_file: "{{ base_scripts }}/.keys/id_ed25519"
loop: "{{ scripts.repos }}"
loop_control:
label: "{{ item.url }}"
when: scripts is defined
tags: scripts
- name: Synchronize scripts
ansible.posix.synchronize:
src: "{{ base_scripts }}/{{ item.0.name }}/{{ item.1.src }}"
dest: "{{ item.1.dest }}"
delegate_to: "{{ inventory_hostname }}"
loop: "{{ scripts.repos | default([]) | subelements('scripts') }}"
loop_control:
label: "{{ item.0.name }}: {{ item.1.src }}"
when: scripts is defined and scripts | length > 0
tags: scripts
- name: Deploy cron jobs
ansible.builtin.cron:
name: "{{ item.name }}"
job: "{{ item.job }}"
user: "{{ item.user | default('root') }}"
minute: "{{ item.minute | default('*') }}"
hour: "{{ item.hour | default('*') }}"
day: "{{ item.day | default('*') }}"
month: "{{ item.month | default('*') }}"
weekday: "{{ item.weekday | default('*') }}"
state: "{{ item.state | default('present') }}"
disabled: "{{ item.disabled | default(false) }}"
loop: "{{ cron }}"
when: cron is defined and cron | length > 0
when: root_gpgkeys is defined and (not item.skipped | default(false)) and ('imported' not in item.stderr)
- name: Install NTPsec
ansible.builtin.apt:
@@ -178,7 +47,7 @@
- name: Generate locale
community.general.locale_gen:
name: "{{ base_locale_default }}"
name: "{{ locale_default }}"
state: present
notify: reconfigure_locales
@@ -186,7 +55,7 @@
ansible.builtin.lineinfile:
path: /etc/default/locale
regexp: "^LANG="
line: "LANG={{ base_locale_default }}"
line: "LANG={{ locale_default }}"
- name: Manage root authorized_keys
ansible.builtin.template:
@@ -194,7 +63,6 @@
dest: /root/.ssh/authorized_keys
mode: "400"
when: authorized_keys is defined
tags: users
- name: Create system user groups
ansible.builtin.group:
@@ -205,7 +73,6 @@
loop_control:
label: "{{ item.key }}"
when: users is defined
tags: users
- name: Create system users
ansible.builtin.user:
@@ -213,32 +80,13 @@
state: present
uid: "{{ item.value.uid }}"
group: "{{ item.value.gid }}"
groups: "{{ item.value.groups | default([]) }}"
shell: "{{ item.value.shell | default('/bin/bash') }}"
create_home: "{{ item.value.home | default(false) }}"
home: "{{ item.value.homedir | default('/home/' + item.key) }}"
system: "{{ item.value.system | default(false) }}"
loop: "{{ users | dict2items }}"
loop_control:
label: "{{ item.key }}"
when: users is defined
tags: users
- name: Create Ansible's temporary remote directory for users
ansible.builtin.file:
path: >-
{{ item.value.homedir | default('/home/' + item.key) }}/.ansible/tmp
state: directory
mode: "700"
owner: "{{ item.key }}"
group: "{{ item.value.gid }}"
loop: "{{ users | dict2items }}"
loop_control:
label: "{{ item.key }}"
when:
- users is defined
- item.value.tmp | default(true)
tags: users
- name: Set authorized_keys for system users
ansible.posix.authorized_key:
@@ -249,7 +97,6 @@
loop_control:
label: "{{ item.key }}"
when: users is defined and item.value.key is defined
tags: users
- name: Manage filesystem mounts
ansible.posix.mount:
-22
View File
@@ -18,28 +18,6 @@
src: /etc/wireguard/privatekey
register: wgkey
- name: Check if WireGuard preshared key file exists
ansible.builtin.stat:
path: /etc/wireguard/presharedkey-{{ item.name }}
loop: "{{ wireguard.peers }}"
loop_control:
label: "{{ item.name }}"
register: presharedkey_files
- name: Grab WireGuard preshared key for configuration
ansible.builtin.slurp:
src: /etc/wireguard/presharedkey-{{ item.item.name }}
register: wgshared
loop: "{{ presharedkey_files.results }}"
loop_control:
label: "{{ item.item.name }}"
when: item.stat.exists
- name: Grab WireGuard private key for configuration
ansible.builtin.slurp:
src: /etc/wireguard/privatekey
register: wgkey
- name: Install WireGuard configuration
ansible.builtin.template:
src: wireguard.j2
+1 -1
View File
@@ -1,7 +1,7 @@
[global]
workgroup = WORKGROUP
server string = Samba Server %v
netbios name = {{ ansible_facts['hostname'] }}
netbios name = {{ ansible_hostname }}
security = user
map to guest = bad user
dns proxy = no
+1 -32
View File
@@ -1,44 +1,13 @@
# {{ ansible_managed }}
[Interface] # {{ ansible_facts['hostname'] }}
[Interface]
PrivateKey = {{ wgkey['content'] | b64decode | trim }}
Address = {{ wireguard.address }}
{% if wireguard.listenport is defined %}
ListenPort = {{ wireguard.listenport }}
{% endif %}
{%- if wireguard.table is defined %}
Table = {{ wireguard.table }}
{% endif -%}
{%- if wireguard.postup is defined %}
PostUp = {{ wireguard.postup }}
{% endif -%}
{%- if wireguard.predown is defined %}
PreDown = {{ wireguard.predown }}
{% endif %}
{% for peer in wireguard.peers %}
{% if peer.name is defined %}
[Peer] # {{ peer.name }}
{% else %}
[Peer]
{% endif %}
PublicKey = {{ peer.publickey }}
{% if peer.presharedkey is defined %}
PresharedKey = {{ peer.presharedkey }}
{% else %}
{% set preshared_key = (
wgshared.results
| selectattr('item.item.name', 'equalto', peer.name)
| first
).content
| default(none)
%}
{% if preshared_key is not none %}
PresharedKey = {{ preshared_key | b64decode | trim }}
{% endif %}
{% endif %}
{% if peer.endpoint is defined %}
Endpoint = {{ peer.endpoint }}
{% endif %}
@@ -1,9 +0,0 @@
# Managed by Ansible
[{{ item.key }}]
zram-size = {{ item.value.size | default('ram') }}
compression-algorithm = {{ item.value.algorithm | default('zstd') }}
{% if item.value.writeback_device is defined %}
writeback-device = {{ item.value.writeback_device }}
{% endif %}
swap-priority = {{ item.value.priority | default(100) }}
fs-type = {{ item.value.fs_type | default('swap') }}
+4 -32
View File
@@ -1,36 +1,8 @@
bitwarden_name: bitwarden
bitwarden_user: "{{ bitwarden_name }}"
bitwarden_domain: "{{ bitwarden.domain }}"
bitwarden_install_id: "{{ bitwarden.install_id }}"
bitwarden_install_key: "{{ bitwarden.install_key }}"
bitwarden_puid: "{{ users[bitwarden_user].uid }}"
bitwarden_root: "{{ podman_compose[bitwarden_user].root }}"
bitwarden_data: "{{ bitwarden_root }}/bwdata"
bitwarden_script: "{{ bitwarden_root }}/bitwarden.sh"
bitwarden_logs: "{{ podman_log_root }}/{{ bitwarden_name }}"
bitwarden_logs_identity: "{{ bitwarden_logs }}/identity/Identity"
bitwarden_logs_identity_date: "{{ ansible_facts['date_time']['date'] | replace('-', '') }}"
bitwarden_root: "/var/lib/{{ bitwarden_name }}"
bitwarden_logs_identity: "{{ bitwarden_root }}/bwdata/logs/identity/Identity"
bitwarden_logs_identity_date: "{{ ansible_date_time.year }}{{ ansible_date_time.month }}{{ ansible_date_time.day }}"
bitwarden_database: "{{ bitwarden_name }}"
bitwarden_realips: "10.89.0.0/16"
bitwarden_realips: "172.16.0.0/12"
bitwarden_standalone: false
bitwarden_production: false
bitwarden_http_port: "127.0.0.1:9080"
bitwarden_https_port: "127.0.0.1:9443"
bitwarden_se_level: "s0:c33,c333"
bitwarden_se_opt: "label=level:{{ bitwarden_se_level }}"
bitwarden_services:
- mssql
- web
- attachments
- api
- identity
- sso
- admin
- icons
- notifications
- events
- nginx
bitwarden_env:
XDG_RUNTIME_DIR: "/run/user/{{ bitwarden_puid }}"
DBUS_SESSION_BUS_ADDRESS: "unix:path=/run/user/{{ bitwarden_puid }}/bus"
DOCKER_HOST: "unix:///run/user/{{ bitwarden_puid }}/podman/podman.sock"
-21
View File
@@ -1,21 +0,0 @@
module bitwarden 1.0;
require {
type container_t;
type container_file_t;
type container_ro_file_t;
type oci_log_t;
type unconfined_t;
class process ptrace;
class file { read getattr open lock ioctl write append create unlink setattr rename link map execmod };
class dir { read getattr search open lock ioctl write add_name remove_name create rmdir setattr rename reparent };
class lnk_file { read getattr create unlink rename };
}
allow container_t self:process ptrace;
allow container_t container_file_t:file execmod;
allow container_t container_ro_file_t:file execmod;
allow unconfined_t container_ro_file_t:file execmod;
allow container_t oci_log_t:dir { read getattr search open lock ioctl write add_name remove_name create rmdir setattr rename reparent };
allow container_t oci_log_t:file { read getattr open lock ioctl write append create unlink setattr rename link map };
allow container_t oci_log_t:lnk_file { read getattr create unlink rename };
+10 -25
View File
@@ -1,43 +1,28 @@
- name: Stop Bitwarden for rebuild
ansible.builtin.systemd:
ansible.builtin.service:
name: "{{ bitwarden_name }}"
state: stopped
scope: user
become: true
become_user: "{{ bitwarden_user }}"
environment: "{{ bitwarden_env }}"
listen: rebuild_bitwarden
- name: Rebuild Bitwarden
ansible.builtin.command: "{{ bitwarden_script }} rebuild"
become: true
become_user: "{{ bitwarden_user }}"
environment: "{{ bitwarden_env }}"
changed_when: true
listen: rebuild_bitwarden
- name: Relabel Bitwarden's data directory
ansible.builtin.command: "restorecon -RF {{ bitwarden_root }}"
changed_when: true
when: selinux is defined and selinux is not false
ansible.builtin.command: "{{ bitwarden_root }}/bitwarden.sh rebuild"
listen: rebuild_bitwarden
- name: Reload systemd manager configuration
ansible.builtin.systemd:
daemon_reload: true
scope: user
become: true
become_user: "{{ bitwarden_user }}"
environment: "{{ bitwarden_env }}"
listen: rebuild_bitwarden
- name: Start Bitwarden after rebuild
ansible.builtin.systemd:
ansible.builtin.service:
name: "{{ bitwarden_name }}"
state: started
enabled: true
scope: user
become: true
become_user: "{{ bitwarden_user }}"
environment: "{{ bitwarden_env }}"
listen: rebuild_bitwarden
- name: Create Bitwarden's initial log file
ansible.builtin.file:
path: "{{ bitwarden_logs_identity }}/{{ bitwarden_logs_identity_date }}.txt"
state: touch
mode: "644"
listen: touch_bitwarden
+27 -211
View File
@@ -3,275 +3,91 @@
name: expect
state: present
- name: Create Bitwarden's containers config directory
ansible.builtin.file:
path: "/home/{{ bitwarden_user }}/.config/containers"
state: directory
owner: "{{ bitwarden_user }}"
group: "{{ bitwarden_user }}"
mode: "0755"
- name: Configure keep-id user namespace for Bitwarden's containers
ansible.builtin.copy:
content: |
[containers]
userns = "keep-id"
dest: "/home/{{ bitwarden_user }}/.config/containers/containers.conf"
owner: "{{ bitwarden_user }}"
group: "{{ bitwarden_user }}"
mode: "0644"
notify: rebuild_bitwarden
- name: Set SELinux context on Bitwarden's root directory
community.general.sefcontext:
target: "{{ bitwarden_root }}(/.*)?"
setype: container_file_t
selevel: "{{ bitwarden_se_level }}"
state: present
when: selinux is defined and selinux is not false
- name: Set SELinux context on Bitwarden's logging directory
community.general.sefcontext:
target: "{{ bitwarden_logs }}(/.*)?"
setype: oci_log_t
selevel: "{{ bitwarden_se_level }}"
state: present
when: selinux is defined and selinux is not false
- name: Install Bitwarden SELinux policy source
ansible.builtin.copy:
src: bitwarden.te
dest: "{{ podman_selinux_dir }}/bitwarden.te"
owner: root
group: root
mode: "0644"
register: bitwarden_selinux_src
when: selinux is defined and selinux is not false
- name: Clear stale Bitwarden SELinux artifacts
ansible.builtin.file:
path: "{{ podman_selinux_dir }}/bitwarden.{{ item }}"
state: absent
loop: [mod, pp]
when:
- selinux is defined and selinux is not false
- bitwarden_selinux_src is changed
- name: Compile Bitwarden SELinux policy module
ansible.builtin.command:
cmd: >-
checkmodule -M -m -o {{ podman_selinux_dir }}/bitwarden.mod
{{ podman_selinux_dir }}/bitwarden.te
creates: "{{ podman_selinux_dir }}/bitwarden.mod"
when: selinux is defined and selinux is not false
- name: Package Bitwarden SELinux policy module
ansible.builtin.command:
cmd: >-
semodule_package -o {{ podman_selinux_dir }}/bitwarden.pp
-m {{ podman_selinux_dir }}/bitwarden.mod
creates: "{{ podman_selinux_dir }}/bitwarden.pp"
when: selinux is defined and selinux is not false
- name: List loaded SELinux policy modules for Bitwarden
ansible.builtin.command:
cmd: semodule -l
register: bitwarden_semodule_list
changed_when: false
when: selinux is defined and selinux is not false
- name: Load Bitwarden SELinux policy module
ansible.builtin.command:
cmd: semodule -i {{ podman_selinux_dir }}/bitwarden.pp
register: bitwarden_semodule
changed_when: bitwarden_semodule.rc == 0
when:
- selinux is defined and selinux is not false
- bitwarden_selinux_src is changed or "bitwarden" not in bitwarden_semodule_list.stdout_lines
notify: rebuild_bitwarden
- name: Create Bitwarden directory
ansible.builtin.file:
path: "{{ bitwarden_root }}"
state: directory
owner: "{{ bitwarden_user }}"
group: "{{ bitwarden_user }}"
mode: "0700"
setype: >-
{{ (selinux is defined and selinux is not false)
| ternary('container_file_t', omit) }}
selevel: "{{ bitwarden_se_level }}"
- name: Check whether the Bitwarden script is already installed
ansible.builtin.stat:
path: "{{ bitwarden_script }}"
register: bitwarden_script_stat
mode: "755"
- name: Download Bitwarden script
ansible.builtin.get_url:
url: "https://raw.githubusercontent.com/\
bitwarden/self-host/master/bitwarden.sh"
dest: "{{ bitwarden_script }}"
force: false
owner: "{{ bitwarden_user }}"
group: "{{ bitwarden_user }}"
mode: "0750"
setype: >-
{{ (selinux is defined and selinux is not false)
| ternary('container_file_t', omit) }}
selevel: "{{ bitwarden_se_level }}"
when: not bitwarden_script_stat.stat.exists
bitwarden/self-host/master/bitwarden.sh"
dest: "{{ bitwarden_root }}"
mode: u+x
- name: Install Bitwarden script wrapper
ansible.builtin.template:
src: bw_wrapper.j2
dest: "{{ bitwarden_root }}/bw_wrapper"
owner: "{{ bitwarden_user }}"
group: "{{ bitwarden_user }}"
mode: "0750"
setype: >-
{{ (selinux is defined and selinux is not false)
| ternary('container_file_t', omit) }}
selevel: "{{ bitwarden_se_level }}"
- name: Pin the SELinux level on newly downloaded run scripts
ansible.builtin.blockinfile:
path: "{{ bitwarden_script }}"
insertafter: '^\s*mv \$tmp_script \$SCRIPTS_DIR/run\.sh$'
marker: " # {mark} Ansible Managed: Add Bitwarden SELinux MCS level"
block: |2
sed -i \
"s|--name setup |&--security-opt {{ bitwarden_se_opt }} |g" \
"$SCRIPTS_DIR/run.sh"
when: selinux is defined and selinux is not false
- name: Give Bitwarden's setup container a writable working directory
ansible.builtin.blockinfile:
path: "{{ bitwarden_script }}"
insertafter: '^\s*mv \$tmp_script \$SCRIPTS_DIR/run\.sh$'
marker: " # {mark} Ansible Managed: Set Bitwarden's setup directory"
block: |2
sed -i \
"s|-it --rm --name setup |&-w /bitwarden |" \
"$SCRIPTS_DIR/run.sh"
mode: u+x
- name: Run Bitwarden installation script
ansible.builtin.command: "{{ bitwarden_root }}/bw_wrapper"
args:
creates: "{{ bitwarden_data }}/config.yml"
become: true
become_user: "{{ bitwarden_user }}"
environment: "{{ bitwarden_env }}"
- name: Pin the SELinux level on Bitwarden's setup container
ansible.builtin.replace:
path: "{{ bitwarden_data }}/scripts/run.sh"
regexp: "--name setup(?! --security-opt)"
replace: "--name setup --security-opt label=level:{{ bitwarden_se_level }}"
when: selinux is defined and selinux is not false
notify: rebuild_bitwarden
creates: "{{ bitwarden_root }}/bwdata/config.yml"
- name: Install compose override
ansible.builtin.template:
src: compose.override.yml.j2
dest: "{{ bitwarden_data }}/docker/docker-compose.override.yml"
owner: "{{ bitwarden_user }}"
group: "{{ bitwarden_user }}"
mode: "0640"
setype: >-
{{ (selinux is defined and selinux is not false)
| ternary('container_file_t', omit) }}
selevel: "{{ bitwarden_se_level }}"
dest: "{{ bitwarden_root }}/bwdata/docker/docker-compose.override.yml"
mode: "644"
when: bitwarden_override | default(true)
notify: rebuild_bitwarden
- name: Set bitwarden-nginx's HTTP port
- name: Disable bitwarden-nginx HTTP on 80
ansible.builtin.replace:
path: "{{ bitwarden_data }}/config.yml"
regexp: "^http_port: .*$"
replace: "http_port: {{ bitwarden_http_port }}"
path: "{{ bitwarden_root }}/bwdata/config.yml"
regexp: "^http_port: 80$"
replace: "http_port: {{ bitwarden_http_port | default('127.0.0.1:9080') }}"
when: not bitwarden_standalone
notify: rebuild_bitwarden
- name: Set bitwarden-nginx's HTTPS port
- name: Disable bitwarden-nginx HTTPS on 443
ansible.builtin.replace:
path: "{{ bitwarden_data }}/config.yml"
regexp: "^https_port: .*$"
replace: "https_port: {{ bitwarden_https_port }}"
path: "{{ bitwarden_root }}/bwdata/config.yml"
regexp: "^https_port: 443$"
replace: "https_port: {{ bitwarden_https_port | default('127.0.0.1:9443') }}"
when: not bitwarden_standalone
notify: rebuild_bitwarden
- name: Disable Bitwarden managed Lets Encrypt
ansible.builtin.replace:
path: "{{ bitwarden_data }}/config.yml"
regexp: "^ssl_managed_lets_encrypt: .*$"
path: "{{ bitwarden_root }}/bwdata/config.yml"
regexp: "^ssl_managed_lets_encrypt: true$"
replace: "ssl_managed_lets_encrypt: false"
when: not bitwarden_standalone or not bitwarden_production
notify: rebuild_bitwarden
- name: Disable Bitwarden managed SSL
ansible.builtin.replace:
path: "{{ bitwarden_data }}/config.yml"
regexp: "^ssl: .*$"
path: "{{ bitwarden_root }}/bwdata/config.yml"
regexp: "^ssl: true$"
replace: "ssl: false"
when: not bitwarden_standalone
notify: rebuild_bitwarden
- name: Define reverse proxy servers
ansible.builtin.lineinfile:
path: "{{ bitwarden_data }}/config.yml"
path: "{{ bitwarden_root }}/bwdata/config.yml"
line: "- {{ bitwarden_realips }}"
insertafter: "^real_ips"
notify: rebuild_bitwarden
- name: Create user systemd directory for Bitwarden
ansible.builtin.file:
path: "/home/{{ bitwarden_user }}/.config/systemd/user"
state: directory
owner: "{{ bitwarden_user }}"
group: "{{ bitwarden_user }}"
mode: "0755"
- name: Install Bitwarden systemd service
ansible.builtin.template:
src: bitwarden.service.j2
dest: "/home/{{ bitwarden_user }}/.config/systemd/user/{{ bitwarden_name }}.service"
owner: "{{ bitwarden_user }}"
group: "{{ bitwarden_user }}"
mode: "0644"
dest: "/etc/systemd/system/{{ bitwarden_name }}.service"
mode: "644"
register: bitwarden_systemd
notify: rebuild_bitwarden
- name: Create Bitwarden's initial logging directory
ansible.builtin.file:
path: "{{ bitwarden_logs_identity }}"
state: directory
owner: "{{ bitwarden_user }}"
group: "{{ bitwarden_user }}"
mode: "0755"
setype: >-
{{ (selinux is defined and selinux is not false)
| ternary('oci_log_t', omit) }}
selevel: "{{ bitwarden_se_level }}"
- name: Create Bitwarden's log file for Fail2ban
ansible.builtin.file:
path: "{{ bitwarden_logs_identity }}/{{ bitwarden_logs_identity_date }}.txt"
state: touch
owner: "{{ bitwarden_user }}"
group: "{{ bitwarden_user }}"
mode: "0644"
modification_time: preserve
access_time: preserve
setype: >-
{{ (selinux is defined and selinux is not false)
| ternary('oci_log_t', omit) }}
selevel: "{{ bitwarden_se_level }}"
- name: Install Bitwarden's Fail2ban filter
ansible.builtin.template:
src: fail2ban-filter.conf.j2
dest: /etc/fail2ban/filter.d/bitwarden.conf
mode: "0644"
notify: restart_fail2ban
mode: "755"
notify: touch_bitwarden
- name: Install Bitwarden's Fail2ban jail
ansible.builtin.template:
+6 -12
View File
@@ -1,19 +1,13 @@
[Unit]
Description=Bitwarden Password Manager Server
Requires=podman.socket
After=podman.socket
StartLimitIntervalSec=300
StartLimitBurst=5
PartOf=docker.service
After=docker.service
[Service]
Type=exec
Type=oneshot
RemainAfterExit=true
WorkingDirectory={{ bitwarden_root }}
Environment=DOCKER_HOST=unix://%t/podman/podman.sock
ExecStart={{ bitwarden_script }} start
ExecStop={{ bitwarden_script }} stop
Restart=on-failure
RestartSec=10
ExecStart={{ bitwarden_root }}/bitwarden.sh start
ExecStop={{ bitwarden_root }}/bitwarden.sh stop
[Install]
WantedBy=default.target
WantedBy=multi-user.target
@@ -1,16 +1,16 @@
# {{ ansible_managed }}
version: '3'
services:
{% for service in bitwarden_services %}
{{ service }}:
{% if service == 'nginx' %}
user: "0:0"
{% endif %}
{% if service == 'identity' %}
environment:
globalSettings__knownNetworks: "{{ bitwarden_realips }}"
volumes:
- {{ bitwarden_logs }}/identity:/etc/bitwarden/logs
{% endif %}
security_opt:
- label=level:{{ bitwarden_se_level }}
{% endfor %}
nginx:
networks:
- traefik
labels:
traefik.http.routers.bitwarden.rule: "Host(`{{ bitwarden_domain }}`)"
traefik.http.routers.bitwarden.entrypoints: {{ bitwarden_entrypoint | default('web') }}
traefik.http.routers.bitwarden.tls: {{ bitwarden_traefik_tls | default('false') }}
traefik.http.services.bitwarden.loadbalancer.server.port: 8080
traefik.docker.network: traefik
traefik.enable: "true"
networks:
traefik:
external: true
@@ -1,4 +0,0 @@
# {{ ansible_managed }}
[Definition]
failregex = Failed login attempt.*IpAddress: "<ADDR>"
ignoreregex =
@@ -2,7 +2,7 @@
[bitwarden]
enabled = true
filter = bitwarden
logpath = {{ bitwarden_logs_identity }}/*
logpath = {{ bitwarden_root }}/bwdata/logs/identity/Identity/*
maxretry = 10
findtime = 3600
bantime = 900
+12 -14
View File
@@ -24,21 +24,15 @@
- name: Install/uninstall Docker from Debian repositories
ansible.builtin.apt:
name: ["docker.io", "docker-compose", "containerd", "runc"]
name: ['docker.io', 'docker-compose', 'containerd', 'runc']
state: "{{ 'absent' if docker_official else 'present' }}"
autoremove: true
update_cache: true
- name: Install/uninstall Docker from Docker repositories
ansible.builtin.apt:
name:
[
"docker-ce",
"docker-ce-cli",
"containerd.io",
"docker-buildx-plugin",
"docker-compose-plugin",
]
name: ['docker-ce', 'docker-ce-cli', 'containerd.io',
'docker-buildx-plugin', 'docker-compose-plugin']
state: "{{ 'present' if docker_official else 'absent' }}"
autoremove: true
update_cache: true
@@ -77,7 +71,7 @@
community.crypto.openssh_keypair:
path: "{{ docker_repos_keys }}/id_{{ docker_repos_keytype }}"
type: "{{ docker_repos_keytype }}"
comment: "{{ ansible_facts['hostname'] }}-deploy-key"
comment: "{{ ansible_hostname }}-deploy-key"
mode: "400"
state: present
when: docker_compose_deploy is defined
@@ -101,7 +95,6 @@
loop_control:
label: "{{ item.url }}"
when: docker_compose_deploy is defined
tags: docker
- name: Create directories for docker-compose projects using the systemd service
ansible.builtin.file:
@@ -112,7 +105,6 @@
loop_control:
label: "{{ item.name }}"
when: docker_compose_deploy is defined
tags: docker
- name: Synchronize docker-compose.yml
ansible.posix.synchronize:
@@ -127,7 +119,6 @@
loop_control:
label: "{{ item.name }}"
when: docker_compose_deploy is defined and docker_compose_deploy | length > 0
tags: docker
- name: Set environment variables for docker-compose projects
ansible.builtin.template:
@@ -143,7 +134,14 @@
loop_control:
label: "{{ item.name }}"
when: docker_compose_deploy is defined and item.env is defined
tags: docker
- name: Add users to docker group
ansible.builtin.user:
name: "{{ item }}"
groups: docker
append: true
loop: "{{ docker_users }}"
when: docker_users is defined
- name: Start Docker and enable on boot
ansible.builtin.service:
+3 -10
View File
@@ -1,6 +1,6 @@
# container settings
gitea_name: gitea
gitea_sshport: "2222"
gitea_sshport: "222"
gitea_webport: "3000"
gitea_ssh: "127.0.0.1:{{ gitea_sshport }}"
gitea_web: "127.0.0.1:{{ gitea_webport }}"
@@ -13,17 +13,10 @@ gitea_dbtype: mysql
gitea_dbhost: host.docker.internal
gitea_dbname: "{{ gitea_name }}"
gitea_dbuser: "{{ gitea_name }}"
gitea_dbencoding: utf8mb4
gitea_dbcollation: utf8mb4_bin
# proxy settings
gitea_proxy_limit: "1"
gitea_trusted_proxies: "10.89.0.0/16"
gitea_trusted_proxies: "172.16.0.0/12"
# host
gitea_root: "{{ podman_compose.git.root }}/{{ gitea_name }}"
gitea_logs: "{{ podman_log_root }}/{{ gitea_name }}"
gitea_data: /srv/gitea
gitea_se_level: "s0:c22,c222"
gitea_uid: 1000
gitea_oci_uid: "{{ podman_subuid_base['git'] | int + gitea_uid | int - 1 }}"
gitea_root: "{{ docker_compose_root }}/{{ gitea_name }}"
-9
View File
@@ -1,9 +0,0 @@
module gitea_ssh 1.0;
require {
type sshd_t;
type ssh_exec_t;
class file { getattr read open map execute execute_no_trans };
}
allow sshd_t ssh_exec_t:file { getattr read open map execute execute_no_trans };
+5 -5
View File
@@ -1,5 +1,5 @@
- name: Reload ssh
ansible.builtin.systemd_service:
name: ssh
state: reloaded
listen: restart_ssh
- name: Restart Gitea
ansible.builtin.service:
name: "{{ docker_compose_service }}@{{ gitea_name }}"
state: restarted
listen: restart_gitea
+22 -177
View File
@@ -2,60 +2,54 @@
ansible.builtin.apt:
name: python3-pymysql
state: present
tags: gitea_db
- name: Create Gitea database
community.mysql.mysql_db:
name: "{{ gitea.DB_NAME }}"
state: present
encoding: "{{ gitea_dbencoding }}"
collation: "{{ gitea_dbcollation }}"
login_unix_socket: /var/run/mysqld/mysqld.sock
tags: gitea_db
- name: Create Gitea database user
community.mysql.mysql_user:
name: "{{ gitea.DB_USER }}"
password: "{{ gitea.DB_PASSWD }}"
host: "%"
host: '%'
state: present
priv: "{{ gitea.DB_NAME }}.*:ALL"
login_unix_socket: /var/run/mysqld/mysqld.sock
tags: gitea_db
- name: Create git's .ssh directory
ansible.builtin.file:
path: /home/git/.ssh
owner: git
group: git
mode: "700"
state: directory
setype: >-
{{ (selinux is defined and selinux is not false)
| ternary('ssh_home_t', omit) }}
- name: Generate git's SSH keys
community.crypto.openssh_keypair:
path: /home/git/.ssh/id_rsa
owner: git
group: git
mode: "600"
register: gitea_keypair
- name: Label git's SSH keys for sshd access
ansible.builtin.file:
path: "/home/git/.ssh/{{ item }}"
setype: >-
{{ (selinux is defined and selinux is not false)
| ternary('ssh_home_t', omit) }}
loop:
- id_rsa
- id_rsa.pub
- name: Find git's public SSH key
ansible.builtin.slurp:
src: /home/git/.ssh/id_rsa.pub
register: gitea_rsapub
register: git_rsapub
- name: Get stats on git's authorized_keys file
ansible.builtin.stat:
path: /home/git/.ssh/authorized_keys
register: git_authkeys
- name: Create git's authorized_keys file
ansible.builtin.file:
path: /home/git/.ssh/authorized_keys
mode: "600"
state: touch
when: not git_authkeys.stat.exists
- name: Add git's public SSH key to authorized_keys
ansible.builtin.lineinfile:
path: /home/git/.ssh/authorized_keys
regex: "^ssh-rsa"
line: "{{ git_rsapub['content'] | b64decode }}"
- name: Create Gitea host script for SSH
ansible.builtin.template:
@@ -63,147 +57,11 @@
dest: /usr/local/bin/gitea
mode: "755"
- name: Install Gitea SSH SELinux policy source
ansible.builtin.copy:
src: gitea_ssh.te
dest: "{{ podman_selinux_dir }}/gitea_ssh.te"
owner: root
group: root
mode: "0644"
register: gitea_selinux_src
when: selinux is defined and selinux is not false
- name: Clear stale Gitea SSH SELinux artifacts
ansible.builtin.file:
path: "{{ podman_selinux_dir }}/gitea_ssh.{{ item }}"
state: absent
loop: [mod, pp]
when:
- selinux is defined and selinux is not false
- gitea_selinux_src is changed
- name: Compile Gitea SSH SELinux policy module
ansible.builtin.command:
cmd: >-
checkmodule -M -m -o {{ podman_selinux_dir }}/gitea_ssh.mod
{{ podman_selinux_dir }}/gitea_ssh.te
creates: "{{ podman_selinux_dir }}/gitea_ssh.mod"
when: selinux is defined and selinux is not false
- name: Package Gitea SSH SELinux policy module
ansible.builtin.command:
cmd: >-
semodule_package -o {{ podman_selinux_dir }}/gitea_ssh.pp
-m {{ podman_selinux_dir }}/gitea_ssh.mod
creates: "{{ podman_selinux_dir }}/gitea_ssh.pp"
when: selinux is defined and selinux is not false
- name: List loaded SELinux policy modules for Gitea
ansible.builtin.command:
cmd: semodule -l
register: gitea_semodule_list
changed_when: false
when: selinux is defined and selinux is not false
- name: Load Gitea SSH SELinux policy module
ansible.builtin.command:
cmd: semodule -i {{ podman_selinux_dir }}/gitea_ssh.pp
register: gitea_semodule
changed_when: gitea_semodule.rc == 0
when:
- selinux is defined and selinux is not false
- gitea_selinux_src is changed or "gitea_ssh" not in gitea_semodule_list.stdout_lines
- name: Configure sshd for Gitea AuthorizedKeysCommand
ansible.builtin.template:
src: gitea_sshd.conf.j2
dest: /etc/ssh/sshd_config.d/gitea.conf
owner: root
group: root
mode: "0644"
validate: /usr/sbin/sshd -t -f %s
notify: restart_ssh
- name: Set SELinux context on Gitea's data directory
community.general.sefcontext:
target: "{{ gitea_data }}(/.*)?"
setype: container_file_t
selevel: "{{ gitea_se_level }}"
state: present
when: selinux is defined and selinux is not false
- name: Create Gitea's data directory
ansible.builtin.file:
path: "{{ gitea_data }}"
state: directory
owner: "{{ gitea_oci_uid }}"
group: "{{ gitea_oci_uid }}"
mode: "0750"
setype: >-
{{ (selinux is defined and selinux is not false)
| ternary('container_file_t', omit) }}
selevel: "{{ gitea_se_level }}"
- name: Create Gitea's container-side SSH directories
ansible.builtin.file:
path: "{{ item.path }}"
state: directory
owner: "{{ gitea_oci_uid }}"
group: "{{ gitea_oci_uid }}"
mode: "{{ item.mode }}"
setype: >-
{{ (selinux is defined and selinux is not false)
| ternary('container_file_t', omit) }}
selevel: "{{ gitea_se_level }}"
loop:
- { path: "{{ gitea_data }}/git", mode: "0755" }
- { path: "{{ gitea_data }}/git/.ssh", mode: "0700" }
- name: Authorise git's public SSH key inside the container
ansible.builtin.copy:
content: "{{ gitea_rsapub['content'] | b64decode }}"
dest: "{{ gitea_data }}/git/.ssh/authorized_keys"
owner: "{{ gitea_oci_uid }}"
group: "{{ gitea_oci_uid }}"
mode: "0600"
setype: >-
{{ (selinux is defined and selinux is not false)
| ternary('container_file_t', omit) }}
selevel: "{{ gitea_se_level }}"
- name: Set SELinux context on Gitea's logging directory
community.general.sefcontext:
target: "{{ gitea_logs }}(/.*)?"
setype: oci_log_t
selevel: "{{ gitea_se_level }}"
state: present
when: selinux is defined and selinux is not false
- name: Create Gitea's logging directory
ansible.builtin.file:
name: "{{ gitea_logs }}"
name: /var/log/gitea
state: directory
owner: "{{ gitea_oci_uid }}"
group: "{{ gitea_oci_uid }}"
mode: "0755"
setype: >-
{{ (selinux is defined and selinux is not false)
| ternary('oci_log_t', omit) }}
selevel: "{{ gitea_se_level }}"
- name: Create Gitea's log file for Fail2ban
ansible.builtin.file:
path: /var/log/oci/gitea/gitea.log
state: touch
owner: "{{ gitea_oci_uid }}"
group: "{{ gitea_oci_uid }}"
mode: "0640"
modification_time: preserve
access_time: preserve
setype: >-
{{ (selinux is defined and selinux is not false)
| ternary('oci_log_t', omit) }}
selevel: "{{ gitea_se_level }}"
mode: "755"
- name: Install Gitea's Fail2ban filter
ansible.builtin.template:
@@ -218,16 +76,3 @@
dest: /etc/fail2ban/jail.d/gitea.conf
mode: "640"
notify: restart_fail2ban
- name: Ensure Gitea's compose service is running
ansible.builtin.systemd:
name: compose@gitea
state: started
scope: user
become: true
become_user: git
vars:
gitea_project: >-
{{ podman_compose.git.compose
| selectattr('name', 'equalto', 'gitea') | first | default({}) }}
when: gitea_project.enabled | default(false)
+19
View File
@@ -0,0 +1,19 @@
# {{ ansible_managed }}
gitea_version={{ gitea_version }}
gitea_name={{ gitea_name }}
gitea_domain={{ gitea_domain }}
gitea_rooturl={{ gitea_rooturl }}
gitea_web={{ gitea_web }}
gitea_ssh={{ gitea_ssh }}
gitea_dbtype={{ gitea_dbtype }}
gitea_dbhost={{ gitea_dbhost }}
gitea_dbname={{ gitea_dbname }}
gitea_dbuser={{ gitea_dbuser }}
gitea_dbpass={{ gitea_dbpass }}
gitea_proxy_limit={{ gitea_proxy_limit }}
gitea_trusted_proxies={{ gitea_trusted_proxies }}
{% if not gitea_signup %}
gitea_disable_registration=true
{% else %}
gitea_disable_registration=false
{% endif %}
@@ -0,0 +1,36 @@
version: '3.7'
services:
gitea:
image: "gitea/gitea:${gitea_version}"
container_name: "${gitea_name}"
ports:
- "${gitea_ssh}:22"
- "${gitea_web}:3000"
extra_hosts:
- "host.docker.internal:host-gateway"
environment:
- USER_UID={{ getent_passwd.git[1] }}
- USER_GID={{ getent_group.git[1] }}
- GITEA__log__MODE=file
- GITEA__server__ROOT_URL=${gitea_rooturl}
- GITEA__server__DOMAIN=${gitea_domain}
- GITEA__server__SSH_DOMAIN=${gitea_domain}
- GITEA__database__DB_TYPE=${gitea_dbtype}
- GITEA__database__HOST=${gitea_dbhost}
- GITEA__database__NAME=${gitea_dbname}
- GITEA__database__USER=${gitea_dbuser}
- GITEA__database__PASSWD=${gitea_dbpass}
- GITEA__security__INSTALL_LOCK=true
- GITEA__security__REVERSE_PROXY_LIMIT=${gitea_proxy_limit}
- GITEA__security__REVERSE_PROXY_TRUSTED_PROXIES=${gitea_trusted_proxies}
- GITEA__service__DISABLE_REGISTRATION=${gitea_disable_registration}
volumes:
- {{ gitea_volume }}:/data
- /home/git/.ssh:/data/git/.ssh
- /var/log/gitea:/data/gitea/log
- /etc/timezone:/etc/timezone:ro
- /etc/localtime:/etc/localtime:ro
volumes:
{{ gitea_volume }}:
+10 -1
View File
@@ -2,8 +2,17 @@
[gitea]
enabled = true
filter = gitea
logpath = {{ gitea_logs }}/gitea.log
logpath = /var/log/gitea/gitea.log
maxretry = 10
findtime = 3600
bantime = 900
action = iptables-allports
[gitea-docker]
enabled = true
filter = gitea
logpath = /var/log/gitea/gitea.log
maxretry = 10
findtime = 3600
bantime = 900
action = iptables-allports[chain="FORWARD"]
-3
View File
@@ -1,3 +0,0 @@
# {{ ansible_managed }}
AuthorizedKeysCommand /usr/local/bin/gitea keys -e git -u %u -t %t -k %k
AuthorizedKeysCommandUser git
@@ -15,7 +15,7 @@ services:
networks:
- traefik
labels:
- "traefik.http.routers.{{ jellyfin_router }}.rule=Host({{ jellyfin_domains }})"
- "traefik.http.routers.{{ jellyfin_router }}.rule=Host(`{{ jellyfin_domain }}`)"
{% if traefik_http_only %}
- "traefik.http.routers.{{ jellyfin_router }}.entrypoints=web"
{% else %}
+31 -4
View File
@@ -1,13 +1,40 @@
- name: Install QEMU/KVM and libvirt
- name: Install QEMU/KVM
ansible.builtin.apt:
name: ["qemu-system", "libvirt-clients", "libvirt-daemon-system"]
install_recommends: false
name: qemu-kvm
state: present
- name: Install Libvirt
ansible.builtin.apt:
name: ["libvirt-clients", "libvirt-daemon-system"]
state: present
- name: Add users to libvirt group
ansible.builtin.user:
name: "{{ item }}"
groups: libvirt
append: true
append: yes
with_items: "{{ libvirt_users }}"
when: libvirt_users is defined
- name: Check for NODOWNLOAD file
ansible.builtin.stat:
path: /var/lib/libvirt/images/NODOWNLOAD
register: NODOWNLOAD
- name: Download GNU/Linux ISOs
ansible.builtin.get_url:
url: "{{ item.url }}"
dest: /var/lib/libvirt/images
checksum: "{{ item.hash }}"
owner: libvirt-qemu
group: libvirt-qemu
loop: "{{ libvirt_isos }}"
register: download_isos
when: libvirt_isos is defined and NODOWNLOAD.stat.exists == false
# Prevent downloaded ISOs from being rehashed every run
- name: Create NODOWNLOAD file
ansible.builtin.file:
path: /var/lib/libvirt/images/NODOWNLOAD
state: touch
when: download_isos.changed
+1 -13
View File
@@ -16,22 +16,10 @@
regex: "^bind-address"
line: "bind-address = {{ ansible_facts.docker0.ipv4.address }}"
notify: restart_mariadb
when: ansible_facts['docker0'] is defined
- name: Change the bind-address for rootless containers
ansible.builtin.lineinfile:
path: /etc/mysql/mariadb.conf.d/50-server.cnf
regexp: "^bind-address"
line: "bind-address = 0.0.0.0"
notify: restart_mariadb
when:
- ansible_facts['docker0'] is not defined
- podman_compose is defined
- name: Flush handlers to ensure MariaDB restarts immediately
ansible.builtin.meta: flush_handlers
tags: restart_mariadb
when: ansible_facts['docker0'] is defined or podman_compose is defined
- name: Allow database connections from Docker
community.general.ufw:
@@ -39,4 +27,4 @@
port: "3306"
proto: tcp
src: "{{ item }}"
loop: "{{ mariadb_trust | default(['169.254.0.0/16']) }}"
loop: "{{ mariadb_trust | default(['172.16.0.0/12']) }}"
+1 -1
View File
@@ -23,7 +23,7 @@
name: "{{ docker_compose_service }}@{{ nextcloud_name }}"
state: started
enabled: true
when: nextcloud.ENABLE | default(false)
when: nextcloud.ENABLE | default('false')
- name: Grab Nextcloud container information
community.general.docker_container_info:
-6
View File
@@ -1,6 +0,0 @@
# Default configuration for podman role
podman_log_root: /var/log/oci
podman_nodocker: false
podman_repos_keytype: ed25519
podman_selinux_dir: /usr/share/selinux
podman_ssh_key_path: "{{ ansible_user_dir }}/.ssh"
-22
View File
@@ -1,22 +0,0 @@
# shellcheck shell=sh
: "${UID:=$(id -u)}"
if [ "$UID" -ne 0 ]; then
if [ -z "$XDG_RUNTIME_DIR" ] && [ -d "/run/user/$UID" ]; then
XDG_RUNTIME_DIR="/run/user/$UID"
export XDG_RUNTIME_DIR
fi
PODMAN_SOCKET="$XDG_RUNTIME_DIR/podman/podman.sock"
if [ -S "$PODMAN_SOCKET" ]; then
DOCKER_HOST="unix://$PODMAN_SOCKET"
export DOCKER_HOST
fi
if [ -z "$DBUS_SESSION_BUS_ADDRESS" ]; then
if [ -S "$XDG_RUNTIME_DIR/bus" ]; then
DBUS_SESSION_BUS_ADDRESS="unix:path=$XDG_RUNTIME_DIR/bus"
export DBUS_SESSION_BUS_ADDRESS
fi
fi
fi
-19
View File
@@ -1,19 +0,0 @@
module oci_log 1.0;
require {
type container_t;
type fail2ban_t;
attribute logfile;
attribute file_type;
attribute non_security_file_type;
class dir { add_name search watch write };
class file { append create getattr open watch };
}
type oci_log_t;
typeattribute oci_log_t file_type, non_security_file_type, logfile;
allow container_t oci_log_t:dir { add_name search write };
allow container_t oci_log_t:file { append create getattr open };
allow fail2ban_t oci_log_t:dir watch;
allow fail2ban_t oci_log_t:file watch;
-19
View File
@@ -1,19 +0,0 @@
- name: Reload systemd manager configuration for all podman users
ansible.builtin.systemd:
daemon_reload: true
scope: user
become: true
become_user: "{{ item }}"
loop: "{{ podman_compose.keys() | list }}"
listen: podman_compose_systemd
- name: Restart docker compose (podman) services
ansible.builtin.systemd:
state: restarted
name: "compose@{{ item.service }}"
scope: user
become: true
become_user: "{{ item.user }}"
loop: "{{ podman_compose_restart_list | default([]) | unique }}"
when: podman_compose_restart_list is defined
listen: podman_compose_restart
-261
View File
@@ -1,261 +0,0 @@
- name: Get user info for podman compose user
ansible.builtin.getent:
database: passwd
key: "{{ podman_user }}"
register: podman_user_info
tags: podman_compose
- name: Set user-specific variables
ansible.builtin.set_fact:
podman_rootdir: "{{ podman_compose_config.root }}"
podman_userid: "{{ podman_user_info.ansible_facts.getent_passwd[podman_user][1] }}"
podman_homedir: "{{ podman_user_info.ansible_facts.getent_passwd[podman_user][4] }}"
podman_project: "{{ podman_compose_config.compose }}"
podman_repos: "{{ podman_compose_config.root }}/.compose_repos"
tags: podman_compose
- name: Create docker compose (podman) root directory for user
ansible.builtin.file:
path: "{{ podman_rootdir }}"
state: directory
owner: "{{ podman_user }}"
group: "{{ podman_user }}"
mode: "0700"
- name: Create user systemd directory
ansible.builtin.file:
path: "/home/{{ podman_user }}/.config/systemd/user"
state: directory
owner: "{{ podman_user }}"
group: "{{ podman_user }}"
mode: "0755"
- name: Create podman API service override directory for user
ansible.builtin.file:
path: "/home/{{ podman_user }}/.config/systemd/user/podman.service.d"
state: directory
owner: "{{ podman_user }}"
group: "{{ podman_user }}"
mode: "0755"
when: podman_compose_config.api_keepalive | default(false)
- name: Keep the podman API service alive for slow compose runs
ansible.builtin.copy:
content: |
# {{ lookup('ansible.builtin.config', 'DEFAULT_MANAGED_STR') }}
[Service]
ExecStart=
ExecStart=/usr/bin/podman $LOGGING system service --time=0
dest: >-
/home/{{ podman_user }}/.config/systemd/user/podman.service.d/timeout.conf
owner: "{{ podman_user }}"
group: "{{ podman_user }}"
mode: "0644"
when: podman_compose_config.api_keepalive | default(false)
notify: podman_compose_systemd
- name: Install docker compose (podman) systemd service for user
ansible.builtin.template:
src: compose.service.j2
dest: "/home/{{ podman_user }}/.config/systemd/user/compose@.service"
owner: "{{ podman_user }}"
group: "{{ podman_user }}"
mode: "0644"
notify: podman_compose_systemd
- name: Create directories for cloning docker compose (podman) repositories
ansible.builtin.file:
path: "{{ repo_dir }}"
state: directory
owner: "{{ podman_user }}"
group: "{{ podman_user }}"
mode: "0700"
loop:
- "{{ podman_repos }}"
loop_control:
loop_var: repo_dir
when:
- podman_project is defined
- podman_project | length > 0
tags: podman_compose
- name: Create .ssh directory for podman compose user
ansible.builtin.file:
path: "{{ podman_homedir }}/.ssh"
state: directory
owner: "{{ podman_user }}"
group: "{{ podman_user }}"
mode: "0700"
when:
- podman_project is defined
- podman_project | length > 0
tags: podman_compose
- name: Generate OpenSSH deploy keys for docker compose (podman) clones
community.crypto.openssh_keypair:
path: "{{ podman_homedir }}/.ssh/podman-id_{{ podman_repos_keytype }}"
type: "{{ podman_repos_keytype }}"
comment: "{{ ansible_facts['hostname'] }}-{{ podman_user }}-deploy-key"
owner: "{{ podman_user }}"
group: "{{ podman_user }}"
mode: "0600"
state: present
become: true
become_user: "{{ podman_user }}"
when:
- podman_project is defined
- podman_project | length > 0
tags: podman_compose
- name: Import trusted GPG keys for docker compose (podman) projects
ansible.builtin.command:
cmd: "gpg --keyserver {{ key.keyserver | default('keys.openpgp.org') }} --recv-key {{ key.id }}"
become: true
become_user: "{{ podman_user }}"
loop: "{{ podman_compose_config.trusted_keys }}"
loop_control:
loop_var: key
label: "{{ key.id }}"
changed_when: false
when: podman_compose_config.trusted_keys is defined
tags: podman_compose
- name: Clone external docker compose (podman) projects
ansible.builtin.git:
repo: "{{ project.url }}"
dest: "{{ podman_repos }}/{{ project.name }}"
version: "{{ project.version }}"
accept_newhostkey: "{{ project.accept_newhostkey | default(false) }}"
gpg_allowlist: "{{ (project.trusted_keys |
default(podman_compose_config.trusted_keys | default([]))) |
map(attribute='id') | list }}"
verify_commit: >-
{{
true if
(project.trusted_keys is defined and project.trusted_keys) or
(
podman_compose_config.trusted_keys is defined and
podman_compose_config.trusted_keys
)
else false
}}
key_file: "{{ podman_homedir }}/.ssh/podman-id_{{ podman_repos_keytype }}"
become: true
become_user: "{{ podman_user }}"
loop: "{{ podman_project }}"
loop_control:
loop_var: project
label: "{{ project.url }}"
when:
- podman_project is defined
- podman_project | length > 0
tags: podman_compose
- name: Create directories for docker compose (podman) projects
ansible.builtin.file:
path: "{{ podman_rootdir }}/{{ project.name }}"
state: directory
owner: "{{ podman_user }}"
group: "{{ podman_user }}"
mode: "0700"
loop: "{{ podman_project }}"
loop_control:
loop_var: project
label: "{{ project.name }}"
when:
- podman_project is defined
- podman_project | length > 0
tags: podman_compose
- name: Synchronize docker-compose.yml
ansible.posix.synchronize:
# noqa jinja[spacing]
src: >-
{{ podman_repos }}/{{ project.name }}/
{{- project.path | default('docker-compose.yml') }}
dest: "{{ podman_rootdir }}/{{ project.name }}/docker-compose.yml"
owner: false
group: false
delegate_to: "{{ inventory_hostname }}"
register: podman_compose_update
notify: podman_compose_restart
loop: "{{ podman_project | default([]) }}"
loop_control:
loop_var: project
label: "{{ project.name }}"
when:
- podman_project is defined
- podman_project | length > 0
tags: podman_compose
- name: Update list of compose projects updated # noqa: no-handler
ansible.builtin.set_fact:
podman_compose_restart_list:
"{{ (podman_compose_restart_list | default([])) +
[{'user': podman_user, 'service': item.project.name}] }}"
loop: "{{ podman_compose_update.results }}"
loop_control:
label: "{{ podman_user }}/{{ item.project.name }}"
when: item.changed | default(false)
tags: podman_compose
- name: Fix ownership of synchronized compose files
ansible.builtin.file:
path: "{{ podman_rootdir }}/{{ project.name }}/docker-compose.yml"
owner: "{{ podman_user }}"
group: "{{ podman_user }}"
mode: "0664"
loop: "{{ podman_project | default([]) }}"
loop_control:
loop_var: project
label: "{{ project.name }}"
when:
- podman_project is defined
- podman_project | length > 0
tags: podman_compose
- name: Set environment variables for docker compose (podman) projects
ansible.builtin.template:
src: compose-env.j2
dest: "{{ podman_rootdir }}/{{ project.name }}/.env"
owner: "{{ podman_user }}"
group: "{{ podman_user }}"
mode: "0600"
register: podman_compose_env_update
notify: podman_compose_restart
no_log: true
loop: "{{ podman_project }}"
loop_control:
loop_var: project
label: "{{ project.name }}"
when: podman_project is defined and project.env is defined
tags: podman_compose
- name: Update list of compose projects who updated their .env # noqa: no-handler
ansible.builtin.set_fact:
# noqa jinja[spacing]
podman_compose_restart_list: "{{
(podman_compose_restart_list | default([]))
+ ([{'user': podman_user,'service': item.project.name}]
if {'user': podman_user, 'service': item.project.name}
not in (podman_compose_restart_list | default([]))
else [])
}}"
loop: "{{ podman_compose_env_update.results }}"
loop_control:
label: "{{ podman_user }}/{{ item.project.name }}"
when: item.changed | default(false)
tags: podman_compose
- name: Start docker compose (podman) services and enable on boot
ansible.builtin.systemd:
name: "compose@{{ project.name }}"
enabled: "{{ project.enabled | default(false) }}"
scope: user
become: true
become_user: "{{ podman_user }}"
loop: "{{ podman_project | default([]) }}"
loop_control:
loop_var: project
label: "{{ podman_user }}/{{ project.name }}"
tags: podman_compose
-20
View File
@@ -1,20 +0,0 @@
- name: "Get UID for {{ podman_user.key }}"
ansible.builtin.getent:
database: passwd
key: "{{ podman_user.key }}"
- name: Login to private Podman registry via Docker CLI
community.docker.docker_login:
registry_url: "{{ registry.key }}"
username: "{{ registry.value.username }}"
password: "{{ registry.value.password }}"
docker_host: "unix:///run/user/{{ podman_uid }}/podman/podman.sock"
vars:
podman_uid: "{{ ansible_facts.getent_passwd[podman_user.key][1] }}"
loop: "{{ podman_user.value | dict2items }}"
loop_control:
loop_var: registry
label: "{{ podman_user.key }} => {{ registry.key }}"
become: true
become_user: "{{ podman_user.key }}"
no_log: true
-324
View File
@@ -1,324 +0,0 @@
- name: Install Podman with Docker CLI tools
ansible.builtin.apt:
name: ["podman", "docker-cli", "docker-compose"]
state: present
- name: Allow rootless containers to use capabilities in their user namespace
ansible.posix.seboolean:
name: container_use_userns_all_caps
state: true
persistent: true
when: selinux is defined and selinux is not false
- name: Create SELinux policy build directory
ansible.builtin.file:
path: "{{ podman_selinux_dir }}"
state: directory
owner: root
group: root
mode: "0755"
when: selinux is defined and selinux is not false
- name: Install container log SELinux policy source
ansible.builtin.copy:
src: oci_log.te
dest: "{{ podman_selinux_dir }}/oci_log.te"
owner: root
group: root
mode: "0644"
register: podman_selinux_src
when: selinux is defined and selinux is not false
- name: Clear stale container log SELinux artifacts
ansible.builtin.file:
path: "{{ podman_selinux_dir }}/oci_log.{{ item }}"
state: absent
loop: [mod, pp]
when:
- selinux is defined and selinux is not false
- podman_selinux_src is changed
- name: Compile container log SELinux policy module
ansible.builtin.command:
cmd: >-
checkmodule -M -m -o {{ podman_selinux_dir }}/oci_log.mod
{{ podman_selinux_dir }}/oci_log.te
creates: "{{ podman_selinux_dir }}/oci_log.mod"
when: selinux is defined and selinux is not false
- name: Package container log SELinux policy module
ansible.builtin.command:
cmd: >-
semodule_package -o {{ podman_selinux_dir }}/oci_log.pp
-m {{ podman_selinux_dir }}/oci_log.mod
creates: "{{ podman_selinux_dir }}/oci_log.pp"
when: selinux is defined and selinux is not false
- name: List loaded SELinux policy modules
ansible.builtin.command:
cmd: semodule -l
register: podman_semodule_list
changed_when: false
when: selinux is defined and selinux is not false
- name: Load container log SELinux policy module
ansible.builtin.command:
cmd: semodule -i {{ podman_selinux_dir }}/oci_log.pp
register: podman_semodule
changed_when: podman_semodule.rc == 0
when:
- selinux is defined and selinux is not false
- podman_selinux_src is changed or "oci_log" not in podman_semodule_list.stdout_lines
- name: Set SELinux context on container log directory
community.general.sefcontext:
target: "{{ podman_log_root }}(/.*)?"
setype: oci_log_t
state: present
when: selinux is defined and selinux is not false
- name: Create container log directory
ansible.builtin.file:
path: "{{ podman_log_root }}"
state: directory
owner: root
group: root
mode: "0755"
setype: >-
{{ (selinux is defined and selinux is not false)
| ternary('oci_log_t', omit) }}
- name: Install GnuPG tools and trusted CA bundle
ansible.builtin.apt:
name: ["gnupg", "ca-certificates"]
state: present
when: podman_compose is defined
- name: Get podman user info for user namespace configuration
ansible.builtin.getent:
database: passwd
key: "{{ item }}"
loop: "{{ podman_compose.keys() | list }}"
register: podman_users_info
loop_control:
label: "{{ item }}"
when: podman_compose is defined
- name: Set subuid base facts for podman users
ansible.builtin.set_fact:
podman_subuid_base: "{{ podman_subuid_base | default({}) | combine(sub) }}"
vars:
uid: "{{ item.ansible_facts.getent_passwd[item.item][1] }}"
sub: "{{ {item.item: 100000 + ((uid | int - 1000) * 65536)} }}"
loop: "{{ podman_users_info.results }}"
loop_control:
label: "{{ item.item }}"
- name: Configure /etc/subuid for rootless users
ansible.builtin.lineinfile:
path: "/etc/subuid"
line: "{{ item.item }}:{{ podman_subuid_base[item.item] }}:65536"
regexp: "^{{ item.item }}:"
create: true
backup: true
mode: "0644"
loop: "{{ podman_users_info.results }}"
loop_control:
label: "{{ item.item }}"
- name: Configure /etc/subgid for rootless users
ansible.builtin.lineinfile:
path: "/etc/subgid"
line: "{{ item.item }}:{{ podman_subuid_base[item.item] }}:65536"
regexp: "^{{ item.item }}:"
create: true
backup: true
mode: "0644"
loop: "{{ podman_users_info.results }}"
loop_control:
label: "{{ item.item }}"
- name: Ensure systemd linger directory exists
ansible.builtin.file:
path: /var/lib/systemd/linger
state: directory
owner: root
group: root
mode: "0755"
- name: Enable lingering for podman compose users
ansible.builtin.file:
path: "/var/lib/systemd/linger/{{ item.item }}"
state: touch
owner: root
group: root
mode: "0644"
access_time: preserve
modification_time: preserve
loop: "{{ podman_users_info.results }}"
loop_control:
label: "{{ item.item }}"
- name: Start user manager for podman compose users
ansible.builtin.systemd_service:
name: "user@{{ item.ansible_facts.getent_passwd[item.item][1] }}.service"
state: started
loop: "{{ podman_users_info.results }}"
loop_control:
label: "{{ item.item }}"
- name: Wait for user runtime directory
ansible.builtin.wait_for:
path: "/run/user/{{ item.ansible_facts.getent_passwd[item.item][1] }}/bus"
timeout: 30
loop: "{{ podman_users_info.results }}"
loop_control:
label: "{{ item.item }}"
- name: Start and enable the Podman socket
ansible.builtin.systemd:
name: podman.socket
state: started
enabled: true
scope: user
vars:
uid: "{{ item.ansible_facts.getent_passwd[item.item][1] }}"
environment:
XDG_RUNTIME_DIR: "/run/user/{{ uid }}"
DBUS_SESSION_BUS_ADDRESS: "unix:path=/run/user/{{ uid }}/bus"
become: true
become_user: "{{ item.item }}"
loop: "{{ podman_users_info.results }}"
loop_control:
label: "{{ item.item }}"
- name: Create global containers config directory
ansible.builtin.file:
path: /etc/containers
state: directory
mode: "0755"
- name: Configure global containers.conf for rootless
ansible.builtin.copy:
content: |
[engine]
cgroup_manager = "cgroupfs"
events_logger = "journald"
runtime = "crun"
dest: /etc/containers/containers.conf
backup: true
mode: "0644"
- name: Configure Docker CLI to use rootless Podman socket
ansible.builtin.copy:
src: files/docker-host.sh
dest: /etc/profile.d/docker-host.sh
owner: root
group: root
mode: "0755"
- name: Install git for repository cloning
ansible.builtin.apt:
name: git
state: present
when: podman_compose is defined
- name: Login to private Podman registries with Docker CLI for each user
ansible.builtin.include_tasks: login.yml
loop: "{{ podman_login | dict2items }}"
loop_control:
loop_var: podman_user
when: podman_login is defined
- name: Stat rootless Podman directory
ansible.builtin.stat:
path: "/home/{{ compose_user.key }}/.local/share/containers"
loop: "{{ podman_compose | dict2items }}"
loop_control:
loop_var: compose_user
label: "{{ compose_user.key }}"
register: podman_user_containers_stat
when:
- podman_compose is defined
- selinux is defined
- selinux is not false
- name: Create rootless Podman directory
ansible.builtin.file:
path: "/home/{{ item.compose_user.key }}/.local/share/containers"
state: directory
owner: "{{ item.compose_user.key }}"
group: "{{ item.compose_user.key }}"
mode: "700"
loop: "{{ podman_user_containers_stat.results }}"
loop_control:
label: "{{ item.compose_user.key }}"
when:
- podman_compose is defined
- selinux is defined
- selinux is not false
- not item.stat.exists
- name: Label rootless Podman directory
ansible.builtin.command: >-
restorecon -Rv /home/{{ item.compose_user.key }}/.local/share/containers
loop: "{{ podman_user_containers_stat.results }}"
loop_control:
label: "/home/{{ item.compose_user.key }}/.local/share/containers"
changed_when: true
when:
- podman_compose is defined
- selinux is defined
- selinux is not false
- not item.stat.exists
- name: Stat Podman label directories
ansible.builtin.stat:
path: "{{ item.path }}"
loop: "{{ podman_label }}"
register: podman_label_stat
loop_control:
label: "{{ item.path }}"
when:
- podman_label is defined
- selinux is defined
- selinux is not false
- name: Create Podman label directories
ansible.builtin.file:
path: "{{ item.item.path }}"
owner: "{{ item.item.owner | default(omit) }}"
group: "{{ item.item.group | default(omit) }}"
mode: "{{ item.item.mode | default('700') }}"
state: directory
loop: "{{ podman_label_stat.results }}"
loop_control:
label: "{{ item.item.path }}"
when:
- podman_label is defined
- selinux is defined
- selinux is not false
- not item.stat.exists
- name: Set labels on Podman label directories
ansible.builtin.command: "chcon {{ item.item.label }} {{ item.item.path }}"
loop: "{{ podman_label_stat.results }}"
changed_when: true
loop_control:
label: "{{ item.item.path }} => {{ item.item.label }}"
when:
- podman_label is defined
- selinux is defined
- selinux is not false
- not item.stat.exists
- name: Deploy Podman compose projects for each user
ansible.builtin.include_tasks: deploy.yml
vars:
podman_user: "{{ compose_user.key }}"
podman_compose_config: "{{ compose_user.value }}"
loop: "{{ podman_compose | dict2items }}"
loop_control:
loop_var: compose_user
when: podman_compose is defined
tags: podman_compose
-10
View File
@@ -1,10 +0,0 @@
# {{ ansible_managed }}
{% if project.env is defined %}
{% for key, value in project.env.items() %}
{% if value is boolean %}
{{ key }}={{ value | lower }}
{% else %}
{{ key }}={{ value }}
{% endif %}
{% endfor %}
{% endif %}
-15
View File
@@ -1,15 +0,0 @@
[Unit]
Description=%i docker compose (podman) service
Requires=podman.socket
After=podman.socket
[Service]
Type=oneshot
RemainAfterExit=true
WorkingDirectory={{ podman_rootdir }}/%i
Environment=DOCKER_HOST=unix://%t/podman/podman.sock
ExecStart=/usr/bin/docker compose up -d --remove-orphans
ExecStop=/usr/bin/docker compose down
[Install]
WantedBy=default.target
+1 -1
View File
@@ -1 +1 @@
proxy_cached_dhparams_pem: /vagrant/scratch/dhparams.pem
cached_dhparams_pem: /vagrant/scratch/dhparams.pem
+10
View File
@@ -1,3 +1,13 @@
- name: Enable nginx sites configuration
ansible.builtin.file:
src: "/etc/nginx/sites-available/{{ item.item.domain }}.conf"
dest: "/etc/nginx/sites-enabled/{{ item.item.domain }}.conf"
state: link
mode: "400"
loop: "{{ nginx_sites.results }}"
when: item.changed
listen: reload_nginx
- name: Reload nginx
ansible.builtin.service:
name: nginx
+24 -66
View File
@@ -10,17 +10,18 @@
state: started
enabled: true
- name: Check if environment is vagrant
- name: Check for cached dhparams.pem file
ansible.builtin.stat:
path: /home/vagrant
register: vagrant_home
path: "{{ cached_dhparams_pem }}"
register: dhparams_file
- name: Download Mozilla's standard DH params (dev only)
ansible.builtin.get_url:
url: https://ssl-config.mozilla.org/ffdhe4096.txt
- name: Copy cached dhparams.pem to /etc/ssl/
ansible.builtin.copy:
src: "{{ cached_dhparams_pem }}"
dest: /etc/ssl/dhparams.pem
mode: "600"
when: vagrant_home.stat.exists
remote_src: true
when: dhparams_file.stat.exists
- name: Generate DH Parameters
community.crypto.openssl_dhparam:
@@ -40,26 +41,14 @@
dest: "/etc/nginx/sites-available/{{ item.domain }}.conf"
mode: "400"
loop: "{{ proxy.servers }}"
loop_control:
label: "{{ item.domain }}"
notify: reload_nginx
- name: Enable nginx sites configuration
ansible.builtin.file:
src: "/etc/nginx/sites-available/{{ item.domain }}.conf"
dest: "/etc/nginx/sites-enabled/{{ item.domain }}.conf"
state: "{{ item.enabled | default(true) | ternary('link', 'absent') }}"
loop: "{{ proxy.servers }}"
loop_control:
label: "{{ item.domain }}"
notify: reload_nginx
register: nginx_sites
- name: Generate self-signed certificate
ansible.builtin.command:
'openssl req -newkey rsa:4096 -x509 -sha256 -days 3650 -nodes \
-subj "/C=US/ST=Local/L=Local/O=Org/OU=IT/CN=example.com" \
-keyout /etc/ssl/private/nginx-selfsigned.key \
-out /etc/ssl/certs/nginx-selfsigned.crt'
ansible.builtin.command: 'openssl req -newkey rsa:4096 -x509 -sha256 -days 3650 -nodes \
-subj "/C=US/ST=Local/L=Local/O=Org/OU=IT/CN=example.com" \
-keyout /etc/ssl/private/nginx-selfsigned.key \
-out /etc/ssl/certs/nginx-selfsigned.crt'
args:
creates: /etc/ssl/certs/nginx-selfsigned.crt
when: proxy.production is not defined or not proxy.production
@@ -67,22 +56,15 @@
- name: Install LE's certbot
ansible.builtin.apt:
name: ["certbot", "python3-certbot-dns-cloudflare"]
name: ['certbot', 'python3-certbot-dns-cloudflare']
state: present
when: proxy.production is defined and proxy.production
- name: Grab Cloudflare API token for configuration
ansible.builtin.slurp:
src: /etc/letsencrypt/cloudflare-api.key
register: cfapi
when: proxy.production is defined and proxy.production and proxy.dns_cloudflare is defined
- name: Install Cloudflare API token
ansible.builtin.template:
src: cloudflare.ini.j2
dest: /etc/letsencrypt/cloudflare.ini
dest: /root/.cloudflare.ini
mode: "400"
diff: false
when: proxy.production is defined and proxy.production and proxy.dns_cloudflare is defined
- name: Create nginx post renewal hook directory
@@ -96,49 +78,25 @@
ansible.builtin.copy:
src: reload-nginx.sh
dest: /etc/letsencrypt/renewal-hooks/post/reload-nginx.sh
mode: "0755"
mode: '0755'
when: proxy.production is defined and proxy.production
- name: Enable SELinux bool certbot_acmesh to allow sh access for DNS-01
ansible.posix.seboolean:
name: certbot_acmesh
state: true
persistent: true
when:
- selinux is defined
- selinux is not false
- proxy is defined
- proxy.production is defined
- proxy.production
- proxy.dns_cloudflare is defined
- name: Run Cloudflare DNS-01 challenges on wildcard domains
ansible.builtin.shell: '/usr/bin/certbot certonly \
--non-interactive \
--agree-tos \
--email "{{ proxy.dns_cloudflare.email }}" \
--dns-cloudflare \
--dns-cloudflare-credentials /etc/letsencrypt/cloudflare.ini \
-d "*.{{ item }}" \
-d "{{ item }}" \
{{ proxy.dns_cloudflare.opts | default("") }}
< /dev/null'
--non-interactive \
--agree-tos \
--email "{{ proxy.dns_cloudflare.email }}" \
--dns-cloudflare \
--dns-cloudflare-credentials /root/.cloudflare.ini \
-d "*.{{ item }}" \
-d "{{ item }}" \
{{ proxy.dns_cloudflare.opts | default("") }}'
args:
creates: "/etc/letsencrypt/live/{{ item }}/fullchain.pem"
loop: "{{ proxy.dns_cloudflare.wildcard_domains }}"
when: proxy.production is defined and proxy.production and proxy.dns_cloudflare is defined
notify: reload_nginx
- name: Enable SELinux bool httpd_can_network_connect to give nginx networking
ansible.posix.seboolean:
name: httpd_can_network_connect
state: true
persistent: true
when:
- selinux is defined
- selinux is not false
- proxy is defined
- name: Add HTTP and HTTPS firewall rule
community.general.ufw:
rule: allow
+1 -1
View File
@@ -1,2 +1,2 @@
# Cloudflare API token used by Certbot
dns_cloudflare_api_token = {{ cfapi['content'] | b64decode | trim }}
dns_cloudflare_api_token = {{ proxy.dns_cloudflare.api_token }}
+4 -15
View File
@@ -1,17 +1,13 @@
server {
listen 80;
{% if proxy.ipv6 is defined and proxy.ipv6 %}
listen [::]:80;
{% endif %}
server_name {{ item.domain }};
return 301 https://{{ item.domain }}$request_uri;
}
server {
listen 443 ssl http2;
{% if proxy.ipv6 is defined and proxy.ipv6 %}
listen [::]:443 ssl http2;
{% endif %}
server_name {{ item.domain }};
access_log /var/log/nginx/{{ item.domain }}.log main;
{% if proxy.production is defined and proxy.production and proxy.dns_cloudflare.wildcard_domains is defined and item.tls.cert is not defined %}
@@ -32,20 +28,14 @@ server {
ssl_certificate /etc/ssl/certs/nginx-selfsigned.crt;
ssl_certificate_key /etc/ssl/private/nginx-selfsigned.key;
{% endif %}
{% if item.hsts is defined %}
add_header Strict-Transport-Security "max-age={{ item.hsts }}" always;
{% endif %}
{% if item.client_max_body_size is defined %}
client_max_body_size {{ item.client_max_body_size }};
{% endif %}
location / {
{% if item.hsts is defined %}
add_header Strict-Transport-Security "max-age={{ item.hsts }}" always;
{% endif %}
{% if item.allowedips is defined %}
{% for ip in item.allowedips %}
allow {{ ip }};
{% endfor %}
deny all;
{% endif %}
{% if item.restrict is defined and item.restrict %}
{% if item.restrict is defined and item.restrict %}
auth_basic "{{ item.restrict_name | default('Restricted Access') }}";
auth_basic_user_file {{ item.restrict_file | default('/etc/nginx/.htpasswd') }};
proxy_set_header Authorization "";
@@ -53,7 +43,6 @@ server {
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_pass {{ item.proxy_pass }};
{% if item.proxy_ssl_verify is defined and item.proxy_ssl_verify is false %}
proxy_ssl_verify off;
+1 -1
View File
@@ -33,4 +33,4 @@
name: "{{ docker_compose_service }}@{{ traefik_name }}"
state: started
enabled: true
when: traefik.ENABLED | default(false)
when: traefik.ENABLED | default('false')
-1
View File
@@ -1 +0,0 @@
zrepl_pkg_hold: true
-40
View File
@@ -1,40 +0,0 @@
- name: Download zrepl APT signing key
ansible.builtin.get_url:
url: https://zrepl.cschwarz.com/apt/apt-key.asc
dest: /tmp/zrepl-apt-key.asc
mode: "600"
force: true
- name: Get fingerprint of downloaded key
ansible.builtin.shell: |
set -euo pipefail
gpg --with-colons --import-options show-only \
--import /tmp/zrepl-apt-key.asc | awk -F: '$1=="fpr"{print $10; exit}'
args:
executable: /bin/bash
changed_when: false
register: gpg_key_info
- name: Verify key fingerprint matches expected value
ansible.builtin.assert:
that: gpg_key_info.stdout == expected_fingerprint
vars:
expected_fingerprint: "E101418FD3D6FBCB9D65A62D708699FC5F2EBF16"
- name: Dearmor zrepl key into APT keyring
ansible.builtin.command:
cmd: >-
gpg --dearmor --yes --output /usr/share/keyrings/zrepl-archive-keyring.gpg
/tmp/zrepl-apt-key.asc
args:
creates: /usr/share/keyrings/zrepl-archive-keyring.gpg
- name: Add zrepl apt repository
ansible.builtin.apt_repository:
repo: "deb [signed-by={{ zrepl_keyring_path }}] {{ zrepl_url }} {{ zrepl_suite }} main"
filename: zrepl
state: present
vars:
zrepl_keyring_path: /usr/share/keyrings/zrepl-archive-keyring.gpg
zrepl_url: "https://zrepl.cschwarz.com/apt/debian"
zrepl_suite: "{{ ansible_distribution_release }}"
-24
View File
@@ -1,24 +0,0 @@
- name: Install GnuPG
ansible.builtin.apt:
name: gnupg
state: present
update_cache: true
- name: Check if zrepl repo exists
ansible.builtin.stat:
path: /etc/apt/sources.list.d/zrepl.list
register: zrepl_repo_file
- name: Install zrepl repo
ansible.builtin.include_tasks: install.yml
when: not zrepl_repo_file.stat.exists
- name: Install zrepl
ansible.builtin.apt:
name: zrepl
state: present
- name: Set zrepl package hold state
ansible.builtin.dpkg_selections:
name: zrepl
selection: "{{ 'hold' if zrepl_pkg_hold else 'install' }}"