forked from saltstack-formulas/mysql-formula
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
probably also apply to saltstack-formulas#104, saltstack-formulas#106
- Loading branch information
1 parent
4d6d3df
commit d629e87
Showing
8 changed files
with
109 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
*.pyc | ||
*.swp | ||
*~ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
# vim: set ft=jinja: | ||
# | ||
# Mysql - MariaDB formula for changing root password. | ||
# | ||
# Note: as root password is required to changed root password for mysql | ||
# (without restarting the server with --skip-grant-tables) this formula require .my.cnf | ||
# See: root_my_cnf.sls | ||
# Other magical case are not handled. | ||
# | ||
# The previous password must be stored in ~/.my.cnf (even empty) | ||
# See: root_my_cnf.sls | ||
|
||
# TODO: DRY this bloc in a common file for every state | ||
{% from "mysql/defaults.yaml" import rawmap with context %} | ||
{%- set mysql = salt['grains.filter_by'](rawmap, grain='os', merge=salt['pillar.get']('mysql:lookup')) %} | ||
{% set os = salt['grains.get']('os', None) %} | ||
{% set os_family = salt['grains.get']('os_family', None) %} | ||
{% set mysql_root_user = salt['pillar.get']('mysql:server:root_user', 'root') %} | ||
{% set mysql_root_password = salt['pillar.get']('mysql:server:root_password', salt['grains.get']('server_id')) %} | ||
{% set mysql_host = salt['pillar.get']('mysql:server:host', 'localhost') %} | ||
{% set mysql_salt_user = salt['pillar.get']('mysql:salt_user:salt_user_name', mysql_root_user) %} | ||
{% set mysql_salt_password = salt['pillar.get']('mysql:salt_user:salt_user_password', mysql_root_password) %} | ||
|
||
# DONT do fancy password with double quote, nor starting or ending with space | ||
{% set escaped_root_pass = mysql_root_password|replace("'", "''") %} | ||
{% set my_cnf = '/root/.my.cnf' %} | ||
|
||
# WARNING: no double quote in the query | ||
{% set query = """ | ||
UPDATE user SET password = password('" ~ escaped_root_pass ~ "') WHERE user = 'root'; | ||
FLUSH PRIVILEGES; | ||
""" %} | ||
change_all_root_pass: | ||
cmd.run: | ||
- name: mysql --defaults-file={{ my_cnf }} -e "{{ query|replace("\n", '') }}" mysql | ||
- unless: grep -q "\<{{ escaped_root_pass }}$" {{ my_cnf }} | ||
- require_in: | ||
- file: mysql_root_my_cnf | ||
|
||
# recreate /root/.my.cnf | ||
include: | ||
- mysql.root_my_cnf |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
# This create a passwordless access for root | ||
mysql_root_my_cnf: | ||
file.managed: | ||
- name: /root/.my.cnf | ||
- source: salt://mysql/files/root-my.cnf | ||
- template: jinja | ||
- user: root | ||
- group: root | ||
- mode: 600 | ||
- create: True |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
# | ||
# This create a passwordless access for root | ||
# See: https://github.com/saltstack-formulas/mysql-formula/issues/120 for discussion about security | ||
# | ||
# | ||
# Usage: salt-call mysql.root_my_cnf | ||
|
||
mysql_root_my_cnf: | ||
file.managed: | ||
- name: /root/.my.cnf | ||
- source: salt://mysql/files/root-my.cnf | ||
- template: jinja | ||
- user: root | ||
- group: root | ||
- mode: 600 | ||
- create: True | ||
|
||
# This use above config file to store mysql's root password for salt | ||
mysql_minion_root_my_cnf: | ||
file.managed: | ||
- name: /etc/salt/minion.d/55-mysql-cnf.conf | ||
# use quote for the content | ||
- contents: | ||
- "mysql.default_file: '/root/.my.cnf'" | ||
- user: root | ||
- group: root | ||
- mode: 600 | ||
- create: True | ||
- require: | ||
- file: mysql_root_my_cnf |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters