summaryrefslogtreecommitdiffstats
path: root/roles/nextcloud/tasks/main.yml
blob: 69a662d79373aac9bb5e51e392f15d6f51fef0be (plain)
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
- name: Install PHP
  apt: pkg={{ packages }}
  vars:
    packages:
    - php-cli
    - php-bcmath
    - php-fpm
    - php-apcu
    - php-gd
    - php-gmp
    - php-imagick
    - php-mbstring
    - php-xml
    - php-curl
    - php-intl
    - php-ldap
    - php-mysql
    - php-zip
    - php-json
    - php-gmp

- name: Configure PHP 7.4 Zend opcache
  lineinfile: dest=/etc/php/7.4/fpm/php.ini
              regexp='^;?{{ item.var }}\\s*='
              line="{{ item.var }} = {{ item.value }}"
              owner=root group=root
              mode=0644
  with_items:
    - { var: opcache.memory_consumption,      value: 512 }
    - { var: opcache.revalidate_freq,         value: 180 }
    - { var: opcache.interned_strings_buffer, value: 12  }
  notify:
    - Restart php7.4-fpm

- name: Configure PHP 7.4 CLI
  lineinfile: dest=/etc/php/7.4/cli/php.ini
              regexp='^;?{{ item.var }}\\s*='
              line="{{ item.var }} = {{ item.value }}"
              owner=root group=root
              mode=0644
  with_items:
    - { var: apc.enable_cli, value: 1 }

- name: Create '_nextcloud' user
  user: name=_nextcloud system=yes
        group=nogroup
        createhome=no
        home=/nonexistent
        shell=/usr/sbin/nologin
        password=!
        state=present

- name: Delete PHP 7.4 FPM's www pool
  file: path=/etc/php/7.4/fpm/pool.d/www.conf state=absent
  notify:
    - Restart php7.4-fpm

- name: Configure PHP 7.4 FPM's nextcloud pool
  copy: src=etc/php/fpm/pool.d/nextcloud.conf
        dest=/etc/php/7.4/fpm/pool.d/nextcloud.conf
        owner=root group=root
        mode=0644
  notify:
    - Restart php7.4-fpm

- name: Start php7.4-fpm
  service: name=php7.4-fpm state=started

- name: Copy /etc/cron.d/nextcloud
  copy: src=etc/cron.d/nextcloud
        dest=/etc/cron.d/nextcloud
        owner=root group=root
        mode=0644

- name: Copy /etc/nginx/sites-available/nextcloud
  copy: src=etc/nginx/sites-available/nextcloud
        dest=/etc/nginx/sites-available/nextcloud
        owner=root group=root
        mode=0644
  register: r1
  notify:
    - Restart Nginx

- name: Create /etc/nginx/sites-enabled/nextcloud
  file: src=../sites-available/nextcloud
        dest=/etc/nginx/sites-enabled/nextcloud
        owner=root group=root
        state=link force=yes
  register: r2
  notify:
    - Restart Nginx

- name: Copy HPKP header snippet
  # never modify the pined pubkeys as we don't want to lock out our users
  template: src=etc/nginx/snippets/cloud.fripost.org.hpkp-hdr.j2
            dest=/etc/nginx/snippets/cloud.fripost.org.hpkp-hdr
            validate=/bin/false
            owner=root group=root
            mode=0644
  register: r3
  notify:
    - Restart Nginx

- name: Start Nginx
  service: name=nginx state=started
  when: not (r1.changed or r2.changed or r3.changed)

- meta: flush_handlers

- name: Fetch Nginx's X.509 certificate
  # Ensure we don't fetch private data
  become: False
  fetch_cmd: cmd="openssl x509 -noout -pubkey"
             stdin=/etc/nginx/ssl/cloud.fripost.org.pem
             dest=certs/public/cloud.fripost.org.pub
  tags:
    - genkey

- import_tasks: ldap.yml
  when: "'LDAP_provider' not in group_names"
  tags:
    - ldap

# Note: intentionally don't set an owner/group as we don't want to set
# ownership unless the path is a mountpoint.  The service will fail
# unless the data directory is mounted and accessible, and that's what
# we want.
- name: Create directory /mnt/nextcloud-data
  file: path=/mnt/nextcloud-data
        state=directory
        mode=0700

- name: Create directory /var/www/nextcloud
  file: path=/var/www/nextcloud
        state=directory
        owner=root group=root
        mode=0755

# Note: Nextcloud doesn't like symlinked apps
# * https://github.com/nextcloud/server/issues/10437
# * https://github.com/nextcloud/server/issues/13556
- name: Create directory /var/www/nextcloud/apps
  file: path=/var/www/nextcloud/apps
        state=directory
        owner=_nextcloud group=nogroup
        mode=0755

- name: Create directory /var/log/nextcloud
  file: path=/var/log/nextcloud
        state=directory
        owner=_nextcloud group=adm
        mode=0750

- name: Create directory /var/cache/nextcloud
  file: path=/var/cache/nextcloud
        state=directory
        owner=_nextcloud group=nogroup
        mode=0700

- name: Copy Nextcloud logrotate snippet
  copy: src=etc/logrotate.d/nextcloud
        dest=/etc/logrotate.d/nextcloud
        owner=root group=root
        mode=0644
  tags:
    - logrotate

- name: Install redis-server
  apt: pkg={{ packages }}
  vars:
    packages:
    - php-redis
    - redis-server

- name: Configure Redis
  lineinfile: dest=/etc/redis/redis.conf
              regexp='^#?\\s*{{ item.var }}\\s+'
              line="{{ item.var }} {{ item.value }}"
              owner=redis group=redis
              mode=0640
  with_items:
    - { var: port,           value: 0 }
    - { var: unixsocket,     value: /run/redis/redis-server.sock }
    - { var: unixsocketperm, value: 660 }
  notify:
    - Restart Redis

- name: Start redis-server
  service: name=redis-server state=started

- name: Add '_nextcloud' user to 'redis' group
  user: name=_nextcloud groups=redis append=yes
  notify:
    - Restart php7.4-fpm

- name: Install other Nextcloud dependencies
  apt: pkg={{ packages }}
  vars:
    packages:
    - libmagickcore-6.q16-6-extra