From fee84b97f496950ecaf120ed1a094f6d0c98e445 Mon Sep 17 00:00:00 2001
From: Corbin Bartsch <me@cbarts.net>
Date: Tue, 12 Apr 2022 12:31:28 -0400
Subject: [PATCH] Added installing Nextcloud files

---
 defaults/main.yaml           |  3 +++
 tasks/install_nextcloud.yaml | 15 +++++++++++++++
 tasks/main.yaml              |  8 ++------
 3 files changed, 20 insertions(+), 6 deletions(-)
 create mode 100644 tasks/install_nextcloud.yaml

diff --git a/defaults/main.yaml b/defaults/main.yaml
index ef876c6..7fcec07 100644
--- a/defaults/main.yaml
+++ b/defaults/main.yaml
@@ -3,6 +3,9 @@
 # Your domain name for web server configuration
 domain_name: 'localdomain'
 
+# The major version of Nextcloud to install
+nextcloud_version: 23
+
 # The subdomain at which you'd like Nextcloud to be accessible at
 nextcloud_subdomain: nextcloud
 
diff --git a/tasks/install_nextcloud.yaml b/tasks/install_nextcloud.yaml
new file mode 100644
index 0000000..459016c
--- /dev/null
+++ b/tasks/install_nextcloud.yaml
@@ -0,0 +1,15 @@
+---
+- name: Download latest Nextcloud {{ nextcloud_version }} tar.bz2 archive
+  ansible.builtin.unarchive:
+    src: "https://download.nextcloud.com/server/releases/latest-{{ nextcloud_version }}.tar.bz2"
+    dest: "{{ nextcloud_www_path }}"
+  extra_opts:
+    - --transform
+    - s/^nextcloud\///
+
+- name: Change ownership of Nextcloud directories
+  ansible.builtin.file:
+    path: "{{ nextcloud_www_path }}"
+    owner: www-data
+    group: www-data
+    recurse: true
diff --git a/tasks/main.yaml b/tasks/main.yaml
index 3a90815..1567aa3 100644
--- a/tasks/main.yaml
+++ b/tasks/main.yaml
@@ -14,9 +14,5 @@
   include_tasks: nginx_template.yaml
   when: nextcloud_nginx
 
-- name: Change ownership of Nextcloud directories
-  ansible.builtin.file:
-    path: "{{ nextcloud_www_path }}"
-    owner: www-data
-    group: www-data
-    recurse: true
+- name: Install Nextcloud files
+  include_tasks: install_nextcloud.yaml