From 39eaf802732f3645a36df078badae0f0e005959d Mon Sep 17 00:00:00 2001 From: Geno Date: Fri, 20 Nov 2020 18:05:07 +0100 Subject: [PATCH] add mysql support --- defaults/main.yml | 2 ++ tasks/db_mysql.yml | 34 ++++++++++++++++++++++++++++++++++ tasks/main.yml | 4 ++++ templates/osp-worker@.service | 3 +++ 4 files changed, 43 insertions(+) create mode 100644 tasks/db_mysql.yml diff --git a/defaults/main.yml b/defaults/main.yml index 5c30e80..acc02fa 100644 --- a/defaults/main.yml +++ b/defaults/main.yml @@ -16,8 +16,10 @@ osp_db_name: osp osp_db_user: osp osp_db_location: 'sqlite:///db/database.db' osp_db_type: "sqlite" +#osp_db_pass: "" # required #osp_db_type: "cockroachdb" osp_db_location_postgresql: "postgresql://{{ osp_db_user }}@{{ osp_db_host }}/{{ osp_db_name }}" +osp_db_location_mysql: "mysql+pymysql://{{ osp_db_user }}:{{osp_db_pass}}@{{ osp_db_host }}/{{ osp_db_name }}?charset=utf8mb4" osp_secret_key: "{{ lookup('password', 'credentials/'+inventory_hostname+'/osp_secret_key length=8 chars=digits') }}" osp_password_salt: "{{ lookup('password', 'credentials/'+inventory_hostname+'/osp_password_salt length=8 chars=digits') }}" osp_allow_registration: yes diff --git a/tasks/db_mysql.yml b/tasks/db_mysql.yml new file mode 100644 index 0000000..9fbe822 --- /dev/null +++ b/tasks/db_mysql.yml @@ -0,0 +1,34 @@ +- name: DB - Install + package: + name: + - mariadb + - python-mysqlclient + +- name: DB - Init + command: mariadb-install-db --user=mysql --basedir=/usr --datadir=/var/lib/mysql + args: + creates: /var/lib/mysql/ + +- name: Started + systemd: + name: mariadb + enabled: yes + state: started + +- name: DB - create user + mysql_user: + login_host: "{{ osp_db_host }}" + name: "{{ osp_db_user }}" + password: "{{ osp_db_pass }}" + priv: '{{ osp_db_name }}.*:ALL,GRANT' + +- name: DB - create database + mysql_db: + login_host: "{{ osp_db_host }}" + name: "{{ osp_db_name }}" + encoding: utf8mb4 + +- name: Set DB location + when: osp_db_location != "///db/database.db" + set_fact: + osp_db_location: "{{ osp_db_location_mysql }}" diff --git a/tasks/main.yml b/tasks/main.yml index 0b56685..6cac741 100644 --- a/tasks/main.yml +++ b/tasks/main.yml @@ -118,6 +118,10 @@ include_tasks: db_postgresql.yml when: osp_db_type == "postgresql" +- name: Database + include_tasks: db_mysql.yml + when: osp_db_type == "mysql" + - name: Clone OSP repository git: repo: "{{ osp_git_root }}" diff --git a/templates/osp-worker@.service b/templates/osp-worker@.service index 96d4d46..02b7286 100644 --- a/templates/osp-worker@.service +++ b/templates/osp-worker@.service @@ -6,6 +6,9 @@ PartOf=osp.target {% if osp_db_type == "postgresql" %} After=postgresql.service {% endif %} +{% if osp_db_type == "mysql" %} +After=mysql.service +{% endif %} [Service] User=http