summaryrefslogtreecommitdiff
path: root/roles/elevate/media/tasks/nextcloud.yml
blob: e9be69d2c70c86af0cec472dd2428a31beb977a3 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
---
- name: preare nextcloud disks
  import_tasks: nextcloud-lvm.yml

- name: create nextcloud config directory
  file:
    path: /srv/nextcloud/config/
    state: directory

- name: install nextcloud fpm config snippet
  template:
    src: nextcloud-fpm.conf.j2
    dest: /srv/nextcloud/config/nextcloud-fpm.conf


- name: create docker build-context for patched nextcloud image
  file:
    path: /srv/nextcloud/docker/
    state: directory

- name: install Dockerfile for patched nextcloud image
  template:
    src: nextcloud-Dockerfile.j2
    dest: /srv/nextcloud/docker/Dockerfile
  register: nextcloud_dockerfile

- name: build patched nextcloud image
  docker_image:
    state: present
    name: nextcloud
    tag: "{{ inventory_hostname }}"
    source: build
    build:
      path: /srv/nextcloud/docker/
      pull: no
    force_source: "{{ nextcloud_dockerfile.changed }}"

### TODO: set mysql variables:
###   <snip>
###   [mysqld]
###   transaction_isolation = READ-COMMITTED
###   binlog_format = ROW
###   </snip>

- name: create nextcloud database
  mysql_db:
    login_user: root
    login_unix_socket: /var/run/mysqld/mysqld.sock
    db: "{{ nextcloud_db.db }}"
    encoding: utf8mb4
    collation: utf8mb4_general_ci
    state: present

- name: create nextcloud database user
  mysql_user:
    login_user: root
    login_unix_socket: /var/run/mysqld/mysqld.sock
    name: "{{ nextcloud_db.user }}"
    password: "{{ nextcloud_db.password }}"
    priv: "{{ nextcloud_db.db }}.*:SELECT,INSERT,UPDATE,DELETE,CREATE,DROP,INDEX,ALTER,CREATE TEMPORARY TABLES"
    state: present


## to purge exisiting installation run the following commands (!!! will delete all data and the DB !!!):
#
# systemctl disable nextcloud-cron.timer
# systemctl stop nextcloud-cron.timer
# systemctl disable nextcloud-rescan.timer
# systemctl stop nextcloud-rescan.timer
# systemctl disable nextcloud.service
# systemctl stop nextcloud.service
# docker rm nextcloud.service
# rm -rf /srv/nextcloud/config/nextcloud
# rm -rf /srv/ncdata/nextcloud
# rm -rf /srv/nextcloud/www
# echo "drop database nextcloud;" | mysql --defaults-extra-file=/etc/mysql/debian.cnf
#
- name: check if nextcloud is already configured
  stat:
    path: /srv/nextcloud/config/nextcloud/config.php
  register: nextcloud_config_file

- name: running nextcloud installer
  when: not nextcloud_config_file.stat.exists
  docker_container:
    name: nextcloud.installer
    image: "nextcloud:{{ inventory_hostname }}"
    ## For some reasons a newly created database schema is not up to date with the recommended settings...
    ## so we will run the migrations right away. If in future this is not needed anymore use '/bin/true' here.
    command: 'su -p www-data -s /bin/sh -c "php /var/www/html/occ db:convert-filecache-bigint"'
    network_mode: host
    detach: no
    auto_remove: yes
    volumes:
      - /srv/nextcloud/www:/var/www/html
      - /srv/nextcloud/config/nextcloud-fpm.conf:/usr/local/etc/php-fpm.d/zzzzz.conf
      - /srv/nextcloud/config/nextcloud:/var/www/html/config
      - /srv/ncdata/nextcloud:/var/www/html/data
      - /srv/smbdata/share:/srv/external/share
    env:
      NEXTCLOUD_UPDATE: '1'
      NEXTCLOUD_TRUSTED_DOMAINS: "{{ nextcloud_hostnames | join(' ') }}"
      MYSQL_DATABASE: "{{ nextcloud_db.db }}"
      MYSQL_HOST: "127.0.0.1:3306"
      MYSQL_USER: "{{ nextcloud_db.user }}"
      MYSQL_PASSWORD: "{{ nextcloud_db.password }}"
      NEXTCLOUD_ADMIN_USER: "{{ nextcloud_admin.username }}"
      NEXTCLOUD_ADMIN_PASSWORD: "will-be-changed-later"

- name: configure nextcloud upload file size limit
  loop:
    - upload_max_filesize
    - post_max_size
  lineinfile:
    path: /srv/nextcloud/www/.user.ini
    regexp: '^{{ item }}='
    line: '{{ item }}={{ nextcloud_max_upload_size }}'

- name: configure nextcloud memory limit
  lineinfile:
    path: /srv/nextcloud/www/.user.ini
    regexp: '^memory_limit='
    line: 'memory_limit={{ nextcloud_memory_limit }}'

- name: install nextcloud service unit
  template:
    src: nextcloud.service.j2
    dest: /etc/systemd/system/nextcloud.service
  register: nextcloud_service

- name: make sure nextcloud is started and enabled
  systemd:
    name: nextcloud.service
    state: "{% if nextcloud_service.changed %}restarted{% else %}started{% endif %}"
    enabled: yes
    daemon_reload: yes

- name: basic nextcloud config
  import_tasks: nextcloud-config.yml

- name: install nextcloud systemd units
  loop:
    - cron.service
    - cron.timer
    - rescan.service
    - rescan.timer
  template:
    src: "nextcloud-{{ item }}.j2"
    dest: "/etc/systemd/system/nextcloud-{{ item }}"

- name: make sure nextcloud systemd timer are started and enabled
  loop:
    - cron
    - rescan
  systemd:
    name: "nextcloud-{{ item }}.timer"
    state: started
    enabled: yes
    daemon_reload: yes