From d1e5f63efd6cc613f1f3f41180bf2968db8699ce Mon Sep 17 00:00:00 2001 From: Jake Howard Date: Tue, 28 Jan 2020 22:02:02 +0000 Subject: [PATCH] Add portainer compose file --- .../docker/files/portainer/docker-compose.yml | 16 ++++++++++ ansible/roles/docker/tasks/main.yml | 3 ++ ansible/roles/docker/tasks/portainer.yml | 30 +++++++++++++++++++ 3 files changed, 49 insertions(+) create mode 100644 ansible/roles/docker/files/portainer/docker-compose.yml create mode 100644 ansible/roles/docker/tasks/portainer.yml diff --git a/ansible/roles/docker/files/portainer/docker-compose.yml b/ansible/roles/docker/files/portainer/docker-compose.yml new file mode 100644 index 0000000..158f2d1 --- /dev/null +++ b/ansible/roles/docker/files/portainer/docker-compose.yml @@ -0,0 +1,16 @@ +version: '3' + +services: + portainer: + image: portainer/portainer + container_name: portainer + restart: unless-stopped + volumes: + - /var/run/docker.sock:/var/run/docker.sock + - ./data:/data + labels: + - "traefik.enable=true" + - "traefik.http.routers.portainer.rule=Host(`portainer.jakehoward.tech`)" + - "traefik.http.routers.portainer.tls=true" + - "traefik.http.routers.portainer.tls.certresolver=le" + - "traefik.http.routers.portainer.middlewares=internal-only@file" diff --git a/ansible/roles/docker/tasks/main.yml b/ansible/roles/docker/tasks/main.yml index 078a4cf..e450377 100644 --- a/ansible/roles/docker/tasks/main.yml +++ b/ansible/roles/docker/tasks/main.yml @@ -9,3 +9,6 @@ - name: Install watchtower include: watchtower.yml + +- name: Install portainer + include: portainer.yml diff --git a/ansible/roles/docker/tasks/portainer.yml b/ansible/roles/docker/tasks/portainer.yml new file mode 100644 index 0000000..11f3749 --- /dev/null +++ b/ansible/roles/docker/tasks/portainer.yml @@ -0,0 +1,30 @@ +- name: Create portainer directory + file: + path: '/opt/portainer' + state: directory + owner: "{{ docker_user.name }}" + mode: "{{ docker_compose_directory_mask }}" + become: true + become_user: root + +- name: Install portainer config + template: + src: files/portainer/docker-compose.yml + dest: "/opt/portainer/docker-compose.yml" + mode: "{{ docker_compose_file_mask }}" + owner: "{{ docker_user.name }}" + register: compose_file + become: true + become_user: root + +- name: Cycle portainer container + docker_compose: + project_src: /opt/portainer + pull: true + remove_orphans: true + remove_volumes: true + state: "{{ item }}" + when: compose_file.changed + loop: + - absent + - present