Page Menu
Home
DevCentral
Search
Configure Global Search
Log In
Files
F3778240
D2987.id7624.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
5 KB
Referenced Files
None
Subscribers
None
D2987.id7624.diff
View Options
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,19 @@
+dbserver_mysql_aliases:
+ - &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
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,64 @@
+#!/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 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
Details
Attached
Mime Type
text/plain
Expires
Tue, Nov 26, 04:21 (18 h, 49 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
2263934
Default Alt Text
D2987.id7624.diff (5 KB)
Attached To
Mode
D2987: Provision users and databases on devserver-mysql role
Attached
Detach File
Event Timeline
Log In to Comment