From bcb92e483d426432655c4f41c04e0f478b176058 Mon Sep 17 00:00:00 2001 From: Jan Dittberner Date: Wed, 4 Mar 2020 19:32:22 +0100 Subject: [PATCH] Setup gvamysql using new mechanisms --- pillar/gnuviechadmin/gvamysql.sls | 12 ++++-- states/gnuviechadmin/gvamysql.sls | 43 +++++++++++++------ .../gnuviechadmin/gvamysql/celery-worker.env | 6 +++ states/gnuviechadmin/gvamysql/run_celery.sh | 12 ------ states/gnuviechadmin/gvamysql/settings.sh | 8 ---- states/patches/files/3000-mysql.diff | 13 ++++++ states/patches/mysql.sls | 19 ++++++++ 7 files changed, 75 insertions(+), 38 deletions(-) create mode 100644 states/gnuviechadmin/gvamysql/celery-worker.env delete mode 100644 states/gnuviechadmin/gvamysql/run_celery.sh delete mode 100644 states/gnuviechadmin/gvamysql/settings.sh create mode 100644 states/patches/files/3000-mysql.diff create mode 100644 states/patches/mysql.sls diff --git a/pillar/gnuviechadmin/gvamysql.sls b/pillar/gnuviechadmin/gvamysql.sls index 903c235..c7fd768 100644 --- a/pillar/gnuviechadmin/gvamysql.sls +++ b/pillar/gnuviechadmin/gvamysql.sls @@ -4,8 +4,12 @@ include: - gnuviechadmin.queues.gvamysql gnuviechadmin: - component: - name: gvamysql + appname: gvamysql + gvamysql: amqp_user: mysql - mysql_admin_user: gvamysql - mysql_admin_password: jSXstgT/AbWofdI2tJWYpQvFX1mtxt4tFMlrYxSA + fullname: MySQL Server + mysql_admin_user: gvamysql + mysql_admin_password: jSXstgT/AbWofdI2tJWYpQvFX1mtxt4tFMlrYxSA + git_url: https://git.dittberner.info/gnuviech/gvamysql.git + git_branch: master + celery_module: mysqltasks diff --git a/states/gnuviechadmin/gvamysql.sls b/states/gnuviechadmin/gvamysql.sls index e059370..71122dd 100644 --- a/states/gnuviechadmin/gvamysql.sls +++ b/states/gnuviechadmin/gvamysql.sls @@ -1,28 +1,43 @@ +{% set gvaappname = salt['pillar.get']('gnuviechadmin:appname') %} +{% set purpose = "for MySQL/MariaDB configuration management" %} +{% set mysql_admin_user = salt['pillar.get']('gnuviechadmin:{}:mysql_admin_user'.format(gvaappname), 'gvamysql') %} +{% set mysql_admin_password = salt['pillar.get']('gnuviechadmin:{}:mysql_admin_password'.format(gvaappname)) %} +{% from 'gnuviechadmin/gvaapp_macros.sls' import create_celery_worker with context %} include: - - gnuviechadmin.base - - gnuviechadmin.celery +- python.pipenv +- python.virtualenv +- mariadb-server +{{ create_celery_worker(gvaappname, purpose) }} + +{{ gvaappname }}-dependencies: + pkg.installed: + - pkgs: + - libmariadb-dev-compat + - require_in: + - cmd: {{ gvaappname }}-requirements + +python3-mysqldb: + pkg.installed + +# FIXME: this is broken due to https://github.com/saltstack/salt/issues/56124 +# require salt-call state.sls patch.mysql to be run on the minion before usage gvamysql-mysql-user: mysql_user.present: - - name: {{ salt['pillar.get']('gnuviechadmin:mysql_admin_user', 'gvamysql') }} + - name: {{ mysql_admin_user }} - host: '%' - - password: {{ salt['pillar.get']('gnuviechadmin:mysql_admin_password') }} + - password: {{ mysql_admin_password }} + - unix_socket: true + - require: + - pkg: python3-mysqldb gvamysql-grants-all-dbs: mysql_grants.present: - grant: ALL PRIVILEGES - database: '*.*' - grant_option: True - - user: {{ salt['pillar.get']('gnuviechadmin:mysql_admin_user', 'gvamysql') }} - - password: {{ salt['pillar.get']('gnuviechadmin:mysql_admin_password') }} + - user: {{ mysql_admin_user }} + - password: {{ mysql_admin_password }} - host: '%' - require: - mysql_user: gvamysql-mysql-user - -gvamysql-packages: - pkg.installed: - - pkgs: - - libmariadbd-dev - - libmysqlclient-dev - - require_in: - - pkg: gnuviechadmin-packages diff --git a/states/gnuviechadmin/gvamysql/celery-worker.env b/states/gnuviechadmin/gvamysql/celery-worker.env new file mode 100644 index 0000000..ae3b43c --- /dev/null +++ b/states/gnuviechadmin/gvamysql/celery-worker.env @@ -0,0 +1,6 @@ +GVAMYSQL_BROKER_URL='{{ broker_url }}' +GVAMYSQL_RESULTS_REDIS_URL="{{ result_url }}" +GVAMYSQL_DBADMIN_HOST="{{ salt['pillar.get']('gnuviechadmin:gvamysql:mysql_admin_host', 'localhost') }}" +GVAMYSQL_DBADMIN_PORT="{{ salt['pillar.get']('gnuviechadmin:gvamysql:mysql_admin_port', 3306) }}" +GVAMYSQL_DBADMIN_USER="{{ salt['pillar.get']('gnuviechadmin:gvamysql:mysql_admin_user', 'gvamysql') }}" +GVAMYSQL_DBADMIN_PASSWORD="{{ salt['pillar.get']('gnuviechadmin:gvamysql:mysql_admin_password') }}" diff --git a/states/gnuviechadmin/gvamysql/run_celery.sh b/states/gnuviechadmin/gvamysql/run_celery.sh deleted file mode 100644 index bc64add..0000000 --- a/states/gnuviechadmin/gvamysql/run_celery.sh +++ /dev/null @@ -1,12 +0,0 @@ -#!/bin/sh - -set -ex - -. {{ home }}/gvasettings.sh - -unset LANG LANGUAGE LC_CTYPE LC_NUMERIC LC_TIME LC_COLLATE LC_MONETARY \ - LC_MESSAGES LC_PAPER LC_NAME LC_ADDRESS LC_TELEPHONE LC_MEASUREMENT \ - LC_IDENTIFICATION LC_ALL - -cd {{ appdir }} -{{ virtualenv }}/bin/celery worker -A gvamysql -Q mysql --loglevel=INFO diff --git a/states/gnuviechadmin/gvamysql/settings.sh b/states/gnuviechadmin/gvamysql/settings.sh deleted file mode 100644 index 0056aea..0000000 --- a/states/gnuviechadmin/gvamysql/settings.sh +++ /dev/null @@ -1,8 +0,0 @@ -#!/bin/sh - -export GVAMYSQL_BROKER_URL='{{ broker_url }}' -export GVAMYSQL_RESULTS_REDIS_URL="redis://:{{ salt['pillar.get']('gnuviechadmin:redis_password') }}@{{ salt['pillar.get']('gnuviechadmin:redis_host') }}/0" -export GVAMYSQL_DBADMIN_HOST="{{ salt['pillar.get']('gnuviechadmin:mysql_admin_host', 'localhost') }}" -export GVAMYSQL_DBADMIN_PORT="{{ salt['pillar.get']('gnuviechadmin:mysql_admin_port', 3306) }}" -export GVAMYSQL_DBADMIN_USER="{{ salt['pillar.get']('gnuviechadmin:mysql_admin_user', 'gvamysql') }}" -export GVAMYSQL_DBADMIN_PASSWORD="{{ salt['pillar.get']('gnuviechadmin:mysql_admin_password') }}" diff --git a/states/patches/files/3000-mysql.diff b/states/patches/files/3000-mysql.diff new file mode 100644 index 0000000..3a0287c --- /dev/null +++ b/states/patches/files/3000-mysql.diff @@ -0,0 +1,13 @@ +diff --git a/salt/modules/mysql.py b/salt/modules/mysql.py +index 87e2361e28..37436206d4 100644 +--- a/salt/modules/mysql.py ++++ b/salt/modules/mysql.py +@@ -355,7 +355,7 @@ def _connect(**kwargs): + except IndexError: + return + val = __salt__['config.option']('mysql.{0}'.format(name), None) +- if val is not None: ++ if val != '': + connargs[key] = val + + # If a default file is explicitly passed to kwargs, don't grab the diff --git a/states/patches/mysql.sls b/states/patches/mysql.sls new file mode 100644 index 0000000..d75e4a0 --- /dev/null +++ b/states/patches/mysql.sls @@ -0,0 +1,19 @@ +{% if grains.saltversion == "3000" %} +patch: + pkg.installed + +mysql_module_patch: + file.patch: + - name: '{{ grains.saltpath }}' + - source: salt://patches/files/3000-mysql.diff + - strip: 2 + - require: + - pkg: patch + +restart_salt_minion: + cmd.run: + - name: 'salt-call service.restart salt-minion' + - bg: true + - onchanges: + - file: mysql_module_patch +{%- endif %}