From e66a4b96ffa8c1fb86b5aecde853a6afe9f5be10 Mon Sep 17 00:00:00 2001 From: Kris Lamoureux Date: Thu, 9 Jul 2020 21:53:07 -0400 Subject: [PATCH] Reorganize Nextcloud docker mounts and variables --- dev/host_vars/nextcloud.yml | 9 ++++--- roles/nextcloud/defaults/main.yml | 16 ++++++++---- roles/nextcloud/tasks/main.yml | 41 ++++++++++++++----------------- 3 files changed, 34 insertions(+), 32 deletions(-) diff --git a/dev/host_vars/nextcloud.yml b/dev/host_vars/nextcloud.yml index cf30247..c5b0a94 100644 --- a/dev/host_vars/nextcloud.yml +++ b/dev/host_vars/nextcloud.yml @@ -1,8 +1,9 @@ -# nextcloud -mariadb_version: latest -nextcloud_name: nextcloud -nextcloud_dbpass: password +# container settings nextcloud_version: stable nextcloud_admin: admin nextcloud_pass: password nextcloud_domain: cloud.vm.krislamo.org + +# database settings +nextcloud_dbversion: latest +nextcloud_dbpass: password diff --git a/roles/nextcloud/defaults/main.yml b/roles/nextcloud/defaults/main.yml index 139e7e0..c4ae79f 100644 --- a/roles/nextcloud/defaults/main.yml +++ b/roles/nextcloud/defaults/main.yml @@ -1,5 +1,11 @@ -# nextcloud -mariadb_name: mariadb -nextcloud_dbname: nextcloud -nextcloud_dbuser: nextcloud -nextcloud_root: "/opt/{{ nextcloud_name }}" +# container names +nextcloud_container: nextcloud +nextcloud_dbcontainer: "{{ nextcloud_container }}-db" + +# database settings +nextcloud_dbname: "{{ nextcloud_container }}" +nextcloud_dbuser: "{{ nextcloud_dbname }}" + +# host mounts +nextcloud_root: "/opt/{{ nextcloud_container }}/public_html" +nextcloud_dbroot: "/opt/{{ nextcloud_container }}/database" diff --git a/roles/nextcloud/tasks/main.yml b/roles/nextcloud/tasks/main.yml index c6b9f03..aa5b0b3 100644 --- a/roles/nextcloud/tasks/main.yml +++ b/roles/nextcloud/tasks/main.yml @@ -1,14 +1,15 @@ -- name: Create Docker container bind mount directory +- name: Create Docker container bind mount directories file: - path: "{{ nextcloud_root }}/public_html" + path: ["{{ nextcloud_root }}", + "{{ nextcloud_dbroot }}"] state: directory -- name: Start MariaDB container +- name: Start Nextcloud's database container docker_container: - name: "{{ mariadb_name }}" - image: mariadb:{{ mariadb_version }} + name: "{{ nextcloud_dbcontainer }}" + image: mariadb:{{ nextcloud_dbversion }} restart_policy: always - volumes: mariadb:/var/lib/mysql + volumes: "{{ nextcloud_dbroot }}:/var/lib/mysql" env: MYSQL_RANDOM_ROOT_PASSWORD: "true" MYSQL_DATABASE: "{{ nextcloud_dbname }}" @@ -17,22 +18,16 @@ - name: Start Nextcloud container docker_container: - name: "{{ nextcloud_name }}" + name: "{{ nextcloud_container }}" image: nextcloud:{{ nextcloud_version }} restart_policy: always - volumes: "{{ nextcloud_root }}/public_html:/var/www/html" + volumes: "{{ nextcloud_root }}:/var/www/html" ports: 80:80 - links: "{{ mariadb_name }}:mysql" - env: - MYSQL_HOST: mysql - MYSQL_DATABASE: "{{ nextcloud_dbname }}" - MYSQL_USER: "{{ nextcloud_dbuser }}" - MYSQL_PASSWORD: "{{ nextcloud_dbpass }}" - register: nextcloud_container + links: "{{ nextcloud_dbcontainer }}:mysql" - name: Grab Nextcloud container information docker_container_info: - name: "{{ nextcloud_name }}" + name: "{{ nextcloud_container }}" register: nextcloud_info - name: Wait for Nextcloud to become available @@ -41,17 +36,17 @@ port: 80 - name: Check Nextcloud status - command: "docker exec --user www-data {{ nextcloud_name }} + command: "docker exec --user www-data {{ nextcloud_container }} php occ status" register: nextcloud_status args: - removes: "{{ nextcloud_root }}/public_html/config/CAN_INSTALL" + removes: "{{ nextcloud_root }}/config/CAN_INSTALL" - name: Install Nextcloud - command: 'docker exec --user www-data {{ nextcloud_name }} + command: 'docker exec --user www-data {{ nextcloud_container }} php occ maintenance:install --database "mysql" - --database-host "{{ mariadb_name }}" + --database-host "{{ nextcloud_dbcontainer }}" --database-name "{{ nextcloud_dbname }}" --database-user "{{ nextcloud_dbuser }}" --database-pass "{{ nextcloud_dbpass }}" @@ -63,13 +58,13 @@ - nextcloud_domain is defined - name: Set Nextcloud's Trusted Domain - command: 'docker exec --user www-data {{ nextcloud_name }} + command: 'docker exec --user www-data {{ nextcloud_container }} php occ config:system:set trusted_domains 0 --value="{{ nextcloud_domain }}"' when: nextcloud_install.changed - name: Preform Nextcloud database maintenance - command: "docker exec --user www-data {{ nextcloud_name }} {{ item }}" + command: "docker exec --user www-data {{ nextcloud_container }} {{ item }}" loop: - "php occ maintenance:mode --on" - "php occ db:add-missing-indices" @@ -79,5 +74,5 @@ - name: Remove Nextcloud's CAN_INSTALL file file: - path: "{{ nextcloud_root }}/public_html/config/CAN_INSTALL" + path: "{{ nextcloud_root }}/config/CAN_INSTALL" state: absent