Page MenuHomeDevCentral

D2987.id7631.diff
No OneTemporary

D2987.id7631.diff

diff --git a/pillar/credentials/vault.sls b/pillar/credentials/vault.sls
--- a/pillar/credentials/vault.sls
+++ b/pillar/credentials/vault.sls
@@ -222,3 +222,7 @@
# Main PostgreSQL cluster
A:
- ops/secrets/dbserver/cluster-A/users/*
+
+ # Main MariaDB cluster - Alkane PaaS, ViperServ
+ B:
+ - ops/secrets/dbserver/cluster-B/users/*
diff --git a/pillar/dbserver/cluster-B.sls b/pillar/dbserver/cluster-B.sls
new file mode 100644
--- /dev/null
+++ b/pillar/dbserver/cluster-B.sls
@@ -0,0 +1,36 @@
+dbserver_mysql_aliases:
+ hosts:
+ - &viperserv 172.27.27.33
+
+dbserver_mysql:
+
+ server:
+ salt:
+ # Account used by Salt to configure the server
+ credentials: dbserver/cluster-B/users/salt
+
+ users:
+ # Password paths are relative to ops/secrets
+
+ nasqueron:
+ password: dbserver/cluster-B/users/nasqueron
+ host: *viperserv
+ privileges:
+ - database: Nasqueron
+ scope: database
+
+ # Tips for databases:
+ # This is a MariaDB cluster. At version 10.6, MariaDB is still using utf8mb3
+ # by default, but we generally prefer utf8mb4 as encoding.
+ #
+ # For collation, MySQL 8 uses utf8mb4_0900_ai_ci / utf8mb4_0900_as_cs
+ # It's a accent (in)sensitive case (in)sensitive based on Unicode 9.0.
+ # For MariaDB 10.10+, we can use uca1400_as_ci, that's Unicode 14.0.
+ #
+ # TRANSITION NOTE. On MariaDB 10.6, utf8mb4_unicode_520_ci is the "newest".
+
+ databases:
+ # Database used by IRC eggdrops
+ Nasqueron: &unicode
+ encoding: utf8mb4
+ collation: utf8mb4_unicode_520_ci
diff --git a/roles/dbserver-mysql/init.sls b/roles/dbserver-mysql/init.sls
--- a/roles/dbserver-mysql/init.sls
+++ b/roles/dbserver-mysql/init.sls
@@ -10,3 +10,4 @@
- .mysql-server
- .grc
- .treasure-chest
+ - .salt
diff --git a/roles/dbserver-mysql/salt/files/dbserver_mysql_salt_credentials.py b/roles/dbserver-mysql/salt/files/dbserver_mysql_salt_credentials.py
new file mode 100644
--- /dev/null
+++ b/roles/dbserver-mysql/salt/files/dbserver_mysql_salt_credentials.py
@@ -0,0 +1,65 @@
+#!/usr/bin/env python3
+
+# -------------------------------------------------------------
+# Salt - configuration
+# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
+# Project: Nasqueron
+# License: Trivial work, not eligible to copyright
+# Source file: roles/dbserver-mysql/salt/files/dbserver_mysql_salt_credentials.py
+# -------------------------------------------------------------
+#
+# <auto-generated>
+# This file is managed by our rOPS SaltStack repository.
+#
+# Changes to this file may cause incorrect behavior
+# and will be lost if the state is redeployed.
+# </auto-generated>
+
+
+import os
+import sys
+import yaml
+
+
+def read_config(config_path):
+ with open(config_path) as fd:
+ return yaml.safe_load(fd)
+
+
+def prepare_query(query, config):
+ query = query.replace("%%username%%", config["mysql"]["username"])
+ query = query.replace("%%password%%", config["mysql"]["password"])
+ return query
+
+
+def run_query(query, config):
+ query = prepare_query(query, config)
+ with open(".query", "w") as fd:
+ fd.write(query)
+ run("mysql < .query", shell=True)
+ os.remove(".query")
+
+
+def provision_account(config):
+ query = (
+ "CREATE OR REPLACE USER %%username%%@localhost IDENTIFIED BY '%%password%%';"
+ )
+ run_query(query, config)
+
+ query = "GRANT ALL PRIVILEGES ON *.* TO '%%username%%'@'localhost';"
+ run_query(query, config)
+
+
+def run(config_path):
+ config = read_config(config_path)
+ provision_account(config)
+
+
+if __name__ == "__main__":
+ argc = len(sys.argv)
+
+ if argc < 2:
+ print(f"Usage: {sys.argv[0]} <configuration path>", file=sys.stderr)
+ sys.exit(1)
+
+ run(sys.argv[1])
diff --git a/roles/dbserver-mysql/salt/files/mysql.conf b/roles/dbserver-mysql/salt/files/mysql.conf
new file mode 100644
--- /dev/null
+++ b/roles/dbserver-mysql/salt/files/mysql.conf
@@ -0,0 +1,23 @@
+# -------------------------------------------------------------
+# Salt - configuration
+# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
+# Project: Nasqueron
+# License: Trivial work, not eligible to copyright
+# Source file: roles/dbserver-mysql/salt/files/mysql.conf
+# -------------------------------------------------------------
+#
+# <auto-generated>
+# This file is managed by our rOPS SaltStack repository.
+#
+# Changes to this file may cause incorrect behavior
+# and will be lost if the state is redeployed.
+# </auto-generated>
+
+mysql:
+ host: 'localhost'
+ port: 3306
+ user: '{{ secret["username"] }}'
+ pass: '{{ secret["password"] }}'
+ db: 'mysql'
+ unix_socket: '/var/run/mysql/mysqld.sock'
+ charset: 'utf8mb4'
diff --git a/roles/dbserver-mysql/salt/init.sls b/roles/dbserver-mysql/salt/init.sls
new file mode 100644
--- /dev/null
+++ b/roles/dbserver-mysql/salt/init.sls
@@ -0,0 +1,41 @@
+# -------------------------------------------------------------
+# Salt — Database server — MySQL
+# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
+# Project: Nasqueron
+# License: Trivial work, not eligible to copyright
+# -------------------------------------------------------------
+
+{% from "map.jinja" import dirs, packages_prefixes with context %}
+
+# -------------------------------------------------------------
+# Required software
+# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
+
+{{ packages_prefixes.python3 }}pymysql
+ pkg.installed:
+ - reload_modules: true
+
+# -------------------------------------------------------------
+# Salt node configuration file
+# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
+
+{% set salt_credential = salt["pillar.get"]("dbserver_mysql:server:salt:credentials") %}
+
+{{ dirs.etc }}/salt/minion.d/mysql:
+ file.managed:
+ - source: salt://roles/dbserver-mysql/salt/files/mysql.conf
+ - user: root
+ - mode: 400
+ - template: jinja
+ - context:
+ secret: {{ salt["credentials.read_secret"](salt_credential) }}
+
+# -------------------------------------------------------------
+# Provision Salt credentials
+# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
+
+dbserver_mysql_salt_credentials:
+ cmd.script:
+ - source: salt://roles/dbserver-mysql/salt/files/dbserver_mysql_salt_credentials.py
+ - onchanges:
+ - file: {{ dirs.etc }}/salt/minion.d/mysql

File Metadata

Mime Type
text/plain
Expires
Tue, Nov 26, 04:24 (18 h, 57 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
2263890
Default Alt Text
D2987.id7631.diff (6 KB)

Event Timeline