---
- name: setup nextcloud containers
  docker_compose:
    project_name: "nextcloud"
    pull: "yes"
    definition:
      services:
        postgres:
          image: "postgres:10"
          restart: "unless-stopped"
          networks:
            - "nextcloud"
          volumes:
            - "{{ nextcloud.volume_folder }}/postgres:/var/lib/postgresql/data"
          environment: 
            POSTGRES_DB: "nextcloud"
            POSTGRES_PASSWORD: "{{ postgres_passwords.nextcloud }}"
            POSTGRES_USER: "nextcloud"
        
        app:
          image: "nextcloud:22-apache"
          restart: "unless-stopped"
          networks:
            - "nextcloud"
            - "external_services"
          volumes:
          - "{{ nextcloud.volume_folder }}/app:/var/www/html"
          environment:
            VIRTUAL_HOST: "{{ nextcloud.domain }}"
            LETSENCRYPT_HOST: "{{ nextcloud.domain }}"
            LETSENCRYPT_EMAIL: "{{ letsencrypt_email }}"
            POSTGRES_HOST: "nextcloud_postgres_1"
            POSTGRES_DB: "nextcloud"
            POSTGRES_USER: "nextcloud"
            POSTGRES_PASSWORD: "{{ postgres_passwords.nextcloud }}"

      networks:
          nextcloud:
          postfix:
            external: true
          external_services:
            external: true