Merge pull request #14 from ninjix/master

Added support for MySQL hashed user password.
This commit is contained in:
Seth House 2014-05-15 15:49:23 -06:00
commit 608e090370
5 changed files with 27 additions and 14 deletions

View file

@ -28,11 +28,19 @@ Install the MySQL server package and start the service.
Debian OS family supports setting MySQL root password during install via debconf. Debian OS family supports setting MySQL root password during install via debconf.
``mysql.database`` ``mysql.database``
---------------- ------------------
Create and manage MySQL databases. Create and manage MySQL databases.
``mysql.user`` ``mysql.user``
---------------- ----------------
Create and manage MySQL database users with definable GRANT privileges. Create and manage MySQL database users with definable GRANT privileges.
The state accepts MySQL hashed passwords or clear text. Hashed password have priority.
.. note::
See the `salt.states.mysql_user <http://docs.saltstack.com/en/latest/ref/states/all/salt.states.mysql_user.html#module-salt.states.mysql_user>`_ docs for additional information on configuring hashed passwords.
Make sure to **quote the passwords** in the pillar so YAML doesn't throw an exception.

View file

@ -1,11 +1,14 @@
{% from "mysql/map.jinja" import mysql with context %} {% from "mysql/map.jinja" import mysql with context %}
include:
- mysql.python
{% for database in salt['pillar.get']('mysql:database', []) %} {% for database in salt['pillar.get']('mysql:database', []) %}
{{ database }}: {{ database }}:
mysql_database.present: mysql_database.present:
- host: localhost - host: localhost
- connection_user: root - connection_user: root
- connection_pass: {{ salt['pillar.get']('mysql:server:root_password', 'somepass') }} - connection_pass: '{{ salt['pillar.get']('mysql:server:root_password', 'somepass') }}'
- connection_charset: utf8 - connection_charset: utf8
{% endfor %} {% endfor %}

View file

@ -50,11 +50,6 @@ mysqld:
- watch: - watch:
- pkg: mysqld - pkg: mysqld
mysql-python:
pkg:
- installed
- name: {{ mysql.python }}
{% if grains['os'] in ['Ubuntu', 'Debian', 'Gentoo', 'CentOS'] %} {% if grains['os'] in ['Ubuntu', 'Debian', 'Gentoo', 'CentOS'] %}
my.cnf: my.cnf:
file.managed: file.managed:

View file

@ -1,13 +1,20 @@
{% from "mysql/map.jinja" import mysql with context %} {% from "mysql/map.jinja" import mysql with context %}
include:
- mysql.python
{% for user in salt['pillar.get']('mysql:user', []) %} {% for user in salt['pillar.get']('mysql:user', []) %}
{{ user['name'] }}: {{ user['name'] }}:
mysql_user.present: mysql_user.present:
- host: {{ user['host'] }} - host: {{ user['host'] }}
- password: {{ user['password'] }} {%- if user['password_hash'] is defined %}
- password_hash: '{{ user['password_hash'] }}'
{% else %}
- password: '{{ user['password'] }}'
{% endif %}
- connection_host: localhost - connection_host: localhost
- connection_user: root - connection_user: root
- connection_pass: {{ salt['pillar.get']('mysql:server:root_password', 'somepass') }} - connection_pass: '{{ salt['pillar.get']('mysql:server:root_password', 'somepass') }}'
- connection_charset: utf8 - connection_charset: utf8
{% for db in user['databases'] %} {% for db in user['databases'] %}
@ -19,7 +26,7 @@
- host: {{ user['host'] }} - host: {{ user['host'] }}
- connection_host: localhost - connection_host: localhost
- connection_user: root - connection_user: root
- connection_pass: {{ salt['pillar.get']('mysql:server:root_password', 'somepass') }} - connection_pass: '{{ salt['pillar.get']('mysql:server:root_password', 'somepass') }}'
- connection_charset: utf8 - connection_charset: utf8
- require: - require:
- mysql_user: {{ user['name'] }} - mysql_user: {{ user['name'] }}

View file

@ -1,6 +1,6 @@
mysql: mysql:
server: server:
root_password: somepass root_password: 'somepass'
bind-address: 127.0.0.1 bind-address: 127.0.0.1
port: 3306 port: 3306
user: mysql user: mysql
@ -13,7 +13,7 @@ mysql:
# Manage users # Manage users
user: user:
- name: frank - name: frank
password: somepass password: 'somepass'
host: localhost host: localhost
databases: databases:
- database: foo - database: foo
@ -21,7 +21,7 @@ mysql:
- database: bar - database: bar
grants: ['all privileges'] grants: ['all privileges']
- name: bob - name: bob
password: someotherpass password_hash: '*6C8989366EAF75BB670AD8EA7A7FC1176A95CEF4'
host: localhost host: localhost
databases: databases:
- database: foo - database: foo