Initial Ansible automation for hobbs.farm infrastructure
Complete IaC covering: - 14 roles: common, docker, traefik, vaultwarden, monitoring, media, matrix, home_assistant, frigate, adguard, gitea, semaphore, openclaw, security, backup - Inventory for all hosts (Peggy, Bart, Yoda, NAS, Firewalla) - Stack playbooks: core-infrastructure, monitoring, media, communication, automation, smarthome, security-hardening - Maintenance playbooks: update-containers, backup, health-check - Production Docker Compose templates with Traefik labels - Security hardening (sysctl, auditd, UFW, fail2ban) - Automated backups with retention policy
This commit is contained in:
@@ -0,0 +1,10 @@
|
||||
---
|
||||
traefik_version: "v3.1"
|
||||
traefik_image: "traefik:{{ traefik_version }}"
|
||||
traefik_compose_dir: "{{ docker_compose_base }}/core-infrastructure"
|
||||
traefik_data_dir: /data/traefik
|
||||
traefik_acme_email: "{{ vault_acme_email }}"
|
||||
cloudflare_api_token: "{{ vault_cloudflare_api_token }}"
|
||||
traefik_log_level: INFO
|
||||
traefik_dashboard_enabled: true
|
||||
traefik_dashboard_host: "traefik.{{ domain }}"
|
||||
@@ -0,0 +1,6 @@
|
||||
---
|
||||
- name: Restart traefik stack
|
||||
community.docker.docker_compose_v2:
|
||||
project_src: "{{ traefik_compose_dir }}"
|
||||
state: present
|
||||
recreate: always
|
||||
@@ -0,0 +1,41 @@
|
||||
---
|
||||
- name: Create Traefik directories
|
||||
ansible.builtin.file:
|
||||
path: "{{ item }}"
|
||||
state: directory
|
||||
owner: glyptic
|
||||
group: docker
|
||||
mode: "0755"
|
||||
loop:
|
||||
- "{{ traefik_compose_dir }}"
|
||||
- "{{ traefik_data_dir }}"
|
||||
- "{{ traefik_data_dir }}/acme"
|
||||
- "{{ traefik_data_dir }}/dynamic"
|
||||
tags: [traefik]
|
||||
|
||||
- name: Ensure acme.json exists with correct permissions
|
||||
ansible.builtin.file:
|
||||
path: "{{ traefik_data_dir }}/acme/acme.json"
|
||||
state: touch
|
||||
owner: root
|
||||
group: root
|
||||
mode: "0600"
|
||||
modification_time: preserve
|
||||
access_time: preserve
|
||||
tags: [traefik]
|
||||
|
||||
- name: Deploy Traefik compose file
|
||||
ansible.builtin.template:
|
||||
src: docker-compose.yml.j2
|
||||
dest: "{{ traefik_compose_dir }}/docker-compose.yml"
|
||||
owner: glyptic
|
||||
group: docker
|
||||
mode: "0644"
|
||||
notify: Restart traefik stack
|
||||
tags: [traefik]
|
||||
|
||||
- name: Start Traefik stack
|
||||
community.docker.docker_compose_v2:
|
||||
project_src: "{{ traefik_compose_dir }}"
|
||||
state: present
|
||||
tags: [traefik]
|
||||
@@ -0,0 +1,46 @@
|
||||
services:
|
||||
traefik:
|
||||
image: {{ traefik_image }}
|
||||
container_name: traefik
|
||||
restart: unless-stopped
|
||||
security_opt:
|
||||
- no-new-privileges:true
|
||||
ports:
|
||||
- "80:80"
|
||||
- "443:443"
|
||||
environment:
|
||||
CF_DNS_API_TOKEN: {{ cloudflare_api_token }}
|
||||
volumes:
|
||||
- /var/run/docker.sock:/var/run/docker.sock:ro
|
||||
- {{ traefik_data_dir }}/acme/acme.json:/acme.json
|
||||
- {{ traefik_data_dir }}/dynamic:/dynamic
|
||||
command:
|
||||
- --api.dashboard={{ traefik_dashboard_enabled | lower }}
|
||||
- --log.level={{ traefik_log_level }}
|
||||
- --providers.docker=true
|
||||
- --providers.docker.exposedbydefault=false
|
||||
- --providers.docker.network={{ docker_network_name }}
|
||||
- --providers.file.directory=/dynamic
|
||||
- --providers.file.watch=true
|
||||
- --entrypoints.web.address=:80
|
||||
- --entrypoints.web.http.redirections.entrypoint.to=websecure
|
||||
- --entrypoints.websecure.address=:443
|
||||
- --certificatesresolvers.cloudflare.acme.dnschallenge=true
|
||||
- --certificatesresolvers.cloudflare.acme.dnschallenge.provider=cloudflare
|
||||
- --certificatesresolvers.cloudflare.acme.email={{ traefik_acme_email }}
|
||||
- --certificatesresolvers.cloudflare.acme.storage=/acme.json
|
||||
- --certificatesresolvers.cloudflare.acme.dnschallenge.resolvers=1.1.1.1:53,1.0.0.1:53
|
||||
labels:
|
||||
traefik.enable: "true"
|
||||
traefik.http.routers.traefik.rule: "Host(`{{ traefik_dashboard_host }}`)"
|
||||
traefik.http.routers.traefik.entrypoints: websecure
|
||||
traefik.http.routers.traefik.tls.certresolver: cloudflare
|
||||
traefik.http.routers.traefik.tls.domains[0].main: "{{ domain }}"
|
||||
traefik.http.routers.traefik.tls.domains[0].sans: "*.{{ domain }}"
|
||||
traefik.http.routers.traefik.service: api@internal
|
||||
networks:
|
||||
- {{ docker_network_name }}
|
||||
|
||||
networks:
|
||||
{{ docker_network_name }}:
|
||||
external: true
|
||||
Reference in New Issue
Block a user