Author SHA1 Message Date
kris 41018708cc testing 2025-11-23 21:55:21 -05:00
49 changed files with 266 additions and 891 deletions
Vendored
+4 -4
View File
@@ -15,10 +15,10 @@ VAGRANT_MEM = settings['VAGRANT_MEM'] || 2048
SSH_FORWARD = settings['SSH_FORWARD'] || false SSH_FORWARD = settings['SSH_FORWARD'] || false
# Default to shell environment variable: PLAYBOOK (priority #1) # Default to shell environment variable: PLAYBOOK (priority #1)
playbook=ENV["PLAYBOOK"] PLAYBOOK=ENV["PLAYBOOK"]
if !playbook || playbook.empty? if !PLAYBOOK || PLAYBOOK.empty?
# PLAYBOOK setting in .vagrant.yml (priority #2) # PLAYBOOK setting in .vagrant.yml (priority #2)
playbook = settings['PLAYBOOK'] || 'default' PLAYBOOK = settings['PLAYBOOK'] || 'default'
end end
Vagrant.configure("2") do |config| Vagrant.configure("2") do |config|
@@ -42,7 +42,7 @@ Vagrant.configure("2") do |config|
config.vm.provision "ansible" do |ansible| config.vm.provision "ansible" do |ansible|
ENV['ANSIBLE_ROLES_PATH'] = File.dirname(__FILE__) + "/roles" ENV['ANSIBLE_ROLES_PATH'] = File.dirname(__FILE__) + "/roles"
ansible.compatibility_mode = "2.0" ansible.compatibility_mode = "2.0"
ansible.playbook = "dev/" + playbook + ".yml" ansible.playbook = "dev/" + PLAYBOOK + ".yml"
ansible.raw_arguments = ["--diff"] ansible.raw_arguments = ["--diff"]
end end
end end
+2 -2
View File
@@ -1,6 +1,6 @@
# base # base
base_allow_reboot: false allow_reboot: false
base_manage_network: false manage_network: false
# docker # docker
docker_users: docker_users:
+2 -2
View File
@@ -1,6 +1,6 @@
# base # base
base_allow_reboot: false allow_reboot: false
base_manage_network: false manage_network: false
# Import my GPG key for git signature verification # Import my GPG key for git signature verification
root_gpgkeys: root_gpgkeys:
+2 -2
View File
@@ -1,6 +1,6 @@
# base # base
base_allow_reboot: false allow_reboot: false
base_manage_network: false manage_network: false
# Import my GPG key for git signature verification # Import my GPG key for git signature verification
root_gpgkeys: root_gpgkeys:
+2 -2
View File
@@ -1,6 +1,6 @@
# base # base
base_allow_reboot: false allow_reboot: false
base_manage_network: false manage_network: false
users: users:
git: git:
+2 -2
View File
@@ -1,8 +1,8 @@
debian_version: 10.5.0 debian_version: 10.5.0
# base # base
base_allow_reboot: false allow_reboot: false
base_manage_network: false manage_network: false
# libvirt # libvirt
libvirt_users: vagrant libvirt_users: vagrant
+2 -2
View File
@@ -1,8 +1,8 @@
base_domain: local.krislamo.org base_domain: local.krislamo.org
# base # base
base_allow_reboot: false allow_reboot: false
base_manage_network: false manage_network: false
users: users:
jellyfin: jellyfin:
+2 -2
View File
@@ -1,6 +1,6 @@
# base # base
base_allow_reboot: false allow_reboot: false
base_manage_network: false manage_network: false
# minecraft # minecraft
# Agree to EULA to start service in Vagrant # Agree to EULA to start service in Vagrant
+2 -2
View File
@@ -1,6 +1,6 @@
# base # base
base_allow_reboot: false allow_reboot: false
base_manage_network: false manage_network: false
# docker # docker
docker_users: docker_users:
+26 -29
View File
@@ -1,25 +1,21 @@
############## ##############
#### base #### #### base ####
############## ##############
selinux:
state: enforcing
base_allow_reboot: true allow_reboot: false
base_manage_network: false manage_network: false
root_gpgkeys: root_gpgkeys:
- id: 42A3A92C5DA0F3E5F71A3710105B748C1362EB96 - id: 42A3A92C5DA0F3E5F71A3710105B748C1362EB96
scripts: scripts:
trusted_keys: - name: gotify
- id: 42A3A92C5DA0F3E5F71A3710105B748C1362EB96 url: https://github.com/krislamo/dotfiles
repos: version: 999d745710b9db500e82d1a0d0107ac5d623a669
- name: dotfiles path: gotify/.local/bin/gotify
url: https://github.com/krislamo/dotfiles dest: /usr/local/bin/gotify
version: 999d745710b9db500e82d1a0d0107ac5d623a669 trusted_keys:
scripts: - 42A3A92C5DA0F3E5F71A3710105B748C1362EB96
- src: gotify/.local/bin/gotify
dest: /usr/local/bin/gotify
################ ################
#### proxy ##### #### proxy #####
@@ -27,34 +23,35 @@ scripts:
proxy: proxy:
servers: servers:
- domain: music.local.krislamo.org - domain: cloud.local.krislamo.org
proxy_pass: http://127.0.0.1:4533 proxy_pass: http://127.0.0.1:8000
################ ################
#### podman #### #### podman ####
################ ################
podman_label:
- path: /home/vagrant/navidrome
label: system_u:object_r:container_file_t:s0
owner: vagrant
group: vagrant
podman_compose: podman_compose:
vagrant: vagrant:
root: /opt/oci root: /opt/oci
trusted_keys: trusted_keys:
- id: 42A3A92C5DA0F3E5F71A3710105B748C1362EB96 - id: 42A3A92C5DA0F3E5F71A3710105B748C1362EB96
compose: compose:
- name: navidrome - name: traefik
url: https://github.com/krislamo/navidrome url: https://github.com/krislamo/traefik
version: 305f92cff143c0d497d21277145f605d9da830de version: d7197ddd5b7019c60faf5d164e555b6374972d40
enabled: true enabled: true
accept_newhostkey: true # Consider verifying manually instead accept_newhostkey: true # Consider verifying manually instead
env: env:
VERSION: latest VERSION: latest
BASEURL: https://music.local.krislamo.org SOCKET: /run/user/1000/podman/podman.sock
MUSIC: /home/vagrant/navidrome DASHBOARD: true
LASTFM_ENABLED: "false" - name: nextcloud
LASTFM_APIKEY: "n/a" url: https://github.com/krislamo/nextcloud
LASTFM_SECRET: "n/a" version: 245c91a22fa75e5dde1d423e88540529a4fa4f27
enabled: true
env:
VERSION: latest
DOMAIN: cloud.local.krislamo.org
DATA: /opt/oci/nextcloud/data/
REDIS_VERSION: latest
REDIS_PASSWORD: changeme
+2 -2
View File
@@ -1,8 +1,8 @@
base_domain: local.krislamo.org base_domain: local.krislamo.org
# base # base
base_allow_reboot: false allow_reboot: false
base_manage_network: false manage_network: false
users: users:
git: git:
+2 -2
View File
@@ -1,6 +1,6 @@
# base # base
base_allow_reboot: false allow_reboot: false
base_manage_network: false manage_network: false
#mail: #mail:
# host: smtp.gmail.com # host: smtp.gmail.com
+2 -2
View File
@@ -1,6 +1,6 @@
# base # base
base_allow_reboot: false allow_reboot: false
base_manage_network: false manage_network: false
# UniFi version # UniFi version
unifi_version: 6.1.71 unifi_version: 6.1.71
-68
View File
@@ -1,68 +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
root_gpgkeys:
- name: kris@lamoureux.io
id: 42A3A92C5DA0F3E5F71A3710105B748C1362EB96
###############
#### proxy ####
###############
base_domain: local.krislamo.org
proxy:
servers:
- domain: "git.{{ base_domain }}"
proxy_pass: "http://127.0.0.1:3000"
################
#### podman ####
################
podman_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 }}"
###############
#### 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
base_allow_reboot: false allow_reboot: false
base_manage_network: false manage_network: false
# docker # docker
docker_users: docker_users:
@@ -22,6 +22,7 @@ wordpress_multisite: true
# database settings # database settings
wordpress_dbversion: latest wordpress_dbversion: latest
wordpress_dbpass: password wordpress_dbpass: password
# multisite (enable in admin panel then uncomment) # multisite (enable in admin panel then uncomment)
#wordpress_rule: "Host(`{{ wordpress_domain }}`) || #wordpress_rule: "Host(`{{ wordpress_domain }}`) ||
# Host(`site1.{{ wordpress_domain }}`) || # Host(`site1.{{ wordpress_domain }}`) ||
-11
View File
@@ -1,11 +0,0 @@
- name: Install VPS Server
hosts: all
become: true
vars_files:
- host_vars/vps.yml
roles:
- base
- proxy
- mariadb
- podman
- 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 # Finds the SSH private key under ./.vagrant and connects to
# the Vagrant box, port forwarding localhost ports: 8443, 443, 80, 22 # the Vagrant box, port forwarding localhost ports: 8443, 443, 80, 22
-7
View File
@@ -1,7 +0,0 @@
- name: Install Podman server
hosts: "{{ PLAYBOOK_HOST | default('none') }}"
become: true
roles:
- base
- proxy
- podman
+6 -10
View File
@@ -1,10 +1,10 @@
base_allow_reboot: true allow_reboot: true
base_manage_firewall: true manage_firewall: true
base_manage_network: false manage_network: false
base_network_type: static network_type: static
base_locale_default: en_US.UTF-8 locale_default: en_US.UTF-8
base_packages: packages:
- apache2-utils - apache2-utils
- cryptsetup - cryptsetup
- curl - curl
@@ -20,7 +20,3 @@ base_packages:
- tree - tree
- vim - vim
- wget - wget
base_scripts: /srv/.scripts
base_ssh_ufw_rule: limit
+1 -3
View File
@@ -3,13 +3,11 @@
msg: "Reboot initiated by Ansible" msg: "Reboot initiated by Ansible"
connect_timeout: 5 connect_timeout: 5
listen: reboot_host listen: reboot_host
when: base_allow_reboot when: allow_reboot
- name: Reconfigure locales - name: Reconfigure locales
ansible.builtin.command: dpkg-reconfigure -f noninteractive locales ansible.builtin.command: dpkg-reconfigure -f noninteractive locales
changed_when: false
listen: reconfigure_locales listen: reconfigure_locales
when: not ansible_check_mode
- name: Restart WireGuard - name: Restart WireGuard
ansible.builtin.service: ansible.builtin.service:
+2 -13
View File
@@ -8,17 +8,6 @@
name: fail2ban name: fail2ban
state: present 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 - name: Deny incoming traffic by default
community.general.ufw: community.general.ufw:
default: deny default: deny
@@ -29,10 +18,10 @@
default: allow default: allow
direction: outgoing direction: outgoing
- name: "{{ base_ssh_ufw_rule | capitalize }} OpenSSH" - name: Allow OpenSSH with rate limiting
community.general.ufw: community.general.ufw:
name: ssh name: ssh
rule: "{{ base_ssh_ufw_rule | default('limit') }}" rule: limit
- name: Remove Fail2ban defaults-debian.conf - name: Remove Fail2ban defaults-debian.conf
ansible.builtin.file: ansible.builtin.file:
+2 -2
View File
@@ -9,12 +9,12 @@
- name: Import Firewall tasks - name: Import Firewall tasks
ansible.builtin.import_tasks: firewall.yml ansible.builtin.import_tasks: firewall.yml
tags: firewall tags: firewall
when: base_manage_firewall when: manage_firewall
- name: Import Network tasks - name: Import Network tasks
ansible.builtin.import_tasks: network.yml ansible.builtin.import_tasks: network.yml
tags: network tags: network
when: base_manage_network when: manage_network
- name: Import Mail tasks - name: Import Mail tasks
ansible.builtin.import_tasks: mail.yml ansible.builtin.import_tasks: mail.yml
+1 -1
View File
@@ -43,4 +43,4 @@
from: "{{ item }}" from: "{{ item }}"
state: enabled state: enabled
loop: "{{ samba.firewall }}" loop: "{{ samba.firewall }}"
when: base_manage_firewall when: manage_firewall
+23 -104
View File
@@ -1,68 +1,16 @@
- name: Install useful software - name: Install useful software
ansible.builtin.apt: ansible.builtin.apt:
name: "{{ base_packages }}" name: "{{ packages }}"
state: present state: present
update_cache: true 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 - name: Install GPG
ansible.builtin.apt: ansible.builtin.apt:
name: gpg name: gpg
state: present state: present
- name: Check for existing GPG keys - name: Check for existing GPG keys
ansible.builtin.command: >- ansible.builtin.command: "gpg --list-keys {{ item.id }} 2>/dev/null"
gpg --list-keys {{ item.id }} 2>/dev/null
register: gpg_check register: gpg_check
loop: "{{ root_gpgkeys }}" loop: "{{ root_gpgkeys }}"
failed_when: false failed_when: false
@@ -71,8 +19,9 @@
- name: Import GPG keys - name: Import GPG keys
ansible.builtin.command: >- ansible.builtin.command: >-
gpg --keyserver {{ item.item.server | default('keys.openpgp.org') }} gpg
--recv-key {{ item.item.id }} --keyserver {{ item.item.server | default('keys.openpgp.org') }}
--recv-key {{ item.item.id }}
register: gpg_check_import register: gpg_check_import
loop: "{{ gpg_check.results }}" loop: "{{ gpg_check.results }}"
loop_control: loop_control:
@@ -91,23 +40,21 @@
- not item.skipped | default(false) - not item.skipped | default(false)
- "'imported' not in item.stderr" - "'imported' not in item.stderr"
- name: Create scripts directories - name: Create /opt/scripts directories
ansible.builtin.file: ansible.builtin.file:
path: "{{ item }}" path: "{{ item }}"
state: directory state: directory
mode: "700" mode: "755"
owner: root
group: root
loop: loop:
- "{{ base_scripts }}" - /opt/scripts
- "{{ base_scripts }}/.keys" - /opt/scripts/.keys
when: scripts is defined when: scripts is defined
- name: Generate OpenSSH deploy keys for script clones - name: Generate OpenSSH deploy keys for script clones
community.crypto.openssh_keypair: community.crypto.openssh_keypair:
path: "{{ base_scripts }}/.keys/id_ed25519" path: /opt/scripts/.keys/id_ed25519
type: ed25519 type: ed25519
comment: "{{ ansible_facts['hostname'] }}-deploy-key" comment: "{{ ansible_hostname }}-deploy-key"
mode: "400" mode: "400"
state: present state: present
when: scripts is defined when: scripts is defined
@@ -121,20 +68,13 @@
- name: Clone external scripts projects - name: Clone external scripts projects
ansible.builtin.git: ansible.builtin.git:
repo: "{{ item.url }}" repo: "{{ item.url }}"
dest: "{{ base_scripts }}/{{ item.name }}" dest: "/opt/scripts/{{ item.name }}"
version: "{{ item.version }}" version: "{{ item.version }}"
accept_newhostkey: "{{ item.accept_newhostkey | default(false) }}" accept_newhostkey: "{{ item.accept_newhostkey | default(false) }}"
gpg_allowlist: >- gpg_allowlist: "{{ item.trusted_keys | default([]) }}"
{{ (item.trusted_keys | default(scripts.trusted_keys) | default([])) verify_commit: "{{ true if (item.trusted_keys is defined and item.trusted_keys) else false }}"
| map(attribute='id') key_file: /opt/scripts/.keys/id_ed25519
| list }} loop: "{{ scripts }}"
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: loop_control:
label: "{{ item.url }}" label: "{{ item.url }}"
when: scripts is defined when: scripts is defined
@@ -142,30 +82,15 @@
- name: Synchronize scripts - name: Synchronize scripts
ansible.posix.synchronize: ansible.posix.synchronize:
src: "{{ base_scripts }}/{{ item.0.name }}/{{ item.1.src }}" src: "/opt/scripts/{{ item.name }}/{{ item.path }}"
dest: "{{ item.1.dest }}" dest: "{{ item.dest }}"
delegate_to: "{{ inventory_hostname }}" delegate_to: "{{ inventory_hostname }}"
loop: "{{ scripts.repos | default([]) | subelements('scripts') }}" loop: "{{ scripts | default([]) }}"
loop_control: loop_control:
label: "{{ item.0.name }}: {{ item.1.src }}" label: "{{ item.name }}"
when: scripts is defined and scripts | length > 0 when: scripts is defined and scripts | length > 0
tags: scripts 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
- name: Install NTPsec - name: Install NTPsec
ansible.builtin.apt: ansible.builtin.apt:
name: ntpsec name: ntpsec
@@ -178,7 +103,7 @@
- name: Generate locale - name: Generate locale
community.general.locale_gen: community.general.locale_gen:
name: "{{ base_locale_default }}" name: "{{ locale_default }}"
state: present state: present
notify: reconfigure_locales notify: reconfigure_locales
@@ -186,7 +111,7 @@
ansible.builtin.lineinfile: ansible.builtin.lineinfile:
path: /etc/default/locale path: /etc/default/locale
regexp: "^LANG=" regexp: "^LANG="
line: "LANG={{ base_locale_default }}" line: "LANG={{ locale_default }}"
- name: Manage root authorized_keys - name: Manage root authorized_keys
ansible.builtin.template: ansible.builtin.template:
@@ -194,7 +119,6 @@
dest: /root/.ssh/authorized_keys dest: /root/.ssh/authorized_keys
mode: "400" mode: "400"
when: authorized_keys is defined when: authorized_keys is defined
tags: users
- name: Create system user groups - name: Create system user groups
ansible.builtin.group: ansible.builtin.group:
@@ -205,7 +129,6 @@
loop_control: loop_control:
label: "{{ item.key }}" label: "{{ item.key }}"
when: users is defined when: users is defined
tags: users
- name: Create system users - name: Create system users
ansible.builtin.user: ansible.builtin.user:
@@ -222,12 +145,10 @@
loop_control: loop_control:
label: "{{ item.key }}" label: "{{ item.key }}"
when: users is defined when: users is defined
tags: users
- name: Create Ansible's temporary remote directory for users - name: Create Ansible's temporary remote directory for users
ansible.builtin.file: ansible.builtin.file:
path: >- path: "{{ item.value.homedir | default('/home/' + item.key) }}/.ansible/tmp"
{{ item.value.homedir | default('/home/' + item.key) }}/.ansible/tmp
state: directory state: directory
mode: "700" mode: "700"
owner: "{{ item.key }}" owner: "{{ item.key }}"
@@ -238,7 +159,6 @@
when: when:
- users is defined - users is defined
- item.value.tmp | default(true) - item.value.tmp | default(true)
tags: users
- name: Set authorized_keys for system users - name: Set authorized_keys for system users
ansible.posix.authorized_key: ansible.posix.authorized_key:
@@ -249,7 +169,6 @@
loop_control: loop_control:
label: "{{ item.key }}" label: "{{ item.key }}"
when: users is defined and item.value.key is defined when: users is defined and item.value.key is defined
tags: users
- name: Manage filesystem mounts - name: Manage filesystem mounts
ansible.posix.mount: ansible.posix.mount:
+1 -1
View File
@@ -1,7 +1,7 @@
[global] [global]
workgroup = WORKGROUP workgroup = WORKGROUP
server string = Samba Server %v server string = Samba Server %v
netbios name = {{ ansible_facts['hostname'] }} netbios name = {{ ansible_hostname }}
security = user security = user
map to guest = bad user map to guest = bad user
dns proxy = no dns proxy = no
+1 -12
View File
@@ -1,22 +1,11 @@
# {{ ansible_managed }} # {{ ansible_managed }}
[Interface] # {{ ansible_facts['hostname'] }} [Interface] # {{ ansible_hostname }}
PrivateKey = {{ wgkey['content'] | b64decode | trim }} PrivateKey = {{ wgkey['content'] | b64decode | trim }}
Address = {{ wireguard.address }} Address = {{ wireguard.address }}
{% if wireguard.listenport is defined %} {% if wireguard.listenport is defined %}
ListenPort = {{ wireguard.listenport }} ListenPort = {{ wireguard.listenport }}
{% endif %} {% 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 %} {% for peer in wireguard.peers %}
{% if peer.name is defined %} {% if peer.name is defined %}
+1 -1
View File
@@ -77,7 +77,7 @@
community.crypto.openssh_keypair: community.crypto.openssh_keypair:
path: "{{ docker_repos_keys }}/id_{{ docker_repos_keytype }}" path: "{{ docker_repos_keys }}/id_{{ docker_repos_keytype }}"
type: "{{ docker_repos_keytype }}" type: "{{ docker_repos_keytype }}"
comment: "{{ ansible_facts['hostname'] }}-deploy-key" comment: "{{ ansible_hostname }}-deploy-key"
mode: "400" mode: "400"
state: present state: present
when: docker_compose_deploy is defined when: docker_compose_deploy is defined
+3 -8
View File
@@ -1,6 +1,6 @@
# container settings # container settings
gitea_name: gitea gitea_name: gitea
gitea_sshport: "2222" gitea_sshport: "222"
gitea_webport: "3000" gitea_webport: "3000"
gitea_ssh: "127.0.0.1:{{ gitea_sshport }}" gitea_ssh: "127.0.0.1:{{ gitea_sshport }}"
gitea_web: "127.0.0.1:{{ gitea_webport }}" gitea_web: "127.0.0.1:{{ gitea_webport }}"
@@ -16,12 +16,7 @@ gitea_dbuser: "{{ gitea_name }}"
# proxy settings # proxy settings
gitea_proxy_limit: "1" gitea_proxy_limit: "1"
gitea_trusted_proxies: "10.89.0.0/16" gitea_trusted_proxies: "172.16.0.0/12"
# host # host
gitea_root: "{{ podman_compose.git.root }}/{{ gitea_name }}" gitea_root: "{{ docker_compose_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 }}"
-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 - name: Restart Gitea
ansible.builtin.systemd_service: ansible.builtin.service:
name: ssh name: "{{ docker_compose_service }}@{{ gitea_name }}"
state: reloaded state: restarted
listen: restart_ssh listen: restart_gitea
+22 -159
View File
@@ -13,7 +13,7 @@
community.mysql.mysql_user: community.mysql.mysql_user:
name: "{{ gitea.DB_USER }}" name: "{{ gitea.DB_USER }}"
password: "{{ gitea.DB_PASSWD }}" password: "{{ gitea.DB_PASSWD }}"
host: "%" host: '%'
state: present state: present
priv: "{{ gitea.DB_NAME }}.*:ALL" priv: "{{ gitea.DB_NAME }}.*:ALL"
login_unix_socket: /var/run/mysqld/mysqld.sock login_unix_socket: /var/run/mysqld/mysqld.sock
@@ -21,36 +21,35 @@
- name: Create git's .ssh directory - name: Create git's .ssh directory
ansible.builtin.file: ansible.builtin.file:
path: /home/git/.ssh path: /home/git/.ssh
owner: git
group: git
mode: "700" mode: "700"
state: directory state: directory
setype: >-
{{ (selinux is defined and selinux is not false)
| ternary('ssh_home_t', omit) }}
- name: Generate git's SSH keys - name: Generate git's SSH keys
community.crypto.openssh_keypair: community.crypto.openssh_keypair:
path: /home/git/.ssh/id_rsa 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 - name: Find git's public SSH key
ansible.builtin.slurp: ansible.builtin.slurp:
src: /home/git/.ssh/id_rsa.pub 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 - name: Create Gitea host script for SSH
ansible.builtin.template: ansible.builtin.template:
@@ -58,147 +57,11 @@
dest: /usr/local/bin/gitea dest: /usr/local/bin/gitea
mode: "755" 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 - name: Create Gitea's logging directory
ansible.builtin.file: ansible.builtin.file:
name: "{{ gitea_logs }}" name: /var/log/gitea
state: directory state: directory
owner: "{{ gitea_oci_uid }}" mode: "755"
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 }}"
- name: Install Gitea's Fail2ban filter - name: Install Gitea's Fail2ban filter
ansible.builtin.template: ansible.builtin.template:
+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] [gitea]
enabled = true enabled = true
filter = gitea filter = gitea
logpath = {{ gitea_logs }}/gitea.log logpath = /var/log/gitea/gitea.log
maxretry = 10 maxretry = 10
findtime = 3600 findtime = 3600
bantime = 900 bantime = 900
action = iptables-allports 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
+31 -4
View File
@@ -1,13 +1,40 @@
- name: Install QEMU/KVM and libvirt - name: Install QEMU/KVM
ansible.builtin.apt: ansible.builtin.apt:
name: ["qemu-system", "libvirt-clients", "libvirt-daemon-system"] name: qemu-kvm
install_recommends: false state: present
- name: Install Libvirt
ansible.builtin.apt:
name: ["libvirt-clients", "libvirt-daemon-system"]
state: present state: present
- name: Add users to libvirt group - name: Add users to libvirt group
ansible.builtin.user: ansible.builtin.user:
name: "{{ item }}" name: "{{ item }}"
groups: libvirt groups: libvirt
append: true append: yes
with_items: "{{ libvirt_users }}" with_items: "{{ libvirt_users }}"
when: libvirt_users is defined 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
+3 -13
View File
@@ -16,22 +16,12 @@
regex: "^bind-address" regex: "^bind-address"
line: "bind-address = {{ ansible_facts.docker0.ipv4.address }}" line: "bind-address = {{ ansible_facts.docker0.ipv4.address }}"
notify: restart_mariadb notify: restart_mariadb
when: ansible_facts['docker0'] is defined 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 - name: Flush handlers to ensure MariaDB restarts immediately
ansible.builtin.meta: flush_handlers ansible.builtin.meta: flush_handlers
tags: restart_mariadb tags: restart_mariadb
when: ansible_facts['docker0'] is defined or podman_compose is defined when: ansible_facts.docker0 is defined
- name: Allow database connections from Docker - name: Allow database connections from Docker
community.general.ufw: community.general.ufw:
@@ -39,4 +29,4 @@
port: "3306" port: "3306"
proto: tcp proto: tcp
src: "{{ item }}" src: "{{ item }}"
loop: "{{ mariadb_trust | default(['169.254.0.0/16']) }}" loop: "{{ mariadb_trust | default(['172.16.0.0/12']) }}"
+1 -3
View File
@@ -1,6 +1,4 @@
# Default configuration for podman role # Default configuration for podman role
podman_log_root: /var/log/oci
podman_nodocker: false
podman_repos_keytype: ed25519 podman_repos_keytype: ed25519
podman_selinux_dir: /usr/share/selinux
podman_ssh_key_path: "{{ ansible_user_dir }}/.ssh" podman_ssh_key_path: "{{ ansible_user_dir }}/.ssh"
podman_nodocker: false
-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;
+5 -19
View File
@@ -3,7 +3,6 @@
database: passwd database: passwd
key: "{{ podman_user }}" key: "{{ podman_user }}"
register: podman_user_info register: podman_user_info
tags: podman_compose
- name: Set user-specific variables - name: Set user-specific variables
ansible.builtin.set_fact: ansible.builtin.set_fact:
@@ -12,7 +11,6 @@
podman_homedir: "{{ podman_user_info.ansible_facts.getent_passwd[podman_user][4] }}" podman_homedir: "{{ podman_user_info.ansible_facts.getent_passwd[podman_user][4] }}"
podman_project: "{{ podman_compose_config.compose }}" podman_project: "{{ podman_compose_config.compose }}"
podman_repos: "{{ podman_compose_config.root }}/.compose_repos" podman_repos: "{{ podman_compose_config.root }}/.compose_repos"
tags: podman_compose
- name: Create docker compose (podman) root directory for user - name: Create docker compose (podman) root directory for user
ansible.builtin.file: ansible.builtin.file:
@@ -53,7 +51,6 @@
when: when:
- podman_project is defined - podman_project is defined
- podman_project | length > 0 - podman_project | length > 0
tags: podman_compose
- name: Create .ssh directory for podman compose user - name: Create .ssh directory for podman compose user
ansible.builtin.file: ansible.builtin.file:
@@ -65,19 +62,17 @@
when: when:
- podman_project is defined - podman_project is defined
- podman_project | length > 0 - podman_project | length > 0
tags: podman_compose
- name: Generate OpenSSH deploy keys for docker compose (podman) clones - name: Generate OpenSSH deploy keys for docker compose (podman) clones
community.crypto.openssh_keypair: community.crypto.openssh_keypair:
path: "{{ podman_homedir }}/.ssh/podman-id_{{ podman_repos_keytype }}" path: "{{ podman_ssh_key_path }}/podman-id_{{ podman_repos_keytype }}"
type: "{{ podman_repos_keytype }}" type: "{{ podman_repos_keytype }}"
comment: "{{ ansible_facts['hostname'] }}-{{ podman_user }}-deploy-key" comment: "{{ ansible_hostname }}-{{ podman_user }}-deploy-key"
owner: "{{ podman_user }}" owner: "{{ podman_user }}"
group: "{{ podman_user }}" group: "{{ podman_user }}"
mode: "0600" mode: "0600"
state: present state: present
when: podman_project is defined when: podman_project is defined
tags: podman_compose
- name: Import trusted GPG keys for docker compose (podman) projects - name: Import trusted GPG keys for docker compose (podman) projects
ansible.builtin.command: ansible.builtin.command:
@@ -90,7 +85,6 @@
label: "{{ key.id }}" label: "{{ key.id }}"
changed_when: false changed_when: false
when: podman_compose_config.trusted_keys is defined when: podman_compose_config.trusted_keys is defined
tags: podman_compose
- name: Clone external docker compose (podman) projects - name: Clone external docker compose (podman) projects
ansible.builtin.git: ansible.builtin.git:
@@ -111,7 +105,7 @@
) )
else false else false
}} }}
key_file: "{{ podman_homedir }}/.ssh/podman-id_{{ podman_repos_keytype }}" key_file: "{{ podman_ssh_key_path }}/podman-id_{{ podman_repos_keytype }}"
become: true become: true
become_user: "{{ podman_user }}" become_user: "{{ podman_user }}"
loop: "{{ podman_project }}" loop: "{{ podman_project }}"
@@ -121,7 +115,6 @@
when: when:
- podman_project is defined - podman_project is defined
- podman_project | length > 0 - podman_project | length > 0
tags: podman_compose
- name: Create directories for docker compose (podman) projects - name: Create directories for docker compose (podman) projects
ansible.builtin.file: ansible.builtin.file:
@@ -137,7 +130,6 @@
when: when:
- podman_project is defined - podman_project is defined
- podman_project | length > 0 - podman_project | length > 0
tags: podman_compose
- name: Synchronize docker-compose.yml - name: Synchronize docker-compose.yml
ansible.posix.synchronize: ansible.posix.synchronize:
@@ -160,7 +152,6 @@
when: when:
- podman_project is defined - podman_project is defined
- podman_project | length > 0 - podman_project | length > 0
tags: podman_compose
- name: Update list of compose projects updated - name: Update list of compose projects updated
ansible.builtin.set_fact: ansible.builtin.set_fact:
@@ -170,8 +161,7 @@
loop: "{{ podman_compose_update.results }}" loop: "{{ podman_compose_update.results }}"
loop_control: loop_control:
label: "{{ podman_user }}/{{ item.project.name }}" label: "{{ podman_user }}/{{ item.project.name }}"
when: item.changed | default(false) when: (podman_compose_update.results | default([]) | length) > 0
tags: podman_compose
- name: Fix ownership of synchronized compose files - name: Fix ownership of synchronized compose files
ansible.builtin.file: ansible.builtin.file:
@@ -186,7 +176,6 @@
when: when:
- podman_project is defined - podman_project is defined
- podman_project | length > 0 - podman_project | length > 0
tags: podman_compose
- name: Set environment variables for docker compose (podman) projects - name: Set environment variables for docker compose (podman) projects
ansible.builtin.template: ansible.builtin.template:
@@ -205,7 +194,6 @@
loop_var: project loop_var: project
label: "{{ project.name }}" label: "{{ project.name }}"
when: podman_project is defined and project.env is defined when: podman_project is defined and project.env is defined
tags: podman_compose
- name: Update list of compose projects who updated their .env - name: Update list of compose projects who updated their .env
ansible.builtin.set_fact: ansible.builtin.set_fact:
@@ -220,8 +208,7 @@
loop: "{{ podman_compose_env_update.results }}" loop: "{{ podman_compose_env_update.results }}"
loop_control: loop_control:
label: "{{ podman_user }}/{{ item.project.name }}" label: "{{ podman_user }}/{{ item.project.name }}"
when: item.changed | default(false) when: (podman_compose_env_update.results | default([]) | length) > 0
tags: podman_compose
- name: Update list of enabled compose projects - name: Update list of enabled compose projects
ansible.builtin.set_fact: ansible.builtin.set_fact:
@@ -230,4 +217,3 @@
+ [{'user': podman_user, 'service': project.name}] }} + [{'user': podman_user, 'service': project.name}] }}
when: project.enabled | default(false) when: project.enabled | default(false)
notify: podman_compose_enable notify: podman_compose_enable
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
+13 -220
View File
@@ -3,91 +3,6 @@
name: ["podman", "docker-cli", "docker-compose"] name: ["podman", "docker-cli", "docker-compose"]
state: present 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 - name: Install GnuPG tools and trusted CA bundle
ansible.builtin.apt: ansible.builtin.apt:
name: ["gnupg", "ca-certificates"] name: ["gnupg", "ca-certificates"]
@@ -104,19 +19,13 @@
label: "{{ item }}" label: "{{ item }}"
when: podman_compose is defined 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({
item.item: 100000 + ((item.ansible_facts.getent_passwd[item.item][1]
| int - 1000) * 65536) }) }}"
loop: "{{ user_info.results }}"
loop_control:
label: "{{ item.item }}"
- name: Configure /etc/subuid for rootless users - name: Configure /etc/subuid for rootless users
ansible.builtin.lineinfile: ansible.builtin.lineinfile:
path: "/etc/subuid" path: "/etc/subuid"
line: "{{ item.item }}:{{ podman_subuid_base[item.item] }}:65536" line:
"{{ item.item }}:{{ 100000 +
((item.ansible_facts.getent_passwd[item.item][1] | int - 1000) * 65536)
}}:65536"
regexp: "^{{ item.item }}:" regexp: "^{{ item.item }}:"
create: true create: true
backup: true backup: true
@@ -128,7 +37,10 @@
- name: Configure /etc/subgid for rootless users - name: Configure /etc/subgid for rootless users
ansible.builtin.lineinfile: ansible.builtin.lineinfile:
path: "/etc/subgid" path: "/etc/subgid"
line: "{{ item.item }}:{{ podman_subuid_base[item.item] }}:65536" line:
"{{ item.item }}:{{ 100000 +
((item.ansible_facts.getent_passwd[item.item][1] | int - 1000) * 65536)
}}:65536"
regexp: "^{{ item.item }}:" regexp: "^{{ item.item }}:"
create: true create: true
backup: true backup: true
@@ -137,39 +49,10 @@
loop_control: loop_control:
label: "{{ item.item }}" label: "{{ item.item }}"
- name: Ensure systemd linger directory exists - name: Enable lingering for podman compose user
ansible.builtin.file: ansible.builtin.command:
path: /var/lib/systemd/linger cmd: "loginctl enable-linger {{ item.item }}"
state: directory changed_when: false
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: "{{ user_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: "{{ user_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: "{{ user_info.results }}" loop: "{{ user_info.results }}"
loop_control: loop_control:
label: "{{ item.item }}" label: "{{ item.item }}"
@@ -214,7 +97,7 @@
dest: /etc/profile.d/docker-host.sh dest: /etc/profile.d/docker-host.sh
owner: root owner: root
group: root group: root
mode: "0755" mode: '0755'
- name: Install git for repository cloning - name: Install git for repository cloning
ansible.builtin.apt: ansible.builtin.apt:
@@ -222,95 +105,6 @@
state: present state: present
when: podman_compose is defined 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 - name: Deploy Podman compose projects for each user
ansible.builtin.include_tasks: deploy.yml ansible.builtin.include_tasks: deploy.yml
vars: vars:
@@ -320,4 +114,3 @@
loop_control: loop_control:
loop_var: compose_user loop_var: compose_user
when: podman_compose is defined when: podman_compose is defined
tags: podman_compose
+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 - name: Reload nginx
ansible.builtin.service: ansible.builtin.service:
name: nginx name: nginx
+13 -47
View File
@@ -10,17 +10,18 @@
state: started state: started
enabled: true enabled: true
- name: Check if environment is vagrant - name: Check for cached dhparams.pem file
ansible.builtin.stat: ansible.builtin.stat:
path: /home/vagrant path: "{{ cached_dhparams_pem }}"
register: vagrant_home register: dhparams_file
- name: Download Mozilla's standard DH params (dev only) - name: Copy cached dhparams.pem to /etc/ssl/
ansible.builtin.get_url: ansible.builtin.copy:
url: https://ssl-config.mozilla.org/ffdhe4096.txt src: "{{ cached_dhparams_pem }}"
dest: /etc/ssl/dhparams.pem dest: /etc/ssl/dhparams.pem
mode: "600" mode: "600"
when: vagrant_home.stat.exists remote_src: true
when: dhparams_file.stat.exists
- name: Generate DH Parameters - name: Generate DH Parameters
community.crypto.openssl_dhparam: community.crypto.openssl_dhparam:
@@ -40,19 +41,8 @@
dest: "/etc/nginx/sites-available/{{ item.domain }}.conf" dest: "/etc/nginx/sites-available/{{ item.domain }}.conf"
mode: "400" mode: "400"
loop: "{{ proxy.servers }}" 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 notify: reload_nginx
register: nginx_sites
- name: Generate self-signed certificate - name: Generate self-signed certificate
ansible.builtin.command: ansible.builtin.command:
@@ -73,14 +63,14 @@
- name: Grab Cloudflare API token for configuration - name: Grab Cloudflare API token for configuration
ansible.builtin.slurp: ansible.builtin.slurp:
src: /etc/letsencrypt/cloudflare-api.key src: /root/.cloudflare-api
register: cfapi register: cfapi
when: proxy.production is defined and proxy.production and proxy.dns_cloudflare is defined when: proxy.production is defined and proxy.production and proxy.dns_cloudflare is defined
- name: Install Cloudflare API token - name: Install Cloudflare API token
ansible.builtin.template: ansible.builtin.template:
src: cloudflare.ini.j2 src: cloudflare.ini.j2
dest: /etc/letsencrypt/cloudflare.ini dest: /root/.cloudflare.ini
mode: "400" mode: "400"
diff: false diff: false
when: proxy.production is defined and proxy.production and proxy.dns_cloudflare is defined when: proxy.production is defined and proxy.production and proxy.dns_cloudflare is defined
@@ -99,46 +89,22 @@
mode: "0755" mode: "0755"
when: proxy.production is defined and proxy.production 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 - name: Run Cloudflare DNS-01 challenges on wildcard domains
ansible.builtin.shell: '/usr/bin/certbot certonly \ ansible.builtin.shell: '/usr/bin/certbot certonly \
--non-interactive \ --non-interactive \
--agree-tos \ --agree-tos \
--email "{{ proxy.dns_cloudflare.email }}" \ --email "{{ proxy.dns_cloudflare.email }}" \
--dns-cloudflare \ --dns-cloudflare \
--dns-cloudflare-credentials /etc/letsencrypt/cloudflare.ini \ --dns-cloudflare-credentials /root/.cloudflare.ini \
-d "*.{{ item }}" \ -d "*.{{ item }}" \
-d "{{ item }}" \ -d "{{ item }}" \
{{ proxy.dns_cloudflare.opts | default("") }} {{ proxy.dns_cloudflare.opts | default("") }}'
< /dev/null'
args: args:
creates: "/etc/letsencrypt/live/{{ item }}/fullchain.pem" creates: "/etc/letsencrypt/live/{{ item }}/fullchain.pem"
loop: "{{ proxy.dns_cloudflare.wildcard_domains }}" loop: "{{ proxy.dns_cloudflare.wildcard_domains }}"
when: proxy.production is defined and proxy.production and proxy.dns_cloudflare is defined when: proxy.production is defined and proxy.production and proxy.dns_cloudflare is defined
notify: reload_nginx 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 - name: Add HTTP and HTTPS firewall rule
community.general.ufw: community.general.ufw:
rule: allow rule: allow
@@ -1,17 +1,13 @@
server { server {
listen 80; listen 80;
{% if proxy.ipv6 is defined and proxy.ipv6 %}
listen [::]:80; listen [::]:80;
{% endif %}
server_name {{ item.domain }}; server_name {{ item.domain }};
return 301 https://{{ item.domain }}$request_uri; return 301 https://{{ item.domain }}$request_uri;
} }
server { server {
listen 443 ssl http2; listen 443 ssl http2;
{% if proxy.ipv6 is defined and proxy.ipv6 %}
listen [::]:443 ssl http2; listen [::]:443 ssl http2;
{% endif %}
server_name {{ item.domain }}; server_name {{ item.domain }};
access_log /var/log/nginx/{{ item.domain }}.log main; 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 %} {% if proxy.production is defined and proxy.production and proxy.dns_cloudflare.wildcard_domains is defined and item.tls.cert is not defined %}
-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' }}"