From fc9210debb8cd0e9954ce881f77e238df39d32bc Mon Sep 17 00:00:00 2001 From: vincent Date: Tue, 8 Sep 2020 21:18:56 +0200 Subject: [PATCH] adapt tt-rss --- defaults/main.yml | 1 + tasks/database_mysql.yml | 25 +++++++++++++++++++++++++ tasks/database_postgres.yml | 29 +++++++++++++++++++++++++++++ templates/config.php.j2 | 2 +- 4 files changed, 56 insertions(+), 1 deletion(-) create mode 100644 tasks/database_mysql.yml create mode 100644 tasks/database_postgres.yml diff --git a/defaults/main.yml b/defaults/main.yml index 87b092a..86617d9 100644 --- a/defaults/main.yml +++ b/defaults/main.yml @@ -1,6 +1,7 @@ --- # defaults file for tt-rss # Database user +ttrss_db_type: postgres #postgres or mysql ttrss_db_user: ttrss # Database password, please change when using the role ttrss_db_password: ttrss diff --git a/tasks/database_mysql.yml b/tasks/database_mysql.yml new file mode 100644 index 0000000..23f82d4 --- /dev/null +++ b/tasks/database_mysql.yml @@ -0,0 +1,25 @@ +- name: "Ensure database is present" + become: yes + mysql_db: + name: "{{ ttrss_db_name }}" + collation: utf8_general_ci + encoding: utf8 + state: present + register: ttrss_database_creation + +- name: import DATA in database in case of creation + become: yes + mysql_db: + name: "{{ ttrss_db_name }}" + state: import + target: "{{ttrss_SQl_target_file}}" + when: ttrss_database_creation.changed == true and ttrss_SQl_target_file is defined + +- name: "Ensure db user is present" + become: yes + mysql_user: + name: "{{ ttrss_db_user }}" + host: localhost + password: "{{ ttrss_db_password }}" + priv: "{{ ttrss_db_name }}.*:ALL" + state: present diff --git a/tasks/database_postgres.yml b/tasks/database_postgres.yml new file mode 100644 index 0000000..df19fa2 --- /dev/null +++ b/tasks/database_postgres.yml @@ -0,0 +1,29 @@ +- name: "Ensure db user is present" + become: yes + become_user: postgres + postgresql_user: + name: "{{ ttrss_db_user }}" + password: "{{ ttrss_db_password }}" + state: present + +- name: "Ensure database is present" + become: yes + become_user: postgres + postgresql_db: + name: "{{ ttrss_db_name }}" + lc_collate: fr_FR.UTF-8 + encoding: utf8 + owner: "{{ ttrss_db_user }}" + state: present + register: ttrss_database_creation + + +- name: import DATA in database in case of creation + become: yes + become_user: postgres + postgresql_db: + name: "{{ ttrss_db_name }}" + state: restore + target: "{{ ttrss_SQl_target_file }}" + register: ttrss_database_import + when: ttrss_database_creation.changed == true and ttrss_SQl_target_file is defined \ No newline at end of file diff --git a/templates/config.php.j2 b/templates/config.php.j2 index 5e659b4..808a99d 100644 --- a/templates/config.php.j2 +++ b/templates/config.php.j2 @@ -2,7 +2,7 @@ // ******************************************* // *** Database configuration (important!) *** // ******************************************* - define('DB_TYPE', 'mysql'); + define('DB_TYPE', '{{ ttrss_db_type}}'); define('DB_HOST', 'localhost'); define('DB_USER', '{{ ttrss_db_user}}'); define('DB_NAME', '{{ttrss_db_name}}');