From 71bf56e60ff6ecb950b122f9c2e0b84f9c2fc44e Mon Sep 17 00:00:00 2001 From: Felix Stupp Date: Sat, 12 Sep 2020 23:24:57 +0200 Subject: [PATCH] server/nextcloud: Changed approach for config to import prepared JSON --- roles/server/nextcloud/defaults/main.yml | 22 ++++++++++ roles/server/nextcloud/tasks/main.yml | 53 ++++++++++-------------- 2 files changed, 43 insertions(+), 32 deletions(-) diff --git a/roles/server/nextcloud/defaults/main.yml b/roles/server/nextcloud/defaults/main.yml index 9adb5f5..7df9c77 100644 --- a/roles/server/nextcloud/defaults/main.yml +++ b/roles/server/nextcloud/defaults/main.yml @@ -18,6 +18,7 @@ nextcloud_keyring: "{{ user_directory }}/nextcloud.gpg" nextcloud_release_file: "{{ user_directory }}/nextcloud.tar.bz2" nextcloud_release_signature: "{{ nextcloud_release_file }}.asc" nextcloud_config: "{{ nextcloud_installation_directory }}/config/config.php" +import_config_file: "{{ nextcloud_installation_directory }}/config/config.json" status_page_path: "{{ phpfpm_status_page_path }}" status_page_acl: "{{ nginx_status_page_acl }}" @@ -31,6 +32,27 @@ database_user: "{{ system_user }}" nextcloud_admin_user: "admin" nextcloud_admin_pass: "{{ lookup('password', 'credentials/' + inventory_hostname + '/' + domain + '/' + nextcloud_admin_user + ' length=80') }}" +import_config: + system: + # domain + "overwrite.cli.url": "{{ domain }}" + trusted_domains: + - "{{ domain }}" + # database + dbtype: mysql + dbhost: localhost + dbport: "" + dbuser: "{{ database_user }}" + dbpass: "{{ database_pass }}" + dbname: "{{ database_name }}" + # memcache + memcache.local: '\OC\Memcache\APCu' + memcache.distributed: '\OC\Memcache\Redis' + memcache.locking: '\OC\Memcache\Redis' + redis: + host: "{{ redis_socket_path }}" + port: 0 + enabled_apps_list: - accessibility - activity diff --git a/roles/server/nextcloud/tasks/main.yml b/roles/server/nextcloud/tasks/main.yml index 5495262..87db4f6 100644 --- a/roles/server/nextcloud/tasks/main.yml +++ b/roles/server/nextcloud/tasks/main.yml @@ -71,40 +71,29 @@ chdir: "{{ nextcloud_installation_directory }}" creates: "{{ nextcloud_config }}" -- name: Configure Nextcloud default domain - become_user: "{{ system_user }}" - lineinfile: - path: "{{ nextcloud_config }}" - firstmatch: yes - insertafter: "array \\(" - regexp: "^(\\s*)0 => '([^.]\\.)+[^.]*',$" - line: " 0 => '{{ domain }}'," - validate: /usr/bin/php %s - -- name: Configure Nextcloud default domain for cli - become_user: "{{ system_user }}" - lineinfile: - path: "{{ nextcloud_config }}" - firstmatch: yes - insertafter: "'version'" - regexp: "^(\\s*)'overwrite.cli.url' => '.*',$" - line: " 'overwrite.cli.url' => 'https://{{ domain }}'," - validate: /usr/bin/php %s +- name: Store additional Nextcloud configuration + copy: + content: "{{ import_config | to_nice_json }}\n" + dest: "{{ import_config_file }}" + owner: "{{ system_user }}" + group: "{{ system_user }}" + mode: u=rw,g=r,o= + register: import_config_file_task + tags: + - nextcloud_config -- name: Add additional entries to Nextcloud config +- name: Import additional Nextcloud configuration become_user: "{{ system_user }}" - blockinfile: - path: "{{ nextcloud_config }}" - insertbefore: "^\\);" - block: | - 'memcache.local' => '\\OC\\Memcache\\APCu', - 'memcache.distributed' => '\\OC\\Memcache\\Redis', - 'memcache.locking' => '\\OC\\Memcache\\Redis', - 'redis' => [ - 'host' => '{{ redis_socket_path }}', - 'port' => 0, - ], - validate: /usr/bin/php %s + command: >- + /usr/bin/php occ + config:import + {{ import_config_file }} + args: + chdir: "{{ nextcloud_installation_directory }}" + creates: "{{ nextcloud_config }}" + when: import_config_file_task.changed + tags: + - nextcloud_config - name: Install Nextcloud apps become_user: "{{ system_user }}"