Skip to content
Snippets Groups Projects
Commit 26e634cd authored by Vincent Schumaker's avatar Vincent Schumaker
Browse files

Add the ability to specify user pillar data in the form of either

  mysql:user:host

  or

  mysql:user:hosts

If mysql:user:hosts is used, an account for each 'user'@'host' combo
will be created with the specified grants

This fixes #49
parent 8d89326f
No related branches found
No related tags found
No related merge requests found
...@@ -3,16 +3,27 @@ ...@@ -3,16 +3,27 @@
{%- set mysql_root_pass = salt['pillar.get']('mysql:server:root_password', 'somepass') %} {%- set mysql_root_pass = salt['pillar.get']('mysql:server:root_password', 'somepass') %}
{% set user_states = [] %} {% set user_states = [] %}
{% set user_hosts = [] %}
include: include:
- mysql.python - mysql.python
{% for name, user in salt['pillar.get']('mysql:user', {}).items() %} {% for name, user in salt['pillar.get']('mysql:user', {}).items() %}
{% set state_id = 'mysql_user_' ~ loop.index0 %}
{% set user_host = salt['pillar.get']('mysql:user:%s:host'|format(name)) %}
{% if user_host != '' %}
{% set user_hosts = [user_host] %}
{% else %}
{% set user_hosts = salt['pillar.get']('mysql:user:%s:hosts'|format(name)) %}
{% endif %}
{% for host in user_hosts %}
{% set state_id = 'mysql_user_' ~ name ~ '_' ~ host%}
{{ state_id }}: {{ state_id }}:
mysql_user.present: mysql_user.present:
- name: {{ name }} - name: {{ name }}
- host: '{{ user['host'] }}' - host: '{{ host }}'
{%- if user['password_hash'] is defined %} {%- if user['password_hash'] is defined %}
- password_hash: '{{ user['password_hash'] }}' - password_hash: '{{ user['password_hash'] }}'
{%- elif user['password'] is defined and user['password'] != None %} {%- elif user['password'] is defined and user['password'] != None %}
...@@ -35,7 +46,7 @@ include: ...@@ -35,7 +46,7 @@ include:
- database: '{{ db['database'] }}.{{ db['table'] | default('*') }}' - database: '{{ db['database'] }}.{{ db['table'] | default('*') }}'
- grant_option: {{ db['grant_option'] | default(False) }} - grant_option: {{ db['grant_option'] | default(False) }}
- user: {{ name }} - user: {{ name }}
- host: '{{ user['host'] }}' - host: '{{ host }}'
- connection_host: localhost - connection_host: localhost
- connection_user: root - connection_user: root
{% if mysql_root_pass -%} {% if mysql_root_pass -%}
...@@ -48,3 +59,4 @@ include: ...@@ -48,3 +59,4 @@ include:
{% do user_states.append(state_id) %} {% do user_states.append(state_id) %}
{% endfor %} {% endfor %}
{% endfor %}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment