mirror of
https://github.com/saltstack-formulas/mysql-formula.git
synced 2025-04-15 17:20:25 +00:00
Merge pull request #55 from vschum/multiple-hosts-per-user
Add the ability to specify user pillar data in the form of either
This commit is contained in:
commit
22b53e4e44
1 changed files with 15 additions and 3 deletions
|
@ -3,16 +3,27 @@
|
|||
{%- set mysql_root_pass = salt['pillar.get']('mysql:server:root_password', 'somepass') %}
|
||||
|
||||
{% set user_states = [] %}
|
||||
{% set user_hosts = [] %}
|
||||
|
||||
include:
|
||||
- mysql.python
|
||||
|
||||
{% 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 }}:
|
||||
mysql_user.present:
|
||||
- name: {{ name }}
|
||||
- host: '{{ user['host'] }}'
|
||||
- host: '{{ host }}'
|
||||
{%- if user['password_hash'] is defined %}
|
||||
- password_hash: '{{ user['password_hash'] }}'
|
||||
{%- elif user['password'] is defined and user['password'] != None %}
|
||||
|
@ -35,7 +46,7 @@ include:
|
|||
- database: '{{ db['database'] }}.{{ db['table'] | default('*') }}'
|
||||
- grant_option: {{ db['grant_option'] | default(False) }}
|
||||
- user: {{ name }}
|
||||
- host: '{{ user['host'] }}'
|
||||
- host: '{{ host }}'
|
||||
- connection_host: localhost
|
||||
- connection_user: root
|
||||
{% if mysql_root_pass -%}
|
||||
|
@ -48,3 +59,4 @@ include:
|
|||
|
||||
{% do user_states.append(state_id) %}
|
||||
{% endfor %}
|
||||
{% endfor %}
|
||||
|
|
Loading…
Add table
Reference in a new issue