add group folder creation
This commit is contained in:
parent
8d57c52637
commit
bea7ae178d
5 changed files with 154 additions and 72 deletions
17
README.md
Normal file
17
README.md
Normal file
|
|
@ -0,0 +1,17 @@
|
||||||
|
# nextcloud
|
||||||
|
|
||||||
|
## Manage group folders
|
||||||
|
|
||||||
|
Group folders are configured as follows:
|
||||||
|
|
||||||
|
```yaml
|
||||||
|
nextcloud:
|
||||||
|
groupfolders:
|
||||||
|
- name: folder_1
|
||||||
|
groups:
|
||||||
|
- group_name
|
||||||
|
- group2_name
|
||||||
|
quota: '1073741274' # Quota in Bytes
|
||||||
|
```
|
||||||
|
|
||||||
|
All configured groups have full edit rights in the group folder.
|
||||||
|
|
@ -17,3 +17,4 @@ nextcloud:
|
||||||
user: nextcloud
|
user: nextcloud
|
||||||
pw: None
|
pw: None
|
||||||
name: nextcloud
|
name: nextcloud
|
||||||
|
groupfolders: []
|
||||||
|
|
|
||||||
71
tasks/base.yml
Normal file
71
tasks/base.yml
Normal file
|
|
@ -0,0 +1,71 @@
|
||||||
|
- name: install nextcloud
|
||||||
|
unarchive:
|
||||||
|
src: "https://download.nextcloud.com/server/releases/latest.tar.bz2"
|
||||||
|
remote_src: yes
|
||||||
|
dest: /var/www/
|
||||||
|
owner: www-data
|
||||||
|
group: www-data
|
||||||
|
creates: /var/www/nextcloud
|
||||||
|
|
||||||
|
- name: create nextcloud datadir
|
||||||
|
file:
|
||||||
|
path: "{{ nextcloud.datadir }}"
|
||||||
|
owner: www-data
|
||||||
|
group: www-data
|
||||||
|
mode: 0770
|
||||||
|
state: directory
|
||||||
|
|
||||||
|
- name: setup nextcloud
|
||||||
|
become_user: www-data
|
||||||
|
become: true
|
||||||
|
command: "/usr/bin/php occ maintenance:install -n --database 'mysql' --database-name '{{ nextcloud.db.name }}' --database-user '{{ nextcloud.db.user }}' --database-pass '{{ nextcloud.db.pw }}' --admin-user '{{ nextcloud.admin.name }}' --admin-pass '{{ nextcloud.admin.pw }}' --data-dir '{{ nextcloud.datadir }}'"
|
||||||
|
args:
|
||||||
|
chdir: /var/www/nextcloud
|
||||||
|
creates: /var/www/nextcloud/config/config.php
|
||||||
|
|
||||||
|
- name: set nextcloud trusted domains
|
||||||
|
become_user: www-data
|
||||||
|
become: true
|
||||||
|
command: '/usr/bin/php occ config:system:set trusted_domains 1 --value "{{ nextcloud.externalurl }}"'
|
||||||
|
args:
|
||||||
|
chdir: /var/www/nextcloud
|
||||||
|
|
||||||
|
- name: set other nextcloud config values
|
||||||
|
become_user: www-data
|
||||||
|
become: true
|
||||||
|
command: '/usr/bin/php occ config:system:set "{{ item.key }}" --value "{{ item.value }}"'
|
||||||
|
args:
|
||||||
|
chdir: /var/www/nextcloud
|
||||||
|
with_items:
|
||||||
|
- { key: "mail_from_address", value: "{{ nextcloud.mail.from }}" }
|
||||||
|
- { key: "mail_domain", value: "{{ nextcloud.mail.domain }}" }
|
||||||
|
- { key: "mail_smtpmode", value: "{{ nextcloud.mail.mode }}" }
|
||||||
|
- { key: "mail_smtpauthtype", value: "PLAIN" }
|
||||||
|
- { key: "mail_smtphost", value: "{{ nextcloud.mail.server|d('') }}" }
|
||||||
|
- { key: "mail_smtpport", value: "25" }
|
||||||
|
- { key: "mail_smtppassword", value: "{{ nextcloud.mail.password|d('') }}" }
|
||||||
|
- { key: "mail_smtpname", value: "{{ nextcloud.mail.user|d('') }}" }
|
||||||
|
- { key: "memcache.local", value: '{{ "\OC\Memcache\APCu" }}' }
|
||||||
|
- { key: "datadirectory", value: "{{ nextcloud.datadir }}" }
|
||||||
|
|
||||||
|
- name: copy nextcloud nginx config
|
||||||
|
template:
|
||||||
|
src: nginx.j2
|
||||||
|
dest: /etc/nginx/sites-available/nextcloud
|
||||||
|
notify:
|
||||||
|
- restart nginx
|
||||||
|
|
||||||
|
- name: enable nextcloud for nginx
|
||||||
|
file:
|
||||||
|
src: /etc/nginx/sites-available/nextcloud
|
||||||
|
dest: /etc/nginx/sites-enabled/nextcloud
|
||||||
|
state: link
|
||||||
|
notify:
|
||||||
|
- restart nginx
|
||||||
|
|
||||||
|
- name: add cronjob for nextcloud
|
||||||
|
cron:
|
||||||
|
job: /usr/bin/php -f /var/www/nextcloud/cron.php
|
||||||
|
user: www-data
|
||||||
|
minute: "*/10"
|
||||||
|
name: nextcloud-cron
|
||||||
61
tasks/groupfolders.yml
Normal file
61
tasks/groupfolders.yml
Normal file
|
|
@ -0,0 +1,61 @@
|
||||||
|
- name: manage group folders
|
||||||
|
become_user: www-data
|
||||||
|
become: true
|
||||||
|
|
||||||
|
block:
|
||||||
|
# Get list of existing group folders and set them as fact
|
||||||
|
- name: get list of group folders
|
||||||
|
check_mode: no
|
||||||
|
command: '/usr/bin/php occ groupfolders:list --output json'
|
||||||
|
args:
|
||||||
|
chdir: /var/www/nextcloud
|
||||||
|
register: existing_group_folders
|
||||||
|
|
||||||
|
- set_fact:
|
||||||
|
group_folders: "{{ existing_group_folders.stdout | from_json }}"
|
||||||
|
|
||||||
|
# Create group folders that did not exist yet
|
||||||
|
- name: create non-existing folders
|
||||||
|
command: "/usr/bin/php occ groupfolders:create {{ item.name }}"
|
||||||
|
args:
|
||||||
|
chdir: /var/www/nextcloud
|
||||||
|
with_items: "{{ nextcloud.groupfolders }}"
|
||||||
|
when: group_folders | selectattr(search_key, 'equalto', search_val) | list | count == 0
|
||||||
|
vars:
|
||||||
|
search_key: "mount_point"
|
||||||
|
search_val: "{{ item.name }}"
|
||||||
|
|
||||||
|
# Get list of existing group folders AGAIN and set them as fact
|
||||||
|
- name: get list of group folders again
|
||||||
|
check_mode: no
|
||||||
|
command: '/usr/bin/php occ groupfolders:list --output json'
|
||||||
|
args:
|
||||||
|
chdir: /var/www/nextcloud
|
||||||
|
register: existing_group_folders
|
||||||
|
|
||||||
|
- set_fact:
|
||||||
|
group_folders: "{{ existing_group_folders.stdout | from_json }}"
|
||||||
|
|
||||||
|
# Set quota for folders where it does not match
|
||||||
|
- name: set group folder quota
|
||||||
|
command: "/usr/bin/php occ groupfolders:quota {{ (group_folders | selectattr(search_key, 'equalto', search_val) | list | first).id }} {{ item.quota }}"
|
||||||
|
args:
|
||||||
|
chdir: /var/www/nextcloud
|
||||||
|
with_items: "{{ nextcloud.groupfolders }}"
|
||||||
|
when: (group_folders | selectattr(search_key, 'equalto', search_val) | list | first).quota != item.quota
|
||||||
|
vars:
|
||||||
|
search_key: "mount_point"
|
||||||
|
search_val: "{{ item.name }}"
|
||||||
|
|
||||||
|
# Set folder permissions if they are not correct yet
|
||||||
|
- name: Set folder permissions
|
||||||
|
command: "/usr/bin/php occ groupfolders:group {{ (group_folders | selectattr(search_key, 'equalto', search_val) | list | first).id }} {{ item.1 }} write share delete"
|
||||||
|
args:
|
||||||
|
chdir: /var/www/nextcloud
|
||||||
|
# Only execute when the permissions of the group for that folder are not "31" (31 is write, share, delete)
|
||||||
|
when: ((group_folders | selectattr(search_key, 'equalto', search_val) | list | first).groups[item.1] is undefined) or
|
||||||
|
((group_folders | selectattr(search_key, 'equalto', search_val) | list | first).groups[item.1] != 31)
|
||||||
|
loop: "{{ nextcloud.groupfolders | subelements('groups') }}"
|
||||||
|
vars:
|
||||||
|
search_key: "mount_point"
|
||||||
|
search_val: "{{ item.0.name }}"
|
||||||
|
|
@ -1,73 +1,5 @@
|
||||||
- name: install nextcloud
|
- import_tasks: base.yml
|
||||||
unarchive:
|
|
||||||
src: "https://download.nextcloud.com/server/releases/latest.tar.bz2"
|
|
||||||
remote_src: yes
|
|
||||||
dest: /var/www/
|
|
||||||
owner: www-data
|
|
||||||
group: www-data
|
|
||||||
creates: /var/www/nextcloud
|
|
||||||
|
|
||||||
- name: create nextcloud datadir
|
|
||||||
file:
|
|
||||||
path: "{{ nextcloud.datadir }}"
|
|
||||||
owner: www-data
|
|
||||||
group: www-data
|
|
||||||
mode: 0770
|
|
||||||
state: directory
|
|
||||||
|
|
||||||
- name: setup nextcloud
|
|
||||||
become_user: www-data
|
|
||||||
become: true
|
|
||||||
command: "/usr/bin/php occ maintenance:install -n --database 'mysql' --database-name '{{ nextcloud.db.name }}' --database-user '{{ nextcloud.db.user }}' --database-pass '{{ nextcloud.db.pw }}' --admin-user '{{ nextcloud.admin.name }}' --admin-pass '{{ nextcloud.admin.pw }}' --data-dir '{{ nextcloud.datadir }}'"
|
|
||||||
args:
|
|
||||||
chdir: /var/www/nextcloud
|
|
||||||
creates: /var/www/nextcloud/config/config.php
|
|
||||||
|
|
||||||
- name: set nextcloud trusted domains
|
|
||||||
become_user: www-data
|
|
||||||
become: true
|
|
||||||
command: '/usr/bin/php occ config:system:set trusted_domains 1 --value "{{ nextcloud.externalurl }}"'
|
|
||||||
args:
|
|
||||||
chdir: /var/www/nextcloud
|
|
||||||
|
|
||||||
- name: set other nextcloud config values
|
|
||||||
become_user: www-data
|
|
||||||
become: true
|
|
||||||
command: '/usr/bin/php occ config:system:set "{{ item.key }}" --value "{{ item.value }}"'
|
|
||||||
args:
|
|
||||||
chdir: /var/www/nextcloud
|
|
||||||
with_items:
|
|
||||||
- { key: "mail_from_address", value: "{{ nextcloud.mail.from }}" }
|
|
||||||
- { key: "mail_domain", value: "{{ nextcloud.mail.domain }}" }
|
|
||||||
- { key: "mail_smtpmode", value: "{{ nextcloud.mail.mode }}" }
|
|
||||||
- { key: "mail_smtpauthtype", value: "PLAIN" }
|
|
||||||
- { key: "mail_smtphost", value: "{{ nextcloud.mail.server|d('') }}" }
|
|
||||||
- { key: "mail_smtpport", value: "25" }
|
|
||||||
- { key: "mail_smtppassword", value: "{{ nextcloud.mail.password|d('') }}" }
|
|
||||||
- { key: "mail_smtpname", value: "{{ nextcloud.mail.user|d('') }}" }
|
|
||||||
- { key: "memcache.local", value: '{{ "\OC\Memcache\APCu" }}' }
|
|
||||||
- { key: "datadirectory", value: "{{ nextcloud.datadir }}" }
|
|
||||||
|
|
||||||
- name: copy nextcloud nginx config
|
|
||||||
template:
|
|
||||||
src: nginx.j2
|
|
||||||
dest: /etc/nginx/sites-available/nextcloud
|
|
||||||
notify:
|
|
||||||
- restart nginx
|
|
||||||
|
|
||||||
- name: enable nextcloud for nginx
|
|
||||||
file:
|
|
||||||
src: /etc/nginx/sites-available/nextcloud
|
|
||||||
dest: /etc/nginx/sites-enabled/nextcloud
|
|
||||||
state: link
|
|
||||||
notify:
|
|
||||||
- restart nginx
|
|
||||||
|
|
||||||
- name: add cronjob for nextcloud
|
|
||||||
cron:
|
|
||||||
job: /usr/bin/php -f /var/www/nextcloud/cron.php
|
|
||||||
user: www-data
|
|
||||||
minute: "*/10"
|
|
||||||
name: nextcloud-cron
|
|
||||||
|
|
||||||
|
|
||||||
|
- include_tasks: groupfolders.yml
|
||||||
|
when:
|
||||||
|
- nextcloud.groupfolders
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue