From de8edf36f93508e6f68d938f9485a0120dd15528 Mon Sep 17 00:00:00 2001 From: vincent Date: Sun, 6 Sep 2020 22:16:56 +0200 Subject: [PATCH] adapt supysonic role for postgress --- defaults/main.yml | 2 ++ meta/main.yml | 4 ++-- tasks/database_mysql.yml | 25 +++++++++++++++++++++++++ tasks/database_postgres.yml | 35 +++++++++++++++++++++++++++++++++++ tasks/main.yml | 30 +++++------------------------- templates/supysonic.j2 | 2 +- 6 files changed, 70 insertions(+), 28 deletions(-) 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 4e18a2b..6de5dc1 100644 --- a/defaults/main.yml +++ b/defaults/main.yml @@ -11,10 +11,12 @@ exec_group: root supysonic_repo: https://github.com/spl0k/supysonic.git supysonic_force_site_update: false supysonic_repo_branch: master +supysonic_DB_type: postgres # mysql or postgres supysonic_db_user: supysonic # Database password, please change when using the role supysonic_db_password: supysonic # Database name supysonic_db_name: supysonic supysonic_log_level: INFO + gitea_SQl_target_file: [] \ No newline at end of file diff --git a/meta/main.yml b/meta/main.yml index dae7197..717987b 100644 --- a/meta/main.yml +++ b/meta/main.yml @@ -55,7 +55,7 @@ galaxy_info: # NOTE: A tag is limited to a single word comprised of alphanumeric characters. # Maximum 20 tags per role. -dependencies: - - {role: mariadb, become: yes } +dependencies: [] + #- {role: mariadb, become: yes } # List your role dependencies here, one per line. Be sure to remove the '[]' above, # if you add dependencies to this list. \ No newline at end of file diff --git a/tasks/database_mysql.yml b/tasks/database_mysql.yml new file mode 100644 index 0000000..2a35d88 --- /dev/null +++ b/tasks/database_mysql.yml @@ -0,0 +1,25 @@ +- name: "Ensure database is present" + become: yes + mysql_db: + name: "{{ supysonic_db_name }}" + collation: utf8_general_ci + encoding: utf8 + state: present + register: supysonic_database_creation + +- name: import DATA in database in case of creation + become: yes + mysql_db: + name: "{{ supysonic_db_name }}" + state: import + target: "{{supysonic_SQl_target_file}}" + when: supysonic_database_creation.changed == true and supysonic_SQl_target_file is defined + +- name: "Ensure db user is present" + become: yes + mysql_user: + name: "{{ supysonic_db_user }}" + host: localhost + password: "{{ supysonic_db_password }}" + priv: "{{ supysonic_db_name }}.*:ALL" + state: present diff --git a/tasks/database_postgres.yml b/tasks/database_postgres.yml new file mode 100644 index 0000000..9e24d01 --- /dev/null +++ b/tasks/database_postgres.yml @@ -0,0 +1,35 @@ +- name: "Ensure db user is present" + become: yes + become_user: postgres + postgresql_user: + name: "{{ supysonic_db_user }}" + password: "{{ supysonic_db_password }}" + state: present + +- name: "Ensure database is present" + become: yes + become_user: postgres + postgresql_db: + name: "{{ supysonic_db_name }}" + lc_collate: fr_FR.UTF-8 + encoding: utf8 + owner: "{{ supysonic_db_user }}" + state: present + register: supysonic_database_creation + +- name: add citext extention + become: yes + become_user: postgres + postgresql_ext: + db: "{{ supysonic_db_name }}" + name: "citext" + +- name: import DATA in database in case of creation + become: yes + become_user: postgres + postgresql_db: + name: "{{ supysonic_db_name }}" + state: restore + target: "{{supysonic_SQl_target_file}}" + when: supysonic_database_creation.changed == true and supysonic_SQl_target_file is defined + diff --git a/tasks/main.yml b/tasks/main.yml index 7ea901a..332b160 100644 --- a/tasks/main.yml +++ b/tasks/main.yml @@ -1,31 +1,9 @@ --- # tasks file for supysonic -- name: "Ensure database is present" - become: yes - mysql_db: - name: "{{ supysonic_db_name }}" - collation: utf8_general_ci - encoding: utf8 - state: present - register: supysonic_database_creation -- name: import DATA in database in case of creation - become: yes - mysql_db: - name: "{{ supysonic_db_name }}" - state: import - target: "{{supysonic_SQl_target_file}}" - when: supysonic_database_creation.changed == true and supysonic_SQl_target_file is defined - -- name: "Ensure db user is present" - become: yes - mysql_user: - name: "{{ supysonic_db_user }}" - host: localhost - password: "{{ supysonic_db_password }}" - priv: "{{ supysonic_db_name }}.*:ALL" - state: present +- name: select specific Database tasks + include_tasks: "database_{{supysonic_DB_type}}.yml" - name: stat location folder stat: @@ -67,7 +45,9 @@ - name: install sql client pip: virtualenv: "{{venv_location}}{{supysonic_venv_name}}" # not required. An optional path to a I(virtualenv) directory to install into. It cannot be specified together with the 'executable' parameter (added in 2.1). If the virtualenv does not exist, it will be created before installing packages. The optional virtualenv_site_packages, virtualenv_command, and virtualenv_python options affect the creation of the virtualenv. - name: pymysql + name: + - pymysql + - psycopg2 - name: apply config template template: diff --git a/templates/supysonic.j2 b/templates/supysonic.j2 index adeaa6a..faf440c 100644 --- a/templates/supysonic.j2 +++ b/templates/supysonic.j2 @@ -2,7 +2,7 @@ ; A database URI. See the 'schema' folder for schema creation scripts ; Default: sqlite:////tmp/supysonic/supysonic.db ;database_uri = sqlite:////var/supysonic/supysonic.db -database_uri = mysql://{{supysonic_db_user}}:{{supysonic_db_password}}@localhost/{{supysonic_db_name}} +database_uri = {{supysonic_DB_type}}://{{supysonic_db_user}}:{{supysonic_db_password}}@localhost/{{supysonic_db_name}} ;database_uri = postgres://supysonic:supysonic@localhost/supysonic ; Optional, restrict scanner to these extensions. Default: none