Compare commits

..
15 Commits
22 changed files with 311 additions and 20 deletions

No files matched your search

+21 -5
View File
@@ -1,4 +1,14 @@
--- ---
- name: WireGuard Deployment
hosts: wireguard
gather_facts: true
become: true
roles:
- role: githubixx.ansible_role_wireguard
when: applications.wireguard.enabled | default(false) | bool
tags: wireguard, apps
- name: Application Deployment - name: Application Deployment
hosts: servers hosts: servers
gather_facts: true gather_facts: true
@@ -6,26 +16,32 @@
serial: 1 serial: 1
roles: roles:
- role: robertdebock.dnsmasq
when: applications.dnsmasq.enabled | default(false) | bool
tags: dnsmasq, apps
- role: borgbase.ansible_role_borgbackup - role: borgbase.ansible_role_borgbackup
when: applications.borgbackup.enabled | bool when: applications.borgbackup.enabled | default(false) | bool
tags: borgbackup, apps tags: borgbackup, apps
- role: artis3n.tailscale.machine - role: artis3n.tailscale.machine
when: applications.tailscale.enabled | bool when: applications.tailscale.enabled | default(false) | bool
vars:
state: "{{ applications.tailscale.state | default('latest') }}"
tags: tailscale, apps tags: tailscale, apps
- role: salt - role: salt
when: applications.salt.enabled | bool when: applications.salt.enabled | default(false) | bool
tags: salt, apps tags: salt, apps
- role: dokploy - role: dokploy
when: (applications.dokploy.enabled and containers.docker.enabled) | bool when: (applications.dokploy.enabled | default(false) and containers.docker.enabled | default(false)) | bool
vars: vars:
dokploy_state: "{{ applications.dokploy.state | default('present') }}" dokploy_state: "{{ applications.dokploy.state | default('present') }}"
tags: dokploy, apps tags: dokploy, apps
- role: coolify - role: coolify
when: (applications.coolify.enabled and containers.docker.enabled) | bool when: (applications.coolify.enabled | default(false) and containers.docker.enabled | default(false)) | bool
vars: vars:
coolify_state: "{{ applications.coolify.state | default('present') }}" coolify_state: "{{ applications.coolify.state | default('present') }}"
tags: coolify, apps tags: coolify, apps
+6
View File
@@ -5,6 +5,12 @@
become: true become: true
pre_tasks: pre_tasks:
- name: Configure Debian package repositories
ansible.builtin.import_role:
name: common
tasks_from: repositories
tags: system, updates, repositories
- name: Update apt cache and upgrade system - name: Update apt cache and upgrade system
ansible.builtin.apt: ansible.builtin.apt:
update_cache: true update_cache: true
+7
View File
@@ -15,6 +15,9 @@ common_journal_retention_days: 21
common_journal_max_disk_limit: "5%" common_journal_max_disk_limit: "5%"
common_atop_retention_days: 3 common_atop_retention_days: 3
# Optimizations
enable_nic_offloads: false
# User management # User management
admin_users: admin_users:
- name: "{{ ansible_user }}" - name: "{{ ansible_user }}"
@@ -38,6 +41,10 @@ applications:
enabled: false enabled: false
tailscale: tailscale:
enabled: false enabled: false
wireguard:
enabled: false
dnsmasq:
enabled: false
salt: salt:
enabled: false enabled: false
coolify: coolify:
+2 -3
View File
@@ -24,6 +24,7 @@ _docker_daemon_options_base:
ipv6: true ipv6: true
ip-forward: true ip-forward: true
firewall-backend: nftables
iptables: true iptables: true
ip6tables: true ip6tables: true
ip-masq: false ip-masq: false
@@ -35,11 +36,9 @@ _docker_daemon_options_base:
default-network-opts: {} default-network-opts: {}
dns: dns:
- "100.100.100.100"
- "1.1.1.1" - "1.1.1.1"
- "8.8.8.8" - "8.8.8.8"
dns-search: dns-search: []
- "headnet.itqdev.xyz"
dns-opts: [] dns-opts: []
storage-driver: "overlay2" storage-driver: "overlay2"
+13
View File
@@ -1,4 +1,15 @@
--- ---
debian_apt_mirror: https://deb.debian.org/debian
debian_apt_security_mirror: https://deb.debian.org/debian-security
debian_apt_components:
- main
- contrib
debian_apt_backports_enabled: false
# Install Brendan Gregg's PMC tools
pmc_cloud_tools_enabled: false
pmc_cloud_tools_repo: https://git.itqdev.xyz/Infrastructure/pmc-cloud-tools.git
system_packages: system_packages:
essential: essential:
- curl - curl
@@ -34,6 +45,7 @@ system_packages:
- python3-docker - python3-docker
- acpi - acpi
- attr - attr
- pahole
monitoring: monitoring:
- htop - htop
- atop - atop
@@ -58,6 +70,7 @@ system_packages:
- mtr - mtr
- ngrep - ngrep
- tcpflow - tcpflow
- pwru
security: security:
- auditd - auditd
- fail2ban - fail2ban
+7
View File
@@ -4,6 +4,8 @@ collections:
version: 2.1.0 version: 2.1.0
- name: community.general - name: community.general
version: 11.4.0 version: 11.4.0
- name: ansible.utils
version: 6.1.0
- name: community.docker - name: community.docker
version: 4.8.1 version: 4.8.1
- name: artis3n.tailscale - name: artis3n.tailscale
@@ -21,3 +23,8 @@ roles:
version: 3.0.0 version: 3.0.0
- src: borgbase.ansible_role_borgbackup - src: borgbase.ansible_role_borgbackup
version: v1.1.3 version: v1.1.3
- src: https://github.com/githubixx/ansible-role-wireguard.git
name: githubixx.ansible_role_wireguard
version: 19.0.0
- src: robertdebock.dnsmasq
version: 2.2.0
+5
View File
@@ -7,3 +7,8 @@
- name: Reload systemd - name: Reload systemd
ansible.builtin.systemd: ansible.builtin.systemd:
daemon_reload: true daemon_reload: true
- name: Restart networking
ansible.builtin.service:
name: networking
state: restarted
+29
View File
@@ -12,6 +12,35 @@
cache_valid_time: 3600 cache_valid_time: 3600
tags: packages tags: packages
- name: Install PMC cloud tools
become: true
when: pmc_cloud_tools_enabled | default(false) | bool
tags: packages
block:
- name: Install perf for PMC cloud tools
ansible.builtin.apt:
name: linux-perf
state: present
- name: Clone PMC cloud tools
ansible.builtin.git:
repo: "{{ pmc_cloud_tools_repo }}"
dest: /opt/pmc-cloud-tools
version: master
- name: Link PMC cloud tools into PATH
ansible.builtin.file:
src: "/opt/pmc-cloud-tools/{{ item }}"
dest: "/usr/local/bin/{{ item }}"
state: link
loop:
- cpucache
- icache
- pmcarch
- pmcipc
- resstalls
- tlbstat
- name: Set hostname and FQDN - name: Set hostname and FQDN
tags: system tags: system
block: block:
+11 -1
View File
@@ -43,7 +43,7 @@
notify: Reload systemd notify: Reload systemd
tags: optimization tags: optimization
- name: Enable and start GPU unbind servie - name: Enable and start GPU unbind service
become: true become: true
ansible.builtin.systemd: ansible.builtin.systemd:
name: gpu-unbind-{{ item.label }} name: gpu-unbind-{{ item.label }}
@@ -51,3 +51,13 @@
state: started state: started
loop: "{{ gpu_unbind_devices }}" loop: "{{ gpu_unbind_devices }}"
tags: optimization tags: optimization
- name: NIC offloads
when: enable_nic_offloads | bool
become: true
ansible.builtin.template:
src: nic-offloads.j2
dest: /etc/network/if-up.d/{{ ansible_default_ipv4.interface }}
mode: "0755"
notify: Restart networking
tags: optimization
+36
View File
@@ -0,0 +1,36 @@
---
- name: Verify the host is Debian
ansible.builtin.assert:
that:
- ansible_distribution == 'Debian'
- ansible_distribution_release | length > 0
fail_msg: Debian APT repository configuration requires a Debian host with a release codename.
- name: Check for legacy APT sources list
ansible.builtin.stat:
path: /etc/apt/sources.list
register: common_debian_apt_legacy_sources
- name: Disable official Debian entries in legacy sources list
ansible.builtin.replace:
path: /etc/apt/sources.list
regexp: '^((?:deb|deb-src)\s+(?:\[[^]]+\]\s+)?https?://(?:deb\.debian\.org/debian(?:-security)?|security\.debian\.org/debian-security|ftp\.debian\.org/debian(?:-security)?)\s+.*)$'
replace: '# Managed in /etc/apt/sources.list.d/debian.sources: \1'
backup: true
when: common_debian_apt_legacy_sources.stat.exists
register: common_debian_apt_legacy_changed
- name: Configure Debian APT sources
ansible.builtin.template:
src: debian.sources.j2
dest: /etc/apt/sources.list.d/debian.sources
owner: root
group: root
mode: '0644'
backup: true
register: common_debian_apt_sources_changed
- name: Refresh APT cache when repositories change
ansible.builtin.apt:
update_cache: true
when: common_debian_apt_legacy_changed.changed or common_debian_apt_sources_changed.changed
+20
View File
@@ -0,0 +1,20 @@
# Managed by Ansible
Types: deb
URIs: {{ debian_apt_mirror }}
Suites: {{ ansible_distribution_release }} {{ ansible_distribution_release }}-updates
Components: {{ debian_apt_components | join(' ') }}
Signed-By: /usr/share/keyrings/debian-archive-keyring.gpg
Types: deb
URIs: {{ debian_apt_security_mirror }}
Suites: {{ ansible_distribution_release }}-security
Components: {{ debian_apt_components | join(' ') }}
Signed-By: /usr/share/keyrings/debian-archive-keyring.gpg
{% if debian_apt_backports_enabled | bool %}
Types: deb
URIs: {{ debian_apt_mirror }}
Suites: {{ ansible_distribution_release }}-backports
Components: {{ debian_apt_components | join(' ') }}
Signed-By: /usr/share/keyrings/debian-archive-keyring.gpg
{% endif %}
+3
View File
@@ -0,0 +1,3 @@
#!/usr/bin/env sh
ethtool -K {{ ansible_default_ipv4.interface }} rx-udp-gro-forwarding on rx-gro-list off
+10
View File
@@ -13,6 +13,11 @@
ansible.builtin.include_tasks: detect.yaml ansible.builtin.include_tasks: detect.yaml
tags: always tags: always
- name: Disable Coolify proxy watchdog
ansible.builtin.include_tasks: watchdog_disable.yaml
when: coolify_state in ['absent', 'stopped']
tags: coolify, proxy
- name: Uninstall Coolify - name: Uninstall Coolify
ansible.builtin.include_tasks: delete.yaml ansible.builtin.include_tasks: delete.yaml
when: coolify_state == 'absent' when: coolify_state == 'absent'
@@ -60,6 +65,11 @@
- name: Ensure services are running - name: Ensure services are running
ansible.builtin.include_tasks: start.yaml ansible.builtin.include_tasks: start.yaml
- name: Configure Coolify proxy watchdog
ansible.builtin.include_tasks: watchdog.yaml
when: coolify_state in ['present', 'latest']
tags: coolify, proxy
- name: Show Coolify status - name: Show Coolify status
ansible.builtin.debug: ansible.builtin.debug:
msg: msg:
+1
View File
@@ -8,6 +8,7 @@
pull: always pull: always
wait: true wait: true
wait_timeout: "{{ coolify_compose_wait_timeout }}" wait_timeout: "{{ coolify_compose_wait_timeout }}"
remove_orphans: true
tags: coolify, docker, start tags: coolify, docker, start
- name: Wait for Coolify HTTP to respond - name: Wait for Coolify HTTP to respond
+29
View File
@@ -0,0 +1,29 @@
---
- name: Deploy Coolify proxy watchdog script
become: true
ansible.builtin.template:
src: proxy-watchdog.sh.j2
dest: /usr/local/sbin/coolify-proxy-watchdog
owner: root
group: root
mode: "0750"
- name: Deploy Coolify proxy watchdog units
become: true
ansible.builtin.template:
src: "{{ item }}.j2"
dest: "/etc/systemd/system/{{ item }}"
owner: root
group: root
mode: "0644"
loop:
- coolify-proxy-watchdog.service
- coolify-proxy-watchdog.timer
- name: Enable Coolify proxy watchdog timer
become: true
ansible.builtin.systemd:
name: coolify-proxy-watchdog.timer
daemon_reload: true
enabled: true
state: started
+34
View File
@@ -0,0 +1,34 @@
---
- name: Check for Coolify proxy watchdog timer
become: true
ansible.builtin.stat:
path: /etc/systemd/system/coolify-proxy-watchdog.timer
register: _coolify_watchdog_timer
- name: Disable Coolify proxy watchdog timer
become: true
ansible.builtin.systemd:
name: coolify-proxy-watchdog.timer
enabled: false
state: stopped
when: _coolify_watchdog_timer.stat.exists
- name: Remove Coolify proxy watchdog files
become: true
ansible.builtin.file:
path: "{{ item }}"
state: absent
loop:
- /usr/local/sbin/coolify-proxy-watchdog
- /etc/systemd/system/coolify-proxy-watchdog.service
- /etc/systemd/system/coolify-proxy-watchdog.timer
register: _coolify_watchdog_removed
when: coolify_state == 'absent'
- name: Reload systemd after removing Coolify proxy watchdog
become: true
ansible.builtin.systemd:
daemon_reload: true
when:
- coolify_state == 'absent'
- _coolify_watchdog_removed is changed
@@ -0,0 +1,8 @@
[Unit]
Description=Recover Traefik proxies after Docker socket connection failures
After=docker.service
[Service]
Type=oneshot
ExecStart=/usr/local/sbin/coolify-proxy-watchdog
TimeoutStartSec=45s
@@ -0,0 +1,10 @@
[Unit]
Description=Check Traefik Docker socket connections
[Timer]
OnBootSec=2min
OnUnitActiveSec=1min
Unit=coolify-proxy-watchdog.service
[Install]
WantedBy=timers.target
@@ -1,4 +1,4 @@
# Managed by Ansible — manual changes will be overwritten on next deployment # Managed by Ansible - changes will be overwritten on next deployment
services: services:
coolify: coolify:
image: "${REGISTRY_URL:-ghcr.io}/coollabsio/coolify:${LATEST_IMAGE:-latest}" image: "${REGISTRY_URL:-ghcr.io}/coollabsio/coolify:${LATEST_IMAGE:-latest}"
@@ -32,7 +32,7 @@ services:
- "${APP_PORT:-8000}" - "${APP_PORT:-8000}"
healthcheck: healthcheck:
test: curl --fail http://127.0.0.1:8080/api/health || exit 1 test: curl --fail http://127.0.0.1:8080/api/health || exit 1
interval: 5s interval: 30s
retries: 10 retries: 10
timeout: 2s timeout: 2s
@@ -47,7 +47,7 @@ services:
test: test:
- CMD-SHELL - CMD-SHELL
- pg_isready -U ${DB_USERNAME} -d ${DB_DATABASE:-coolify} - pg_isready -U ${DB_USERNAME} -d ${DB_DATABASE:-coolify}
interval: 5s interval: 30s
retries: 10 retries: 10
timeout: 2s timeout: 2s
@@ -59,7 +59,7 @@ services:
- coolify-redis:/data - coolify-redis:/data
healthcheck: healthcheck:
test: redis-cli ping test: redis-cli ping
interval: 5s interval: 30s
retries: 10 retries: 10
timeout: 2s timeout: 2s
@@ -90,7 +90,7 @@ services:
# test: # test:
# - CMD-SHELL # - CMD-SHELL
# - wget -qO- http://127.0.0.1:6001/ready && wget -qO- http://127.0.0.1:6002/ready || exit 1 # - wget -qO- http://127.0.0.1:6001/ready && wget -qO- http://127.0.0.1:6002/ready || exit 1
# interval: 5s # interval: 30s
# retries: 10 # retries: 10
# timeout: 2s # timeout: 2s
@@ -1,7 +1,9 @@
# Managed by Ansible — manual changes will be overwritten on next deployment # Managed by Ansible - manual changes will be overwritten on next deployment
services: services:
coolify: coolify:
container_name: coolify container_name: coolify
mem_limit: 768m
memswap_limit: 768m
restart: always restart: always
working_dir: /var/www/html working_dir: /var/www/html
extra_hosts: extra_hosts:
@@ -19,6 +21,8 @@ services:
postgres: postgres:
image: postgres:15-alpine image: postgres:15-alpine
container_name: coolify-db container_name: coolify-db
mem_limit: 64m
memswap_limit: 128m
restart: always restart: always
networks: networks:
- coolify - coolify
@@ -26,12 +30,16 @@ services:
redis: redis:
image: redis:8-alpine image: redis:8-alpine
container_name: coolify-redis container_name: coolify-redis
mem_limit: 32m
memswap_limit: 64m
restart: always restart: always
networks: networks:
- coolify - coolify
# soketi: # soketi:
# container_name: coolify-realtime # container_name: coolify-realtime
# mem_limit: 32m
# memswap_limit: 64m
# extra_hosts: # extra_hosts:
# - host.docker.internal:host-gateway # - host.docker.internal:host-gateway
# restart: always # restart: always
@@ -0,0 +1,39 @@
#!/usr/bin/env bash
set -u
docker info >/dev/null 2>&1 || exit 0
containers=$(timeout 10s docker ps --format '{% raw %}{{.Names}} {{.Image}}{% endraw %}') || exit 0
state_dir=/run/coolify-proxy-watchdog
mkdir -p "$state_dir"
while read -r container image; do
case "$container:$image" in
coolify-proxy:*|*traefik*) ;;
*) continue ;;
esac
now=$(date +%s)
state_file="$state_dir/$container"
last_restart=$(cat "$state_file" 2>/dev/null || true)
if [[ "$last_restart" =~ ^[0-9]+$ ]] && (( now - last_restart < 300 )); then
continue
fi
started_at=$(timeout 10s docker inspect --format '{% raw %}{{.State.StartedAt}}{% endraw %}' "$container") || continue
started_epoch=$(date -d "$started_at" +%s) || continue
if (( started_epoch > now - 120 )); then
since="$started_at"
else
since=2m
fi
logs=$(timeout 15s docker logs --since "$since" --tail 500 "$container" 2>&1) || continue
if printf '%s\n' "$logs" | grep -Ei 'docker\.sock|docker\.socket' | grep -Eiq 'connection refused|cannot connect|no such file or directory|connection reset|i/o timeout|context deadline exceeded'; then
printf '%s\n' "$now" > "$state_file"
if docker restart --time 10 "$container" >/dev/null; then
echo "Restarted $container after Docker socket connection failure"
else
echo "Failed to restart $container after Docker socket connection failure" >&2
fi
fi
done <<< "$containers"
+6 -5
View File
@@ -24,6 +24,7 @@
{% set blocked_ips = security_nftables_blocked_ips | default([]) %} {% set blocked_ips = security_nftables_blocked_ips | default([]) %}
{% set trusted_ips = security_nftables_trusted_ips | default([]) %} {% set trusted_ips = security_nftables_trusted_ips | default([]) %}
{% set allowed_port_ranges = security_nftables_allowed_port_ranges | default([]) %} {% set allowed_port_ranges = security_nftables_allowed_port_ranges | default([]) %}
{% set chain_priorities = security_nftables_chain_priorities | default({}) %}
{% set blocked_v4 = blocked_ips | select('match', '.*\\..*') | list %} {% set blocked_v4 = blocked_ips | select('match', '.*\\..*') | list %}
{% set blocked_v6 = blocked_ips | reject('match', '.*\\..*') | list %} {% set blocked_v6 = blocked_ips | reject('match', '.*\\..*') | list %}
@@ -91,7 +92,7 @@ table inet ansible_filter {
{% endif %} {% endif %}
chain input { chain input {
type filter hook input priority filter; policy {{ default_policy }}; type filter hook input priority {{ chain_priorities.input | default('filter') }}; policy {{ default_policy }};
# Conntrack: allow established, drop invalid # Conntrack: allow established, drop invalid
ct state established,related accept ct state established,related accept
@@ -182,7 +183,7 @@ table inet ansible_filter {
} }
chain forward { chain forward {
type filter hook forward priority filter; policy {{ forward_policy }}; type filter hook forward priority {{ chain_priorities.forward | default('filter') }}; policy {{ forward_policy }};
# Conntrack # Conntrack
ct state established,related accept ct state established,related accept
@@ -218,7 +219,7 @@ table inet ansible_filter {
} }
chain output { chain output {
type filter hook output priority filter; policy {{ output_policy }}; type filter hook output priority {{ chain_priorities.output | default('filter') }}; policy {{ output_policy }};
ct state established,related accept ct state established,related accept
@@ -236,7 +237,7 @@ table ip ansible_nat {
{% if dnat_rules | length > 0 %} {% if dnat_rules | length > 0 %}
chain prerouting { chain prerouting {
type nat hook prerouting priority dstnat; policy accept; type nat hook prerouting priority {{ chain_priorities.prerouting | default('dstnat') }}; policy accept;
{% for rule in dnat_rules %} {% for rule in dnat_rules %}
{% set proto = rule.proto | default('tcp') %} {% set proto = rule.proto | default('tcp') %}
@@ -263,7 +264,7 @@ table ip ansible_nat {
{% endif %} {% endif %}
{% if snat_rules | length > 0 or masquerade_interfaces | length > 0 %} {% if snat_rules | length > 0 or masquerade_interfaces | length > 0 %}
chain postrouting { chain postrouting {
type nat hook postrouting priority srcnat; policy accept; type nat hook postrouting priority {{ chain_priorities.postrouting | default('srcnat') }}; policy accept;
{% for rule in snat_rules %} {% for rule in snat_rules %}
{% set comment = ' comment "' + rule.comment + '"' if rule.comment is defined else '' %} {% set comment = ' comment "' + rule.comment + '"' if rule.comment is defined else '' %}