add postgres compatibility

This commit is contained in:
vincent 2020-09-08 19:27:15 +02:00
parent 10c93e1916
commit 91afd99167
6 changed files with 91 additions and 31 deletions

View File

@ -4,14 +4,17 @@ nextcloud_db_name: nextcloud
nextcloud_SQl_target_file:
nextcloud_db_user: nextcloud
nextcloud_db_password:
nextcloud_dbhost: localhost
nextcloud_dbport:
nextcloud_DB_type: postgres # mysql or postgres
nextcloud_admin_user: admin
nextcloud_admin_password:
nextcloud_datadirectory: /var/nextcloud
nextcloud_web_root: /usr/share/webapps/nextcloud
nextcloud_trusted_domains:
- localhost
nextcloud_dbhost: localhost
nextcloud_dbport:
nextcloud_config_options: # additional options to set in config.php
- option: overwrite.cli.url

View File

@ -48,7 +48,6 @@ galaxy_info:
dependencies:
- {role: nginx,become: yes}
- {role: mariadb,become: yes}
- php
- cronie
- fail2ban

27
tasks/database_mysql.yml Normal file
View File

@ -0,0 +1,27 @@
- name: "Ensure database is present"
become: yes
mysql_db:
name: "{{ nextcloud_db_name }}"
collation: utf8mb4_unicode_ci
encoding: utf8mb4
state: present
register: nextcloud_database_creation
- name: import DATA in database in case of creation
become: yes
mysql_db:
name: "{{ nextcloud_db_name }}"
state: import
target: "{{gitea_SQl_target_file}}"
register: nextcloud_database_import
when: nextcloud_database_creation.changed == true and nextcloud_SQl_target_file is defined
- name: "Ensure db user is present"
become: yes
mysql_user:
name: "{{ nextcloud_db_user }}"
host: localhost
password: "{{ nextcloud_db_password }}"
priv: "{{ nextcloud_db_name }}.*:ALL"
state: present

View File

@ -0,0 +1,29 @@
- name: "Ensure db user is present"
become: yes
become_user: postgres
postgresql_user:
name: "{{ nextcloud_db_user }}"
password: "{{ nextcloud_db_password }}"
state: present
- name: "Ensure database is present"
become: yes
become_user: postgres
postgresql_db:
name: "{{ nextcloud_db_name }}"
lc_collate: fr_FR.UTF-8
encoding: utf8
owner: "{{ nextcloud_db_user }}"
state: present
register: nextcloud_database_creation
- name: import DATA in database in case of creation
become: yes
become_user: postgres
postgresql_db:
name: "{{ nextcloud_db_name }}"
state: restore
target: "{{ nextcloud_SQl_target_file }}"
register: nextcloud_database_import
when: nextcloud_database_creation.changed == true and nextcloud_SQl_target_file is defined

View File

@ -1,31 +1,8 @@
---
# tasks file for nextcloud
- name: "Ensure database is present"
become: yes
mysql_db:
name: "{{ nextcloud_db_name }}"
collation: utf8mb4_unicode_ci
encoding: utf8mb4
state: present
register: nextcloud_database_creation
- name: import DATA in database in case of creation
become: yes
mysql_db:
name: "{{ nextcloud_db_name }}"
state: import
target: "{{gitea_SQl_target_file}}"
when: nextcloud_database_creation.changed == true and nextcloud_SQl_target_file is defined
- name: "Ensure db user is present"
become: yes
mysql_user:
name: "{{ nextcloud_db_user }}"
host: localhost
password: "{{ nextcloud_db_password }}"
priv: "{{ nextcloud_db_name }}.*:ALL"
state: present
- name: select specific Database tasks
include_tasks: "database_{{nextcloud_DB_type}}.yml"
- name: ensure pacman hook folder exist
become: true
@ -77,15 +54,16 @@
- name: installation - ensure nextcloud installation is finished
- name: installation - ensure nextcloud config
command: >
php {{ nextcloud_web_root }}/occ maintenance:install --database "mysql" --database-name "{{ nextcloud_db_name}}"
php {{ nextcloud_web_root }}/occ maintenance:install --database "{{ 'pgsql' if nextcloud_DB_type == 'postgres' else nextcloud_DB_type }}" --database-name "{{ nextcloud_db_name}}"
--database-user "{{ nextcloud_db_user }}" --database-pass "{{ nextcloud_db_password }}"
--admin-user "{{ nextcloud_admin_user }}" --admin-pass "{{ nextcloud_admin_password }}" --data-dir "{{ nextcloud_datadirectory }}"
become: true
become_user: http
changed_when: true
when: installed_mode is changed or nextcloud_config_exist.stat.exists == false
- name: installation - ensure trusted domains are set
command: 'php {{ nextcloud_web_root }}/occ config:system:set trusted_domains {{ item.0 }} --value "{{ item.1 }}"'
@ -95,6 +73,16 @@
with_indexed_items:
- '{{ nextcloud_trusted_domains }}'
- name: ensure correct database parameter in config.php
become: true
lineinfile:
path: '{{ nextcloud_web_root }}/config/config.php'
regexp: '^\s*''{{ item.option }}'''
line: ' ''{{ item.option }}'' => {{ item.value }},'
insertafter: '\$CONFIG'
with_items: '{{ nextcloud_db_options }}'
when: nextcloud_config_options is defined
- name: ensure additional options are set in config.php if defined
become: true
lineinfile:

View File

@ -1,2 +1,16 @@
---
# vars file for nextcloud
# vars file for nextcloud
nextcloud_db_options:
- option: dbtype
value: "{{ 'pgsql' if nextcloud_DB_type == 'postgres' else nextcloud_DB_type }}"
- option: dbname
value: "{{nextcloud_db_name}}"
- option: dbuser
value: "{{nextcloud_db_user}}"
- option: dbpassword
value: "{{nextcloud_db_password}}"
- option: dbhost
value: "{{nextcloud_dbhost}}"
- option: dbport
value: "{{nextcloud_dbport}}"