#SPDX-License-Identifier: MIT-0
---
# tasks file for role-nextcloud
- name: install nextcloud and dependencies
  ansible.builtin.package:
    name:
      - nextcloud
      - php-legacy-sodium
      - php-legacy-imagick
      - librsvg
      - php-legacy-igbinary
      - php-legacy-redis
      - php-legacy-fpm
    state: present

- name: deploy nextcloud php.ini file
  ansible.builtin.copy:
    src: files/nextcloud-php.ini
    dest: /etc/webapps/nextcloud/php.ini

- name: enforce symlink to nextclound config file
  ansible.builtin.file:
    src: /mnt/nextcloud/config.php
    dest: /etc/webapps/nextcloud/config/config.php
    state: link
    force: yes

- name: Create sessions directory
  ansible.builtin.file:
    path: /var/lib/nextcloud/sessions
    state: directory
    owner: nextcloud
    group: nextcloud
    mode: '0700'

- name: deploy php-fpm.ini
  ansible.builtin.copy:
    src: files/php-fpm.ini
    dest: /etc/php-legacy/php-fpm.ini

- name: ensure php-fpm.d directory exists
  ansible.builtin.file:
    path: /etc/php-legacy/php-fpm.d
    state: directory

- name: deploy fpm-nextcloud.conf
  ansible.builtin.copy:
    src: files/fpm-nextcloud.conf
    dest: /etc/php-legacy/php-fpm.d/nextcloud.conf

- name: ensure php-fpm override directory exists
  ansible.builtin.file:
    path: /etc/systemd/system/php-fpm-legacy.service.d/
    state: directory

- name: ensure php-fpm log directory exists
  ansible.builtin.file:
    path:
      - /var/log/php-fpm-legacy/
      - /var/log/php-fpm-legacy/access/
    state: directory

- name: deploy php-fpm systemd override
  ansible.builtin.copy:
    src: files/php-fpm-override.conf
    dest: /etc/systemd/system/php-fpm-legacy.service.d/override.conf
#notify php-fpm-legacy

- name: deploy nextcloud nginx file
  ansible.builtin.template:
    src: files/nginx-nextcloud.conf
    dest: /etc/nginx/conf.d/nextcloud.conf
#notify nginx

- name: ensure nextcloud-cron override directory exists
  ansible.builtin.file:
    path: /etc/systemd/system/nextcloud-cron.service.d/
    state: directory

- name: deploy nextcloud cron override
  ansible.builtin.copy:
    src: files/nextcloud-cron-override.conf
    dest: /etc/systemd/system/nextcloud-cron.service.d/override.conf

#- name: ensure nextcloud is running
#  service:
#    name: nextcloud
#    state: started
#    enabled: yes

# start/enable php-fpm-legacy