diff --git a/.gitignore b/.gitignore
index d67951a..9ea6295 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,3 +1,6 @@
# Vagrant files
.vagrant
+# Unneeded ansible file
+*.retry
+
diff --git a/Vagrantfile b/Vagrantfile
index 3279f19..9221854 100644
--- a/Vagrantfile
+++ b/Vagrantfile
@@ -21,6 +21,9 @@ Vagrant.configure("2") do |config|
config.vm.box = "debian/stretch64"
config.vm.synced_folder ".", "/vagrant", disabled: true
+ # Set static IP
+ config.vm.network "private_network", ip: "192.168.121.2"
+
# Machine Name
config.vm.define :frita do |frita| #
end
@@ -36,14 +39,5 @@ Vagrant.configure("2") do |config|
ansible.playbook = "site.yml"
end
- # Display IP below
- config.vm.provision "shell" do |s|
- s.inline = "
- ip a | grep 192.168 |
- awk '{
- print substr($2, 1, index($2,\"/\") - 1);
- }'
- "
- end
-
end
+
diff --git a/ansible.cfg b/ansible.cfg
new file mode 100644
index 0000000..1b26d78
--- /dev/null
+++ b/ansible.cfg
@@ -0,0 +1,3 @@
+[ssh_connection]
+pipelining=True
+
diff --git a/group_vars/all b/group_vars/all
index ddd4779..1d0b91e 100644
--- a/group_vars/all
+++ b/group_vars/all
@@ -9,13 +9,38 @@ wp_version: 5.0.2
wp_sha1_hash: 4a6971d35eb92e2fc30034141b1c865e8c156add
# WordPress Home Directory
-# Note: value is a directory is without trailing '/'
+# Note: value is a directory without trailing '/'
wp_dir: /var/www/wordpress
-# Database Settings
+# WordPress Database Settings
wp_db_host: localhost
wp_db_name: wordpress
wp_db_user: wordpress_user
wp_db_pass: Password1
wp_db_table_prefix: wp_
+
+### Nextcloud Configuration ###
+
+# Domain
+nc_domain: cloud.freeitathens.org
+nc_admin_email: contact@freeitathens.org
+
+# Version of Nextcloud to deploy
+nc_version: 15.0.2
+nc_sha256_hash: c1f4cc33e39994ddbe6777370b62c30b7ae52136a0530c0b9922770803ca0fea
+
+# Nextcloud Home Directory
+# Note: value is a directory without trailing '/'
+nc_dir: /var/www/nextcloud
+
+# Nextcloud Database Settings
+nc_db_host: localhost
+nc_db_name: nextcloud
+nc_db_user: nextcloud_user
+nc_db_pass: Password1
+
+# Nextcloud Admin
+nc_admin: admin
+nc_admin_pass: Password1
+
diff --git a/roles/nextcloud/tasks/main.yml b/roles/nextcloud/tasks/main.yml
new file mode 100644
index 0000000..9df4620
--- /dev/null
+++ b/roles/nextcloud/tasks/main.yml
@@ -0,0 +1,134 @@
+# Copyright (C) 2019 Free I.T. Athens
+#
+# 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 .
+
+# psycopg2 is required for database tasks
+- name: Install PostgreSQL Support for Python
+ apt: name=python-psycopg2 state=present
+
+- name: Install PostgreSQL
+ apt: name=postgresql state=present
+
+- name: Create Database
+ postgresql_db:
+ name: "{{ nc_db_name }}"
+ state: present
+ become_user: postgres
+
+- name: Create Database User
+ postgresql_user:
+ user: "{{ nc_db_user }}"
+ password: "{{ nc_db_pass }}"
+ db: "{{ nc_db_name }}"
+ state: present
+ become_user: postgres
+
+- name: Add Database User Permissions
+ postgresql_privs:
+ db: "{{ nc_db_name }}"
+ role: "{{ nc_db_user }}"
+ objs: ALL_IN_SCHEMA
+ privs: SELECT,INSERT,UPDATE,DELETE
+ become_user: postgres
+
+- name: Install PHP Modules
+ apt:
+ name: [
+ # Required
+ 'php-ctype', 'php-curl', 'php-dom',
+ 'php-gd', 'php-iconv', 'php-json', 'php-xml',
+ 'php-mbstring', 'php-posix', 'php-simplexml',
+ 'php-xmlreader', 'php-xmlwriter', 'php-zip',
+
+ # Database Connectors
+ 'php-pgsql',
+
+ # Recommended Packages
+ 'php-fileinfo', 'php-bz2', 'php-intl',
+
+ # Enhanced Performance
+ 'php-redis', 'redis-server',
+
+ # Preview Generation
+ 'php-imagick'
+ ]
+ state: present
+ notify: Reload Apache2
+
+- name: Create Public HTML Directory
+ file:
+ path: "{{ nc_dir }}/public_html"
+ state: directory
+
+- name: Create Nextcloud Directories
+ file:
+ path: "{{ nc_dir }}/public_html/data"
+ state: directory
+ owner: www-data
+ group: www-data
+
+- name: Create Logs Directory
+ file:
+ path: "{{ nc_dir }}/logs"
+ state: directory
+
+- 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_sha256_hash }}
+
+- name: Extract Nextcloud
+ unarchive:
+ src: /tmp/nextcloud-{{ nc_version }}.tar.bz2
+ dest: "{{ nc_dir }}/public_html"
+ owner: www-data
+ group: www-data
+ extra_opts: [--strip-components=1]
+ remote_src: yes
+
+- name: Install Nextcloud
+ command: |
+ php occ maintenance:install --database pgsql \
+ --database-name {{ nc_db_name }} --database-host {{ nc_db_host }} \
+ --database-user {{ nc_db_user }} --database-pass {{ nc_db_pass }} \
+ --admin-user {{ nc_admin }} --admin-pass {{ nc_admin_pass }} \
+ --data-dir {{ nc_dir }}/public_html/data
+ become_user: www-data
+ args:
+ chdir: "{{ nc_dir }}/public_html"
+ creates: "{{ nc_dir }}/public_html/config/config.php"
+
+- name: Add Domain Name to Trusted Domains
+ command: |
+ php occ config:system:set trusted_domains 0 --value={{ nc_domain }}
+ become_user: www-data
+ args:
+ chdir: "{{ nc_dir }}/public_html"
+
+- name: "Enable Apache2 Module: rewrite"
+ apache2_module: name=rewrite state=present
+
+- name: Apply Apache Configuration
+ template:
+ src: nextcloud.conf.j2
+ dest: /etc/apache2/sites-available/{{ nc_domain }}.conf
+ notify: Reload Apache2
+
+- name: Enable Apache Website
+ shell: a2ensite {{ nc_domain }}
+ args:
+ creates: /etc/apache2/sites-enabled/{{ nc_domain }}.conf
+ notify: Reload Apache2
+
diff --git a/roles/nextcloud/templates/nextcloud.conf.j2 b/roles/nextcloud/templates/nextcloud.conf.j2
new file mode 100644
index 0000000..d0de0ad
--- /dev/null
+++ b/roles/nextcloud/templates/nextcloud.conf.j2
@@ -0,0 +1,26 @@
+
+ ServerName {{ nc_domain }}
+
+ ServerAdmin {{ nc_admin_email }}
+ DocumentRoot {{ nc_dir }}/public_html
+
+
+
+ Options +FollowSymLinks
+ AllowOverride All
+
+
+ Dav off
+
+
+ SetEnv HOME {{ nc_dir }}/public_html
+ SetEnv HTTP_HOME {{ nc_dir }}/public_html
+
+
+
+ ErrorLog {{ nc_dir }}/logs/error.log
+ CustomLog {{ nc_dir }}/logs/access.log combined
+
+
+# vim: syntax=apache ts=4 sw=4 sts=4 sr noet
+
diff --git a/site.yml b/site.yml
index b83bb8d..974b0e2 100644
--- a/site.yml
+++ b/site.yml
@@ -19,4 +19,5 @@
roles:
- webserver
- wordpress
+ - nextcloud