2020-02-05 20:23:20 -06:00
|
|
|
#!/usr/bin/ansible-playbook
|
|
|
|
# vim:ft=ansible:
|
|
|
|
---
|
|
|
|
- name: Install, configure, and start Nextcloud
|
|
|
|
block:
|
|
|
|
- name: Install Nextcloud-required packages
|
|
|
|
apt:
|
2020-04-18 03:15:41 -05:00
|
|
|
name:
|
|
|
|
- php-imagick
|
2020-02-05 23:56:41 -06:00
|
|
|
- name: Set up MySQL
|
|
|
|
block:
|
|
|
|
- name: Create database
|
|
|
|
mysql_db:
|
2020-02-06 01:42:12 -06:00
|
|
|
name: nextcloud
|
2020-02-05 23:56:41 -06:00
|
|
|
login_user: root
|
|
|
|
login_password: "{{ mysql_root_password }}"
|
|
|
|
state: present
|
|
|
|
- name: Create Nextcloud user
|
|
|
|
mysql_user:
|
|
|
|
name: nextcloud
|
|
|
|
host: localhost
|
|
|
|
password: "{{ nextcloud_mysql_password }}"
|
2020-02-06 03:17:15 -06:00
|
|
|
priv: "nextcloud.*:ALL,GRANT"
|
2020-02-05 23:56:41 -06:00
|
|
|
login_user: root
|
|
|
|
login_password: "{{ mysql_root_password }}"
|
2020-02-05 21:54:30 -06:00
|
|
|
- name: Set up Apache
|
|
|
|
block:
|
|
|
|
- name: Create webroot
|
|
|
|
file:
|
2020-02-05 22:09:35 -06:00
|
|
|
path: "{{ nextcloud_webroot }}"
|
2020-05-06 00:31:49 -05:00
|
|
|
mode: "0750"
|
2020-02-05 21:54:30 -06:00
|
|
|
state: directory
|
|
|
|
- name: Check for existing installation
|
|
|
|
stat:
|
2020-02-05 22:09:35 -06:00
|
|
|
path: "{{ nextcloud_webroot }}/index.html"
|
2020-02-05 21:54:30 -06:00
|
|
|
register: stat_webroot_index
|
|
|
|
- name: Install Nextcloud
|
|
|
|
block:
|
|
|
|
- name: Download Nextcloud
|
|
|
|
get_url:
|
2020-02-05 21:56:33 -06:00
|
|
|
dest: /var/www/nextcloud.tar.bz2
|
|
|
|
url: "{{ nextcloud_tarbz2 }}"
|
2020-02-05 21:54:30 -06:00
|
|
|
- name: Extract Nextcloud
|
|
|
|
unarchive:
|
2020-02-05 21:58:04 -06:00
|
|
|
src: /var/www/nextcloud.tar.bz2
|
|
|
|
remote_src: yes
|
2020-02-05 22:09:35 -06:00
|
|
|
dest: "{{ nextcloud_webroot }}"
|
2020-02-05 21:54:30 -06:00
|
|
|
extra_opts: [--strip-components=1]
|
2020-02-26 18:53:20 -06:00
|
|
|
notify: restart apache
|
2020-02-06 00:20:43 -06:00
|
|
|
- name: Create data directory
|
|
|
|
file:
|
2020-02-06 00:53:47 -06:00
|
|
|
path: "/var/nextcloud"
|
2020-02-06 00:20:43 -06:00
|
|
|
state: directory
|
2020-02-06 00:53:47 -06:00
|
|
|
mode: 0700
|
|
|
|
owner: www-data
|
|
|
|
group: www-data
|
2020-02-05 22:48:21 -06:00
|
|
|
- name: Chown webroot
|
2020-02-06 00:20:43 -06:00
|
|
|
# Nextcloud docs say Apache needs write access, so it gets write access
|
2020-02-05 22:48:21 -06:00
|
|
|
file:
|
|
|
|
path: "{{ nextcloud_webroot }}"
|
|
|
|
state: directory
|
|
|
|
recurse: yes
|
2020-02-06 00:20:43 -06:00
|
|
|
owner: www-data
|
|
|
|
group: www-data
|
2020-02-05 21:54:30 -06:00
|
|
|
- name: Cleanup
|
|
|
|
file:
|
2020-02-05 22:12:56 -06:00
|
|
|
path: /var/www/nextcloud.tar.bz2
|
2020-02-05 21:54:30 -06:00
|
|
|
state: absent
|
|
|
|
when: not stat_webroot_index.stat.exists
|
2020-05-06 00:31:49 -05:00
|
|
|
- name: Assert permissions
|
|
|
|
block:
|
|
|
|
- name: Tighten config.php
|
|
|
|
file:
|
|
|
|
path: "{{ nextcloud_webroot }}/config/config.php"
|
2020-05-06 23:22:35 -05:00
|
|
|
mode: "0640"
|
2020-05-06 00:31:49 -05:00
|
|
|
- name: Loosen occ
|
|
|
|
file:
|
|
|
|
path: "{{ nextcloud_webroot }}/occ"
|
|
|
|
mode: "0755"
|
2020-02-06 03:44:37 -06:00
|
|
|
- name: Set up Nextcloud cronjob
|
|
|
|
cron:
|
|
|
|
user: www-data
|
|
|
|
name: "nextcloud-cron"
|
2020-02-06 03:47:10 -06:00
|
|
|
minute: "*/5"
|
2020-02-06 04:05:34 -06:00
|
|
|
job: 'php -f "{{ nextcloud_webroot }}/cron.php"'
|
2020-02-20 05:28:39 -06:00
|
|
|
- name: Copy over virtual host configs
|
|
|
|
template:
|
|
|
|
src: apache2-vhost-ssl.conf
|
2020-02-27 05:16:02 -06:00
|
|
|
dest: "/etc/apache2/sites-available/{{ nextcloud_url }}.conf"
|
|
|
|
notify: restart apache
|
|
|
|
- name: Enable config
|
|
|
|
command:
|
|
|
|
cmd: "a2ensite {{ nextcloud_url }}.conf"
|
|
|
|
creates: "/etc/apache2/sites-enabled/{{ nextcloud_url }}.conf"
|
2020-02-26 18:53:20 -06:00
|
|
|
notify: restart apache
|
2020-02-20 05:28:39 -06:00
|
|
|
- name: Generate certificate
|
|
|
|
include_role:
|
|
|
|
name: https
|
|
|
|
vars:
|
|
|
|
website_url: "{{ nextcloud_url }}"
|
|
|
|
website_webroot: "{{ nextcloud_webroot }}"
|
2020-05-06 01:59:17 -05:00
|
|
|
- name: Template out backup module
|
|
|
|
template:
|
|
|
|
src: "backup.sh"
|
|
|
|
dest: "/opt/backups/modules/{{ nextcloud_url }}.sh"
|
|
|
|
mode: "0600"
|
2020-02-05 21:13:04 -06:00
|
|
|
become: yes
|