commit a291a888fda22eadebc243682e3411b43ad3b1ed Author: Kris Lamoureux Date: Thu Jul 11 01:41:05 2019 -0400 Basic Nextcloud Installation on Debian 10 A basic installation of Nextcloud 16 Stable on Debian Stable. diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..c9252d8 --- /dev/null +++ b/.gitignore @@ -0,0 +1,10 @@ +# Vagrant files +.vagrant + +# Unneeded ansible file +*.retry + +# Production files +group_vars/production.yml +group_vars/.gitignore + diff --git a/Vagrantfile b/Vagrantfile new file mode 100644 index 0000000..677e0ce --- /dev/null +++ b/Vagrantfile @@ -0,0 +1,38 @@ +# Freedom Cloud. Management code for a self-hosted file server. +# Copyright (C) 2019 Kris Lamoureux +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, version 3 of the License. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . +# +# vi: set ft=ruby : + +Vagrant.configure("2") do |config| + + # Debian Stable + # Temporary box until debian/buster64 updates + # https://lists.debian.org/debian-cloud/2019/07/msg00023.html + config.vm.box = "krislamo/debian" + + # Disable default sync + config.vm.synced_folder '.', '/vagrant', disabled: true + + # Get local IP and display + config.vm.network :forwarded_port, guest: 80, host: 8080 + + # Run Ansible + config.vm.provision "ansible" do |ansible| + ansible.compatibility_mode = "2.0" + ansible.playbook = "testing.yml" + end + +end + diff --git a/group_vars/all.yml b/group_vars/all.yml new file mode 100644 index 0000000..9aa0407 --- /dev/null +++ b/group_vars/all.yml @@ -0,0 +1,13 @@ +## Nextcloud Configuration ## +nc_version: 16.0.3 +nc_sha256sum: a13f68ce47a1362318629ba5b118a59fa98358bb18f4afc371ea15104f2881f3 + +nc_domain: www.example.com +nc_docroot: /var/www/nextcloud + +nc_db: nextcloud +nc_db_user: nextcloud +nc_db_pass: nc+password + +nc_admin: admin +nc_admin_pass: ncadmin+password diff --git a/production.yml b/production.yml new file mode 100644 index 0000000..2d68fcc --- /dev/null +++ b/production.yml @@ -0,0 +1,29 @@ +# Freedom Cloud. Management code for a self-hosted file server. +# Copyright (C) 2019 Kris Lamoureux +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, version 3 of the License. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . + + +- name: Install Backup Server + hosts: production + become: true + + pre_tasks: + - name: Install Ansible requirements + shell: apt-get update && apt-get install -y python-apt aptitude + args: + creates: /usr/lib/python2.7/dist-packages/apt/__init__.py + warn: false + + roles: + - nextcloud diff --git a/roles/nextcloud/handlers/main.yml b/roles/nextcloud/handlers/main.yml new file mode 100644 index 0000000..0a271ea --- /dev/null +++ b/roles/nextcloud/handlers/main.yml @@ -0,0 +1,19 @@ +# Freedom Cloud. Management code for a self-hosted file server. +# Copyright (C) 2019 Kris Lamoureux +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, version 3 of the License. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . + +- name: Reload Apache + service: + name: apache2 + state: reloaded diff --git a/roles/nextcloud/tasks/main.yml b/roles/nextcloud/tasks/main.yml new file mode 100644 index 0000000..9f25777 --- /dev/null +++ b/roles/nextcloud/tasks/main.yml @@ -0,0 +1,119 @@ +# Freedom Cloud. Management code for a self-hosted file server. +# Copyright (C) 2019 Kris Lamoureux +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, version 3 of the License. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . + + +- name: Install Apache + apt: + name: apache2 + state: present + +- name: Create Public HTML Directory + file: + path: "{{ nc_docroot }}" + state: directory + +- name: Install MySQL/MariaDB + apt: + name: mariadb-server + state: present + +- name: Ansible MySQL/MariaDB Dependency + apt: + name: python-mysqldb + state: present + +- name: Create Database + mysql_db: + name: "{{ nc_db }}" + state: present + +- name: Create Database User + mysql_user: + name: "{{ nc_db_user }}" + password: "{{ nc_db_pass }}" + priv: 'nextcloud.*:ALL' + state: present + +- name: Install PHP + apt: + name: php7.3 + state: present + +- name: Install PHP modules + apt: + name: ['php7.3-mysql', 'php7.3-xml', 'php7.3-mbstring', + 'php7.3-gd', 'php7.3-curl', 'php7.3-zip', + 'php7.3-intl', 'php7.3-imagick'] + state: present + notify: + - Reload Apache + +- name: Download Nextcloud + get_url: + url: "https://download.nextcloud.com/server/releases/\ + nextcloud-{{ nc_version }}.tar.bz2" + dest: /tmp/nextcloud-{{ nc_version }}.tar.bz2 + checksum: sha256:{{ nc_sha256sum }} + timeout: 600 + +- name: Extract Nextcloud + unarchive: + src: /tmp/nextcloud-{{ nc_version }}.tar.bz2 + dest: /var/www + owner: www-data + group: www-data + remote_src: true + +- name: Install Nextcloud + command: 'sudo -u www-data php occ maintenance:install + --database "mysql" + --database-name "{{ nc_db }}" + --database-user "{{ nc_db_user }}" + --database-pass "{{ nc_db_pass }}" + --admin-user "{{ nc_admin }}" + --admin-pass "{{ nc_admin_pass }}"' + register: nc_install + args: + warn: false + chdir: "{{ nc_docroot }}" + creates: "{{ nc_docroot }}/config/config.php" + +- name: Set Nextcloud's Trusted Domain + command: 'sudo -u www-data php occ config:system:set trusted_domains 0 + --value="{{ nc_domain }}"' + when: nc_install.changed + args: + warn: false + chdir: "{{ nc_docroot }}" + +- name: Create Apache Virtual Host + template: + src: apacheconf.conf + dest: /etc/apache2/sites-available/{{ nc_domain }}.conf + owner: root + group: root + mode: '0644' + notify: + - Reload Apache + +- name: Enable Site + file: + src: /etc/apache2/sites-available/{{ nc_domain }}.conf + dest: /etc/apache2/sites-enabled/{{ nc_domain }}.conf + state: link + owner: root + group: root + notify: + - Reload Apache diff --git a/roles/nextcloud/templates/apacheconf.conf b/roles/nextcloud/templates/apacheconf.conf new file mode 100644 index 0000000..39db7e8 --- /dev/null +++ b/roles/nextcloud/templates/apacheconf.conf @@ -0,0 +1,36 @@ +# Freedom Cloud. Management code for a self-hosted file server. +# Copyright (C) 2019 Kris Lamoureux +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, version 3 of the License. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . + + + + ServerName {{ nc_domain }} + + ServerAdmin {{ nc_admin }} + DocumentRoot {{ nc_docroot }} + + ErrorLog ${APACHE_LOG_DIR}/error.log + CustomLog ${APACHE_LOG_DIR}/access.log combined + + + + + Options Indexes FollowSymLinks + AllowOverride All + Require all granted + + php_value memory_limit 512M + + +# vim: syntax=apache diff --git a/testing.yml b/testing.yml new file mode 100644 index 0000000..a7077e7 --- /dev/null +++ b/testing.yml @@ -0,0 +1,29 @@ +# Copyright (C) 2019 Kris Lamoureux +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, version 3 of the License. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . + + +- name: Install Backup Server + hosts: all + become: true + + pre_tasks: + - name: Install Ansible requirements + shell: apt-get update && apt-get install -y python-apt aptitude + args: + creates: /usr/lib/python2.7/dist-packages/apt/__init__.py + warn: false + + roles: + - nextcloud +