ansible-roles/nextcloud/tasks/main.yml

166 lines
4.5 KiB
YAML

---
- name: Install dependencies
apt:
name: "{{ item }}"
state: present
with_items:
- bzip2
- php-ctype
- php-gd
- php-json
- php-xml
- php-mbstring
- php-zip
- php-pdo-mysql
- php-curl
- php-bz2
- php-intl
- php-mcrypt
- php-ldap
- php-imap
- php-gmp
- php-apcu
- php-redis
- python-mysqldb
tags:
- nextcloud
- name: Create Nextcloud groups
group:
name: "{{ item }}"
state: present
with_items: "{{ nextcloud_instances | list }}"
tags:
- nextcloud
- name: Create Nextcloud users
user:
name: "{{ item }}"
group: "{{ item }}"
home: "{{ nextcloud_root }}/{{ item }}"
shell: '/bin/bash'
createhome: True
state: present
with_items: "{{ nextcloud_instances | list }}"
tags:
- nextcloud
- name: Create needed directories
file:
dest: "{{ nextcloud_root }}/{{ item[0] }}/{{ item[1] }}"
state: directory
mode: "0770"
owner: "{{ item[0] }}"
group: "{{ item[0] }}"
with_nested:
- "{{ nextcloud_instances | list }}"
- [ 'logs', 'config', 'data', 'tmp' ]
tags:
- nextcloud
- name: Retrieve Nextcloud archive
get_url:
url: "https://download.nextcloud.com/server/releases/nextcloud-{{ item.value.version | default(nextcloud_version) }}.tar.bz2"
dest: "/home/nextcloud-{{ item.value.version | default(nextcloud_version) }}.tar.bz2"
with_dict: "{{ nextcloud_instances }}"
tags:
- nextcloud
- name: Retrieve Nextcloud sha256 checksum
get_url:
url: "https://download.nextcloud.com/server/releases/nextcloud-{{ item.value.version | default(nextcloud_version) }}.tar.bz2.sha256"
dest: "/home/nextcloud-{{ item.value.version | default(nextcloud_version) }}.tar.bz2.sha256"
with_dict: "{{ nextcloud_instances }}"
tags:
- nextcloud
- name: Verify Nextcloud sha256 checksum
command: "sha256sum -c nextcloud-{{ item.value.version | default(nextcloud_version) }}.tar.bz2.sha256"
changed_when: False
args:
chdir: "/home/"
with_dict: "{{ nextcloud_instances }}"
tags:
- nextcloud
- name: Extract Nextcloud archive
unarchive:
src: '/home/nextcloud-{{ item.value.version | default(nextcloud_version) }}.tar.bz2'
dest: "{{ nextcloud_root }}/{{ item.key }}"
remote_src: True
mode: "0750"
owner: "{{ item.key }}"
group: "{{ item.key }}"
with_dict: "{{ nextcloud_instances }}"
tags:
- nextcloud
- include: mysql.yml
- name: Link config dir to global config dir
file:
src: "{{ nextcloud_root }}/{{ item }}/config/config.php"
dest: "{{ nextcloud_root }}/{{ item }}/nextcloud/config/config.php"
state: link
owner: "{{ item }}"
group: "{{ item }}"
force: True
with_items: "{{ nextcloud_instances | list }}"
tags:
- nextcloud
- name: Install Nextcloud
shell: "php ./occ maintenance:install --database mysql --database-name {{ item.key }} --database-user {{ item.key }} --database-pass {{ item.value.db_pass }} --admin-user admin --admin-pass toor --data-dir {{ nextcloud_root }}/{{ item.key }}/data"
args:
chdir: "{{ nextcloud_root }}/{{ item.key }}/nextcloud/"
creates: "{{ nextcloud_root }}/{{ item.key }}/config/config.php"
with_dict: "{{ nextcloud_instances }}"
tags:
- nextcloud
- name: Configure Nextcloud cron
cron:
name: 'Nextcloud'
minute: "*/15"
job: "php -f ~/nextcloud/cron.php"
user: "{{ item }}"
with_items: "{{ nextcloud_instances | list }}"
tags:
- nextcloud
- name: Erase previously trusted domains config
shell: "php ./occ config:system:set trusted_domains"
args:
chdir: "{{ nextcloud_root }}/{{ item }}/nextcloud/"
with_items: "{{ nextcloud_instances | list }}"
tags:
- nextcloud
- name: Configure trusted domains
shell: "php ./occ config:system:set trusted_domains {{ item[1] }} --value {{ nextcloud_instances[item[0]].domains[item[1]] }}"
args:
chdir: "{{ nextcloud_root }}/{{ item[0] }}/nextcloud/"
with_nested:
- "{{ nextcloud_instances | list }}"
- "{{ range(0, nextcloud_instances | list | length ) | list }}"
tags:
- nextcloud
#- name: Configure memcache local to APCu
# shell: "php ./occ config:system:set memcache.local --value '\\OC\\Memcache\\APCu'"
# args:
# chdir: "{{ nextcloud_root }}/{{ item }}/nextcloud/"
# with_items: "{{ nextcloud_instances | list }}"
# tags:
# - nextcloud
- name: Fix right on config.php
file:
dest: "{{ nextcloud_root }}/{{ item }}/config/config.php"
owner: "{{ item }}"
group: "{{ item }}"
mode: "0660"
with_items: "{{ nextcloud_instances | list }}"
tags:
- nextcloud