add mysql support

This commit is contained in:
Geno 2020-11-20 18:05:07 +01:00
parent b72b4e03b1
commit 39eaf80273
4 changed files with 43 additions and 0 deletions

View File

@ -16,8 +16,10 @@ osp_db_name: osp
osp_db_user: osp osp_db_user: osp
osp_db_location: 'sqlite:///db/database.db' osp_db_location: 'sqlite:///db/database.db'
osp_db_type: "sqlite" osp_db_type: "sqlite"
#osp_db_pass: "" # required
#osp_db_type: "cockroachdb" #osp_db_type: "cockroachdb"
osp_db_location_postgresql: "postgresql://{{ osp_db_user }}@{{ osp_db_host }}/{{ osp_db_name }}" 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_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_password_salt: "{{ lookup('password', 'credentials/'+inventory_hostname+'/osp_password_salt length=8 chars=digits') }}"
osp_allow_registration: yes osp_allow_registration: yes

34
tasks/db_mysql.yml Normal file
View File

@ -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 }}"

View File

@ -118,6 +118,10 @@
include_tasks: db_postgresql.yml include_tasks: db_postgresql.yml
when: osp_db_type == "postgresql" when: osp_db_type == "postgresql"
- name: Database
include_tasks: db_mysql.yml
when: osp_db_type == "mysql"
- name: Clone OSP repository - name: Clone OSP repository
git: git:
repo: "{{ osp_git_root }}" repo: "{{ osp_git_root }}"

View File

@ -6,6 +6,9 @@ PartOf=osp.target
{% if osp_db_type == "postgresql" %} {% if osp_db_type == "postgresql" %}
After=postgresql.service After=postgresql.service
{% endif %} {% endif %}
{% if osp_db_type == "mysql" %}
After=mysql.service
{% endif %}
[Service] [Service]
User=http User=http