From 44261862ad490e80be798b85e93466b4a58da303 Mon Sep 17 00:00:00 2001 From: Francesco Antognazza Date: Fri, 3 Feb 2023 18:04:29 +0100 Subject: [PATCH] Add portainer container --- containers/portainer/tasks.yml | 72 ++++++++++++++++++++++++++++++++++ 1 file changed, 72 insertions(+) create mode 100644 containers/portainer/tasks.yml diff --git a/containers/portainer/tasks.yml b/containers/portainer/tasks.yml new file mode 100644 index 0000000..8af51ce --- /dev/null +++ b/containers/portainer/tasks.yml @@ -0,0 +1,72 @@ +--- +- hosts: all + name: Portainer container manager + tasks: + - name: Get containers UID + ansible.builtin.command: "id -u containers" + register: uid_containers + changed_when: uid_containers.rc != 0 + + - name: Pull portainer image + become_user: containers + become: true + containers.podman.podman_image: + name: docker.io/portainer/portainer-ee:latest + + - name: Create traefik-portainer network + containers.podman.podman_network: + name: traefik-portainer + recreate: false + state: "present" + disable_dns: true + become_user: containers + become: true + + - name: Create portainer data volume + containers.podman.podman_volume: + state: present + name: portainer + become_user: containers + become: true + + - name: Create portainer instance + become_user: containers + become: true + containers.podman.podman_container: + name: portainer + image: docker.io/portainer/portainer-ee:latest + 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: "Path(`/portainer`)" + traefik.http.routers.portainer.tls: "true" + traefik.http.routers.portainer.tls.certresolver: "wildcard" + traefik.http.routers.portainer.service: "portainer" + 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 + names: true + new: true + + - 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