From ab3db12fca48c92dd473f915ce79f3f0752c3d50 Mon Sep 17 00:00:00 2001 From: Simeon Keske Date: Thu, 19 Nov 2020 23:25:23 +0100 Subject: [PATCH] implement upgrade --- defaults/main.yml | 1 + tasks/main.yml | 60 +++++++++++++++++++++++++++-------------------- 2 files changed, 36 insertions(+), 25 deletions(-) diff --git a/defaults/main.yml b/defaults/main.yml index f69600f..80bafbe 100644 --- a/defaults/main.yml +++ b/defaults/main.yml @@ -18,6 +18,7 @@ nextcloud_datadir: "/var/www/nextcloud/data" # nextcloud_db_password # nextcloud_admin_password +nextcloud_config: [] # nextcloud_config: # - key: foobar # value: baz diff --git a/tasks/main.yml b/tasks/main.yml index 34559a3..70eb08c 100644 --- a/tasks/main.yml +++ b/tasks/main.yml @@ -7,39 +7,25 @@ group: "{{ nextcloud_group }}" loop: - "{{ nextcloud_directory }}" - - "{{ nextcloud_directory }}/nextcloud-{{ nextcloud_version }}" + - "{{ nextcloud_install_directory }}" - "{{ nextcloud_datadir }}" -- name: Download Nextcloud release - get_url: - url: "{{ nextcloud_download }}" - dest: "{{ nextcloud_directory }}/nextcloud-{{ nextcloud_version }}.tar.bz2" - owner: "{{ nextcloud_user }}" - group: "{{ nextcloud_group }}" +- name: Get current installed nextcloud version + stat: + path: "{{ nextcloud_directory }}/current" + register: nc_current -- name: Extract the nextcloud release +- name: Download and extract the nextcloud release become: yes become_user: "{{ nextcloud_user }}" unarchive: - src: "{{ nextcloud_directory }}/nextcloud-{{ nextcloud_version }}.tar.bz2" + src: "{{ nextcloud_download }}" dest: "{{ nextcloud_install_directory }}" remote_src: yes extra_opts: - "--strip-components=1" + when: not nc_current.stat.lnk_target is defined or nc_current.stat.lnk_target != nextcloud_install_directory -# TODO: Detect older installed releases -# TODO: copy old nextcloud config - -# TODO: only run if not newly installed and when nc should be updated -- name: Put nextcloud into maintenance mode - become: yes - become_user: "{{ nextcloud_user }}" - command: "php occ maintenance:mode --on" - args: - chdir: "{{ nextcloud_directory }}/current" - ignore_errors: yes - -# TODO: only run if newly installed, then remove ignore_error - name: Generate nextcloud config file become: yes become_user: "{{ nextcloud_user }}" @@ -56,8 +42,14 @@ args: chdir: "{{ nextcloud_install_directory }}" creates: "{{ nextcloud_install_directory }}/config/config.php" - ignore_errors: yes - register: setup_nc + when: not nc_current.stat.lnk_target is defined + +- name: Copy old nextcloud config + copy: + src: "{{ nextcloud_directory }}/current/config/config.php" + dest: "{{ nextcloud_install_directory }}/config/config.php" + remote_src: yes + when: not nc_current.stat.lnk_target is defined or nc_current.stat.lnk_target != nextcloud_install_directory - name: Configure nextcloud become: yes @@ -67,7 +59,16 @@ chdir: "{{ nextcloud_install_directory }}" loop: "{{ nextcloud_config }}" -# TODO: run update command +# TODO: install apps + +- name: Put nextcloud into maintenance mode + become: yes + become_user: "{{ nextcloud_user }}" + command: "php occ maintenance:mode --on" + args: + chdir: "{{ nextcloud_directory }}/current" + ignore_errors: yes + when: nc_current.stat.lnk_target is defined and nc_current.stat.lnk_target != nextcloud_install_directory - name: Symlink current nextcloud version become: yes @@ -79,6 +80,15 @@ group: "{{ nextcloud_group }}" state: link +- name: Put nextcloud into maintenance mode + become: yes + become_user: "{{ nextcloud_user }}" + command: "php occ upgrade --no-interaction" + args: + chdir: "{{ nextcloud_directory }}/current" + ignore_errors: yes + when: nc_current.stat.lnk_target is defined and nc_current.stat.lnk_target != nextcloud_install_directory + - name: Take nextcloud out of maintenance mode become: yes become_user: "{{ nextcloud_user }}"