chef-recipes/containers/portainer/tasks.yml

103 lines
3.2 KiB
YAML
Raw Permalink Normal View History

2023-02-07 13:02:43 +00:00
# code: language=ansible
2023-02-03 17:04:29 +00:00
---
- hosts: all
name: Portainer container manager
tasks:
2023-02-06 08:59:41 +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:04:29 +00:00
- name: Stop running containers
become_user: containers
become: true
ansible.builtin.systemd:
scope: user
name: container-{{ item }}.service
state: stopped
loop:
- portainer
2023-08-01 08:59:37 +00:00
failed_when: false
2023-02-06 08:59:41 +00:00
- name: Pull portainer image
become_user: containers
become: true
containers.podman.podman_image:
name: docker.io/portainer/portainer-ce:latest
2023-02-03 17:04:29 +00:00
2023-02-06 08:59:41 +00:00
- name: Create traefik-portainer network
containers.podman.podman_network:
name: traefik-portainer
recreate: false
state: "present"
become_user: containers
become: true
2023-02-03 17:04:29 +00:00
2023-02-06 08:59:41 +00:00
- name: Create portainer data volume
containers.podman.podman_volume:
state: present
name: portainer
become_user: containers
become: true
2023-02-03 17:04:29 +00:00
2023-02-06 08:59:41 +00:00
- name: Create portainer instance
become_user: containers
become: true
containers.podman.podman_container:
name: portainer
image: docker.io/portainer/portainer-ce:latest
2023-02-06 08:59:41 +00:00
state: present
security_opt:
- label=type:container_runtime_t
volume:
- /run/user/{{ uid_containers.stdout }}/podman/podman.sock:/var/run/docker.sock:z
- portainer:/data:Z
network:
- traefik-portainer
label:
io.containers.autoupdate: "registry"
traefik.enable: "true"
traefik.http.routers.portainer.entrypoints: "https"
traefik.http.routers.portainer.rule: "Host(`{{ vault_domain }}`) && (PathPrefix(`/portainer/`) || Path(`/portainer`))"
2023-02-06 08:59:41 +00:00
traefik.http.routers.portainer.tls: "true"
traefik.http.routers.portainer.tls.certresolver: "wildcard"
traefik.http.routers.portainer.service: "portainer"
traefik.http.routers.portainer.middlewares: "force-trailing-slash@file,portainer-prefixstrip@docker"
traefik.http.middlewares.portainer-prefixstrip.stripprefix.prefixes: "/portainer"
2023-02-06 08:59:41 +00:00
traefik.http.services.portainer.loadbalancer.server.port: "9000"
traefik.docker.network: "traefik-portainer"
generate_systemd:
path: /home/containers/.config/systemd/user/
restart_policy: on-failure
2024-04-12 12:06:57 +00:00
requires: [container-traefik.service]
2023-02-06 08:59:41 +00:00
names: true
new: true
2023-02-03 17:04:29 +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-portainer.service
section: Service
option: "{{ item }}"
value: 3600
mode: "0664"
state: "present"
no_extra_spaces: true
loop:
- TimeoutStartSec
- TimeoutStopSec
2023-02-06 08:59:41 +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:
- portainer