From e9715e31bf4c1dc77b4e4caeeb8fe360c9f0c97c Mon Sep 17 00:00:00 2001 From: Johanna Dorothea Reichmann Date: Sun, 24 Oct 2021 15:50:32 +0200 Subject: [PATCH] feat(server): allow configuring nextcloud settings by populating `nextcloud_extra_config` --- .../server/tasks/configure-single-setting.yml | 30 +++++++++++++ roles/server/tasks/main.yml | 44 +++---------------- roles/server/vars/main.yml | 13 ++++++ 3 files changed, 50 insertions(+), 37 deletions(-) create mode 100644 roles/server/tasks/configure-single-setting.yml diff --git a/roles/server/tasks/configure-single-setting.yml b/roles/server/tasks/configure-single-setting.yml new file mode 100644 index 0000000..3f0c7a1 --- /dev/null +++ b/roles/server/tasks/configure-single-setting.yml @@ -0,0 +1,30 @@ +--- + +- name: Ensure {{ key }} is set to {{ value }} + block: + - name: Check value of {{ key }} + community.docker.docker_container_exec: + container: "{{ nextcloud_container_name }}" + command: "{{ nextcloud_occ_command }} config:{{ type }}:get {{ scope }} {{ entry }}" + user: "{{ nextcloud_user_info.uid }}" + tty: yes + register: nextcloud_current_config_entry + changed_when: false + + - name: Set {{ key }} to {{ value }} + community.docker.docker_container_exec: + container: "{{ nextcloud_container_name }}" + command: "{{ nextcloud_occ_command }} config:{{ type }}:set {{ scope }} {{ entry }} --value={{ value }} -n" + user: "{{ nextcloud_user_info.uid }}" + tty: yes + when: nextcloud_current_config_entry.stdout != value + notify: restart-nextcloud + vars: + entry_path: "{{ key.split('.') }}" + type: "{{ entry_path | first }}" + scope: "{{ entry_path[1] if entry_path | length > 2 else '' }}" + entry: >- + {{ + entry_path[1] if entry_path|length == 2 else + (entry_path[2:] | join(" ")) + }} diff --git a/roles/server/tasks/main.yml b/roles/server/tasks/main.yml index 9febf32..b8be4cb 100644 --- a/roles/server/tasks/main.yml +++ b/roles/server/tasks/main.yml @@ -135,40 +135,10 @@ state: started when: nextcloud_background_job_mode == 'cron' -- name: Check nextcloud background job mode - community.docker.docker_container_exec: - container: "{{ nextcloud_container_name }}" - command: "{{ nextcloud_occ_command }} config:app:get core backgroundjobs_mode" - user: "{{ nextcloud_user_info.uid }}" - tty: yes - register: nextcloud_current_backgroundjob_mode - # As nextcloud might still be starting, retry this task - retries: 5 - delay: 5 - changed_when: false - -- name: Set nextcloud background job mode to {{ nextcloud_background_job_mode }} - community.docker.docker_container_exec: - container: "{{ nextcloud_container_name }}" - command: "{{ nextcloud_occ_command }} config:app:set core backgroundjobs_mode {{ nextcloud_background_job_mode }}" - user: "{{ nextcloud_user_info.uid }}" - tty: yes - when: nextcloud_current_backgroundjob_mode.stdout != nextcloud_background_job_mode - -- name: Check nextcloud database host - community.docker.docker_container_exec: - container: "{{ nextcloud_container_name }}" - command: "{{ nextcloud_occ_command }} config:system:get dbhost" - user: "{{ nextcloud_user_info.uid }}" - tty: yes - register: nextcloud_current_dbhost - changed_when: false - -- name: Set nextcloud database host mode to {{ nextcloud_database_host }} - community.docker.docker_container_exec: - container: "{{ nextcloud_container_name }}" - command: "{{ nextcloud_occ_command }} config:system:set dbhost --value={{ nextcloud_database_host }} --update-only -n" - user: "{{ nextcloud_user_info.uid }}" - tty: yes - when: nextcloud_current_dbhost.stdout != nextcloud_database_host - notify: restart-nextcloud +- name: Configure nextcloud + include_tasks: + file: configure-single-setting.yml + vars: + key: "{{ item.key | replace('[', '.') | replace(']', '.') }}" + value: "{{ item.value }}" + loop: "{{ lookup('ansible.utils.to_paths', nextcloud_config ) | dict2items }}" diff --git a/roles/server/vars/main.yml b/roles/server/vars/main.yml index 9dee6fd..3dbb4d0 100644 --- a/roles/server/vars/main.yml +++ b/roles/server/vars/main.yml @@ -25,5 +25,18 @@ nextcloud_container_base_environment_yaml: |+2 PHP_MEMORY_LIMIT: "{{ nextcloud_php_memory_limit }}" PHP_UPLOAD_LIMIT: "{{ nextcloud_php_upload_limit }}" +nextcloud_config: "{{ nextcloud_base_config | combine(nextcloud_extra_config|default({}), recursive=True, list_merge='append') }}" +nextcloud_base_config: + system: + # TODO: needs to have conditions as f.ex. sqlite doesn't have a user + dbhost: "{{ nextcloud_database_host }}" + dbuser: "{{ nextcloud_database_user }}" + dbpassword: "{{ nextcloud_database_pass }}" + dbname: "{{ nextcloud_database_name }}" + #dbtype: "{{ nextcloud_db_types[nextcloud_database_type] }}" + app: + core: + backgroundjobs_mode: "{{ nextcloud_background_job_mode }}" + nextcloud_occ_command: "php occ" nextcloud_container_php_socket_path: /var/run/php