From 954ea7f2a6982750ed4eb0a2ab5f37dd69bb540f Mon Sep 17 00:00:00 2001 From: Kris Lamoureux Date: Tue, 7 Jul 2020 17:21:04 -0400 Subject: [PATCH] Initial admin credentials for Nextcloud container --- dev/host_vars/nextcloud.yml | 3 ++ roles/docker/defaults/main.yml | 1 - roles/nextcloud/defaults/main.yml | 1 + roles/nextcloud/tasks/main.yml | 54 ++++++++++++++++++++++++++----- 4 files changed, 50 insertions(+), 9 deletions(-) delete mode 100644 roles/docker/defaults/main.yml diff --git a/dev/host_vars/nextcloud.yml b/dev/host_vars/nextcloud.yml index e677cda..cf30247 100644 --- a/dev/host_vars/nextcloud.yml +++ b/dev/host_vars/nextcloud.yml @@ -3,3 +3,6 @@ mariadb_version: latest nextcloud_name: nextcloud nextcloud_dbpass: password nextcloud_version: stable +nextcloud_admin: admin +nextcloud_pass: password +nextcloud_domain: cloud.vm.krislamo.org diff --git a/roles/docker/defaults/main.yml b/roles/docker/defaults/main.yml deleted file mode 100644 index 7278ac6..0000000 --- a/roles/docker/defaults/main.yml +++ /dev/null @@ -1 +0,0 @@ -docker_user: vagrant diff --git a/roles/nextcloud/defaults/main.yml b/roles/nextcloud/defaults/main.yml index 7af2365..139e7e0 100644 --- a/roles/nextcloud/defaults/main.yml +++ b/roles/nextcloud/defaults/main.yml @@ -2,3 +2,4 @@ mariadb_name: mariadb nextcloud_dbname: nextcloud nextcloud_dbuser: nextcloud +nextcloud_root: "/opt/{{ nextcloud_name }}" diff --git a/roles/nextcloud/tasks/main.yml b/roles/nextcloud/tasks/main.yml index e0d4111..1d8f875 100644 --- a/roles/nextcloud/tasks/main.yml +++ b/roles/nextcloud/tasks/main.yml @@ -1,3 +1,8 @@ +- name: Create Docker container bind mount directory + file: + path: "{{ nextcloud_root }}/public_html" + state: directory + - name: Start MariaDB container docker_container: name: "{{ mariadb_name }}" @@ -15,7 +20,7 @@ name: "{{ nextcloud_name }}" image: nextcloud:{{ nextcloud_version }} restart_policy: always - volumes: nextcloud:/var/www/html + volumes: "{{ nextcloud_root }}/public_html:/var/www/html" ports: 80:80 links: "{{ mariadb_name }}:mysql" env: @@ -25,11 +30,44 @@ MYSQL_PASSWORD: "{{ nextcloud_dbpass }}" register: nextcloud_container -- name: Do Nextcloud database maintenance - command: "docker exec --user www-data {{ nextcloud_name }} php {{ item }}" +- name: Grab Nextcloud container information + docker_container_info: + name: "{{ nextcloud_name }}" + register: nextcloud_info + +- name: Wait for Nextcloud to become available + wait_for: + host: "{{ nextcloud_info.container.NetworkSettings.IPAddress }}" + port: 80 + +- name: Check Nextcloud status + command: "docker exec --user www-data {{ nextcloud_name }} + php occ status" + register: nextcloud_status + args: + removes: "{{ nextcloud_root }}/public_html/config/CAN_INSTALL" + +- name: Install Nextcloud + command: 'docker exec --user www-data {{ nextcloud_name }} + php occ maintenance:install + --admin-user "{{ nextcloud_admin }}" + --admin-pass "{{ nextcloud_pass }}"' + register: nextcloud_install + when: + - nextcloud_status.stdout[:26] == "Nextcloud is not installed" + - nextcloud_domain is defined + +- name: Set Nextcloud's Trusted Domain + command: 'docker exec --user www-data {{ nextcloud_name }} + 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 }}" loop: - - "occ maintenance:mode --on" - - "occ db:add-missing-indices" - - "occ db:convert-filecache-bigint" - - "occ maintenance:mode --off" - when: nextcloud_container.changed + - "php occ maintenance:mode --on" + - "php occ db:add-missing-indices" + - "php occ db:convert-filecache-bigint" + - "php occ maintenance:mode --off" + when: nextcloud_install.changed