summaryrefslogtreecommitdiff
path: root/roles/apps/nextcloud/tasks/main.yml
blob: d1a11b197c45a48c629204a89662aa50fb3a9fa5 (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
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
---
- name: create zfs datasets
  when: nextcloud_zfs is defined
  block:
  - name: create zfs base dataset
    zfs:
      name: "{{ nextcloud_zfs.pool }}/{{ nextcloud_zfs.name }}"
      state: present
      extra_zfs_properties: "{{ nextcloud_zfs.properties | dehumanize_zfs_properties | default(omit) }}"

  - name: create zfs volumes for instances
    loop: "{{ nextcloud_instances | dict2items }}"
    loop_control:
      label: "{{ item.key }} ({{ (item.value.zfs_properties | default({})).items() | map('join', '=') | join(', ') }})"
    zfs:
      name: "{{ nextcloud_zfs.pool }}/{{ nextcloud_zfs.name }}/{{ item.key }}"
      state: present
      extra_zfs_properties: "{{ item.value.zfs_properties | dehumanize_zfs_properties | default(omit) }}"

  - name: configure nextcloud base bath
    set_fact:
      nextcloud_base_path: "{{ (zfs_pools[nextcloud_zfs.pool].mountpoint, nextcloud_zfs.name) | path_join }}"


- name: create instance subdirectories
  when: nextcloud_zfs is not defined
  loop: "{{ nextcloud_instances | list }}"
  file:
    path: "{{ nextcloud_base_path }}/{{ item }}"
    state: directory



- name: add group for nextcloud app
  group:
    name: nc-app
    gid: "{{ nextcloud_app_gid }}"

- name: add user for nextcloud app
  user:
    name: nc-app
    uid: "{{ nextcloud_app_uid }}"
    group: nc-app
    password: "!"

- name: create nextcloud app subdirectory
  loop: "{{ nextcloud_instances | list }}"
  file:
    path: "{{ nextcloud_base_path }}/{{ item }}/nextcloud"
    owner: "{{ nextcloud_app_uid }}"
    group: "{{ nextcloud_app_gid }}"
    state: directory


- name: add group for nextcloud db
  group:
    name: nc-db
    gid: "{{ nextcloud_db_gid }}"

- name: add user for nextcloud db
  user:
    name: nc-db
    uid: "{{ nextcloud_db_uid }}"
    group: nc-db
    password: "!"

- name: create nextcloud database subdirectory
  loop: "{{ nextcloud_instances | dict2items }}"
  loop_control:
    label: "{{ item.key }} ({{ item.value.database.type }})"
  file:
    path: "{{ nextcloud_base_path }}/{{ item.key }}/{{ item.value.database.type }}"
    owner: "{{ nextcloud_db_uid }}"
    group: "{{ nextcloud_db_gid }}"
    state: directory


- name: add group for nextcloud redis
  group:
    name: nc-redis
    gid: "{{ nextcloud_redis_gid }}"

- name: add user for nextcloud redis
  user:
    name: nc-redis
    uid: "{{ nextcloud_redis_uid }}"
    group: nc-redis
    password: "!"

- name: create nextcloud database subdirectory
  loop: "{{ nextcloud_instances | list }}"
  file:
    path: "{{ nextcloud_base_path }}/{{ item }}/redis"
    owner: "{{ nextcloud_redis_uid }}"
    group: "{{ nextcloud_redis_gid }}"
    state: directory


- name: create auxiliary config directory
  loop: "{{ nextcloud_instances | list }}"
  file:
    path: "{{ nextcloud_base_path }}/{{ item }}/config"
    state: directory

- name: create apache vhost config
  loop: "{{ nextcloud_instances | list }}"
  template:
    src: apache-site.conf.j2
    dest: "{{ nextcloud_base_path }}/{{ item }}/config/apache-site.conf"

- name: configure apache to run on port 8080 only
  loop: "{{ nextcloud_instances | list }}"
  copy:
    content: |
      Listen 8080
    dest: "{{ nextcloud_base_path }}/{{ item }}/config/ports.conf"


- name: build custom image
  loop: "{{ nextcloud_instances | dict2items }}"
  loop_control:
    label: "{{ item.key }}"
  # when: "'custom_image' in item.value"
  include_tasks: custom-image.yml

- name: install pod manifest
  loop: "{{ nextcloud_instances | dict2items }}"
  loop_control:
    label: "{{ item.key }}"
  vars:
    kubernetes_standalone_pod:
      name: "nextcloud-{{ item.key }}"
      spec: "{{ lookup('template', 'pod-spec-with-{{ item.value.database.type }}.yml.j2') }}"
      mode: "0600"
      config_hash_items:
      - path: "{{ nextcloud_base_path }}/{{ item.key }}/config/apache-site.conf"
        properties:
        - checksum
      - path: "{{ nextcloud_base_path }}/{{ item.key }}/config/ports.conf"
        properties:
        - checksum
      - path: "{{ nextcloud_base_path }}/{{ item.key }}/build/Dockerfile"
        properties:
        - checksum
  include_role:
    name: kubernetes/standalone/pod


- name: install cron trigger script
  loop: "{{ nextcloud_instances | list }}"
  template:
    src: run-cron.sh.j2
    dest: "{{ nextcloud_base_path }}/{{ item }}/config/run-cron.sh"
    mode: 0755

- name: install template systemd unit for cron trigger
  template:
    src: cron@.service.j2
    dest: /etc/systemd/system/nextcloud-cron@.service

- name: install systemd timer unit
  loop: "{{ nextcloud_instances | list }}"
  template:
    src: cron-.timer.j2
    dest: "/etc/systemd/system/nextcloud-cron-{{ item }}.timer"

- name: start/enable cron trigger systemd timer
  loop: "{{ nextcloud_instances | list }}"
  systemd:
    daemon_reload: yes
    name: "nextcloud-cron-{{ item }}.timer"
    state: started
    enabled: yes


- name: configure nginx vhost
  loop: "{{ nextcloud_instances | dict2items }}"
  loop_control:
    label: "{{ item.key }}"
  vars:
    nginx_vhost:
      name: "nextcloud-{{ item.key }}"
      template: generic
      tls:
        certificate_provider: "{{ acme_client }}"
      hostnames: "{{ item.value.hostnames }}"
      locations:
        '/':
          proxy_pass: "http://127.0.0.1:{{ item.value.port }}"
          proxy_redirect:
          - redirect: "http://$host/"
            replacement: "https://$host/"
          - redirect: "http://$host:8080/"
            replacement: "https://$host/"
          extra_directives: |-
            client_max_body_size 0;
            types {
                text/javascript js mjs;
            }
  include_role:
    name: nginx/vhost


- name: install management scripts
  loop:
    - nextcloud-upgrade
    - nextcloud-occ
  template:
    src: "{{ item }}.j2"
    dest: "/usr/local/bin/{{ item }}"
    mode: 0755

## TODO:
# do this automatically!
- name: print info for new instance
  loop: "{{ nextcloud_instances | dict2items }}"
  loop_control:
    label: "{{ item.key }}"
  when: "'new' in item.value and item.value.new"
  pause:
    seconds: 5
    prompt: |
      ************* {{ item.key }} is a new instance
      **
      **  Go to https://{{ item.value.hostnames[0] }} and finalize the
      **  installation. After that run the following commands:
      **
      **  $ nextcloud-occ {{ item.key }} config:system:set default_phone_region --value='at'
      **  $ nextcloud-occ {{ item.key }} config:system:set memcache.locking --value '\OC\Memcache\Redis'
      **  $ nextcloud-occ {{ item.key }} config:system:set redis host --value '127.0.0.1'
      **  $ nextcloud-occ {{ item.key }} config:system:set redis port --type integer --value 6379
      **  $ nextcloud-occ {{ item.key }} config:system:set redis timeout --type float --value 0.0
      **  $ nextcloud-occ {{ item.key }} config:system:set redis password
      **
      **  in case you want to use an exteranl collabora/code server:
      **
      **  $ nextcloud-occ {{ item.key }} app:disable richdocumentscode
      **  $ nextcloud-occ {{ item.key }} app:remove richdocumentscode
      **
      ****************************************