From 296f081c43297b68e18b0bd09c84f687272c5cc2 Mon Sep 17 00:00:00 2001 From: Markus Katharina Brechtel Date: Mon, 29 Jun 2020 07:33:41 +0200 Subject: [PATCH] Postgresql support and other improvements --- defaults/main.yml | 4 +++- tasks/install.yml | 5 +++-- tasks/main.yml | 3 +++ tasks/mysql.yml | 4 ++-- tasks/postgresql.yaml | 26 ++++++++++++++++++++++++++ tasks/reset.yml | 16 +++++++++++++++- tasks/setup_Debian.yml | 2 ++ vars/main.yml | 8 ++++++++ 8 files changed, 62 insertions(+), 6 deletions(-) create mode 100644 tasks/postgresql.yaml diff --git a/defaults/main.yml b/defaults/main.yml index adbf47f..09690a8 100644 --- a/defaults/main.yml +++ b/defaults/main.yml @@ -28,6 +28,8 @@ nextcloud_server_names: nextcloud_force_downgrade: false -timezone: UTC +timezone: Europe/Berlin + +nextcloud_postgresql_lc: de_DE.UTF-8 nextcloud_php_version: 7.3 diff --git a/tasks/install.yml b/tasks/install.yml index fef5b60..e1bb9a1 100644 --- a/tasks/install.yml +++ b/tasks/install.yml @@ -24,8 +24,9 @@ php occ maintenance:install --admin-user "{{ nextcloud_admin_user }}" --admin-pass "{{ nextcloud_admin_pass }}" - --database "{{ nextcloud_database_type }}" - --database-host "{{ (nextcloud_database_host == inventory_hostname) | ternary('localhost',nextcloud_database_host) }}" + --database "{{ _nextcloud_database_type_cli[nextcloud_database_type] }}" + --database-host "{{ (nextcloud_database_host == inventory_hostname) + | ternary(_nextcloud_database_localhost_cli[nextcloud_database_type],nextcloud_database_host) }}" --database-name "{{ nextcloud_database_name }}" --database-user "{{ nextcloud_database_user }}" --database-pass "{{ nextcloud_database_pass }}" diff --git a/tasks/main.yml b/tasks/main.yml index b8b50a6..7354a2d 100644 --- a/tasks/main.yml +++ b/tasks/main.yml @@ -22,6 +22,9 @@ - import_tasks: mysql.yml when: nextcloud_database_type == "mysql" +- import_tasks: postgresql.yaml + when: nextcloud_database_type == "postgresql" + - import_tasks: core.yml when: nextcloud_state == "reinstalled" or diff --git a/tasks/mysql.yml b/tasks/mysql.yml index 6dce89d..cfde707 100644 --- a/tasks/mysql.yml +++ b/tasks/mysql.yml @@ -6,7 +6,7 @@ host: "{{ (nextcloud_database_host == inventory_hostname) | ternary('localhost',nextcloud_database_host) }}" password: "{{ nextcloud_database_pass }}" priv: "{{nextcloud_database_name}}.*:ALL" - delegate_to: "{{ nextcloud_database_host }}" + delegate_to: "{{ (nextcloud_database_host != 'localhost') | ternary(nextcloud_database_host,inventory_hostname) }}" - name: mysql database mysql_db: @@ -14,4 +14,4 @@ encoding: utf8mb4 collation: utf8mb4_unicode_ci state: present - delegate_to: "{{ nextcloud_database_host }}" + delegate_to: "{{ (nextcloud_database_host != 'localhost') | ternary(nextcloud_database_host,inventory_hostname) }}" diff --git a/tasks/postgresql.yaml b/tasks/postgresql.yaml new file mode 100644 index 0000000..24d739d --- /dev/null +++ b/tasks/postgresql.yaml @@ -0,0 +1,26 @@ +--- + +- name: debian packages required for database management + apt: + pkg: python-psycopg2 + delegate_to: "{{ (nextcloud_database_host != 'localhost') | ternary(nextcloud_database_host,inventory_hostname) }}" + +- name: postgresql database + postgresql_db: + name: "{{nextcloud_database_name}}" + encoding: UTF-8 + lc_collate: "{{nextcloud_postgresql_lc}}" + lc_ctype: "{{nextcloud_postgresql_lc}}" + template: template0 + delegate_to: "{{ (nextcloud_database_host != 'localhost') | ternary(nextcloud_database_host,inventory_hostname) }}" + become: yes + become_user: postgres + +- name: postgresql user + postgresql_user: + name: "{{ nextcloud_database_user }}" + password: "{{ nextcloud_database_pass }}" + db: "{{nextcloud_database_name}}" + delegate_to: "{{ (nextcloud_database_host != 'localhost') | ternary(nextcloud_database_host,inventory_hostname) }}" + become: yes + become_user: postgres diff --git a/tasks/reset.yml b/tasks/reset.yml index 381131e..0cf86f9 100644 --- a/tasks/reset.yml +++ b/tasks/reset.yml @@ -10,13 +10,27 @@ path: "{{nextcloud_directory}}" state: absent +- name: delete nextcloud lib directory + file: + path: "{{nextcloud_lib_directory}}" + state: absent + - name: drop mysql database mysql_db: name: "{{nextcloud_database_name}}" state: absent - delegate_to: "{{ nextcloud_database_host }}" + delegate_to: "{{ (nextcloud_database_host != 'localhost') | ternary(nextcloud_database_host,inventory_hostname) }}" when: nextcloud_database_type == "mysql" +- name: drop postgresql database + postgresql_db: + name: "{{nextcloud_database_name}}" + state: absent + delegate_to: "{{ (nextcloud_database_host != 'localhost') | ternary(nextcloud_database_host,inventory_hostname) }}" + when: nextcloud_database_type == "postgresql" + become: yes + become_user: postgres + - name: delete nextcloud log file: path: /var/log/nextcloud/nextcloud.log diff --git a/tasks/setup_Debian.yml b/tasks/setup_Debian.yml index ea294cb..8298016 100644 --- a/tasks/setup_Debian.yml +++ b/tasks/setup_Debian.yml @@ -19,6 +19,7 @@ - php{{nextcloud_php_version}}-mbstring - php{{nextcloud_php_version}}-zip - php{{nextcloud_php_version}}-mysql + - php{{nextcloud_php_version}}-pgsql - php{{nextcloud_php_version}}-curl - php{{nextcloud_php_version}}-intl - php{{nextcloud_php_version}}-imagick @@ -29,4 +30,5 @@ - php{{nextcloud_php_version}}-memcached - libreoffice - mariadb-client + - rsync notify: restart apache2 diff --git a/vars/main.yml b/vars/main.yml index b85149e..468c145 100644 --- a/vars/main.yml +++ b/vars/main.yml @@ -11,3 +11,11 @@ _nextcloud_valid_states: - reinstalled - installed - updated + +_nextcloud_database_type_cli: + mysql: mysql + postgresql: pgsql + +_nextcloud_database_localhost_cli: + mysql: localhost + postgresql: /var/run/postgresql