chef-recipes/containers/traefik/tasks.yml

159 lines
4.3 KiB
YAML
Raw Normal View History

2023-02-07 13:02:43 +00:00
# code: language=ansible
2023-02-03 17:01:35 +00:00
---
- hosts: all
name: Traefik reverse proxy
tasks:
2023-02-06 09:12:02 +00:00
- name: Get containers UID
ansible.builtin.command: "id -u containers"
register: uid_containers
changed_when: uid_containers.rc != 0
2023-02-03 17:01:35 +00:00
- name: Stop running containers
become_user: containers
become: true
ansible.builtin.systemd:
scope: user
name: container-{{ item }}.service
state: stopped
loop:
- traefik
2023-08-01 08:59:37 +00:00
failed_when: false
2023-02-06 09:12:02 +00:00
- name: Permit traffic from any IP to http port
become: true
2023-02-06 09:11:03 +00:00
community.general.ufw:
2023-02-06 09:12:02 +00:00
direction: in
from_ip: any
proto: tcp
to_port: 80
rule: allow
2023-02-03 17:01:35 +00:00
2023-02-06 09:12:02 +00:00
- name: Permit traffic from any IP to https port
become: true
2023-02-06 09:11:03 +00:00
community.general.ufw:
2023-02-06 09:12:02 +00:00
direction: in
from_ip: any
proto: tcp
to_port: 443
rule: allow
2023-02-03 17:01:35 +00:00
2023-02-06 09:12:02 +00:00
- name: Pull traefik image
become_user: containers
become: true
containers.podman.podman_image:
name: docker.io/traefik:latest
2023-02-03 17:01:35 +00:00
2023-02-06 09:12:02 +00:00
- name: Change permission to traefik folder
become: true
ansible.builtin.file:
path: /etc/traefik
owner: containers
group: containers
mode: "0700"
2023-02-06 09:12:02 +00:00
state: directory
2023-02-03 17:01:35 +00:00
2023-02-06 09:12:02 +00:00
- name: Copy config directory
become: true
ansible.builtin.copy:
src: files/
dest: /etc/traefik/
owner: containers
group: containers
mode: "0600"
2023-02-03 17:01:35 +00:00
2023-02-06 09:12:02 +00:00
- name: Copy config files from templates
become: true
ansible.builtin.template:
src: "templates/{{ item }}.j2"
dest: "/etc/traefik/{{ item }}"
owner: containers
group: containers
mode: "0600"
2023-02-06 09:12:02 +00:00
loop:
- traefik.yml
- conf/cockpit.yml
2023-02-03 17:01:35 +00:00
2023-02-06 09:12:02 +00:00
- name: Create podman networks
containers.podman.podman_network:
name: "{{ item }}"
recreate: false
state: "present"
become_user: containers
become: true
loop:
2023-02-03 17:01:35 +00:00
- traefik
- traefik-portainer
- traefik-nextcloud
2023-02-06 09:12:02 +00:00
- traefik-gitea
2023-02-07 16:28:46 +00:00
- traefik-collabora
2023-02-15 13:03:22 +00:00
- traefik-heimdall
2023-02-06 09:12:02 +00:00
- name: Create traefik instance
become_user: containers
become: true
containers.podman.podman_container:
name: traefik
image: docker.io/traefik:latest
state: present
publish:
- "80:80"
- "443:443"
2023-02-06 09:12:02 +00:00
security_opt:
- label=type:container_runtime_t
volume:
- /run/user/{{ uid_containers.stdout }}/podman/podman.sock:/var/run/docker.sock:z
- /etc/traefik/:/etc/traefik:Z
network:
- traefik
- traefik-portainer
- traefik-nextcloud
- traefik-gitea
2023-02-07 16:28:46 +00:00
- traefik-collabora
2023-02-15 13:03:22 +00:00
- traefik-heimdall
2023-02-06 09:12:02 +00:00
cap_add:
- NET_ADMIN
label:
io.containers.autoupdate: "registry"
traefik.enable: "true"
traefik.http.middlewares.traefik-auth.basicauth.users: "{{ vault_traefik_basic_auth }}"
traefik.http.routers.traefik.entrypoints: "https"
traefik.http.routers.traefik.rule: "Host(`{{ vault_domain }}`) && (PathPrefix(`/api`) || Path(`/dashboard`))"
2023-02-06 09:12:02 +00:00
traefik.http.routers.traefik.middlewares: "traefik-auth@docker"
traefik.http.routers.traefik.tls: "true"
traefik.http.routers.traefik.tls.certresolver: "wildcard"
traefik.http.routers.traefik.tls.domains[0].main: "{{ inventory_hostname }}"
traefik.http.routers.traefik.service: "api@internal"
generate_systemd:
path: /home/containers/.config/systemd/user/
restart_policy: on-failure
names: true
new: true
2023-02-03 17:01:35 +00:00
2023-04-20 15:14:24 +00:00
- name: Change start and stop timeout limits
become_user: containers
become: true
community.general.ini_file:
path: /home/containers/.config/systemd/user/container-traefik.service
section: Service
option: "{{ item }}"
value: 3600
mode: "0664"
state: "present"
no_extra_spaces: true
loop:
- TimeoutStartSec
- TimeoutStopSec
2023-02-06 09:12:02 +00:00
- name: Start containers at boot
become_user: containers
become: true
ansible.builtin.systemd:
scope: user
name: container-{{ item }}.service
enabled: true
state: started
daemon_reload: true
loop:
- traefik