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
|
|
|
|
2023-02-15 13:02:20 +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-15 13:02:20 +00:00
|
|
|
|
2023-02-06 08:59:41 +00:00
|
|
|
- name: Pull portainer image
|
|
|
|
become_user: containers
|
|
|
|
become: true
|
|
|
|
containers.podman.podman_image:
|
2023-02-07 13:04:44 +00:00
|
|
|
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
|
2023-02-07 13:04:44 +00:00
|
|
|
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"
|
2023-02-15 13:00:52 +00:00
|
|
|
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"
|
2023-02-15 13:00:52 +00:00
|
|
|
traefik.http.routers.portainer.middlewares: "force-trailing-slash@file,portainer-prefixstrip@docker"
|
2023-02-07 13:04:44 +00:00
|
|
|
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
|
2023-04-17 12:40:34 +00:00
|
|
|
time: 3600
|
2023-02-06 08:59:41 +00:00
|
|
|
names: true
|
|
|
|
new: true
|
2023-02-03 17:04:29 +00:00
|
|
|
|
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
|