Преглед на файлове

Additional users

feature/additional_users
Petr Michalec преди 7 години
родител
ревизия
bca6ffa727
No account linked to committer's email address
променени са 3 файла, в които са добавени 82 реда и са изтрити 5 реда
  1. +24
    -0
      README.rst
  2. +42
    -5
      galera/server.sls
  3. +16
    -0
      tests/pillar/master_cluster.sls

+ 24
- 0
README.rst Целия файл

@@ -56,6 +56,30 @@ Galera cluster slave node
user: root
password: pass


Additional mysql users:

.. code-block:: yaml

mysql:
server:
users:
- name: clustercheck
password: clustercheck
database: '*.*'
grants: PROCESS
grant_option: False
- name: inspector
host: 127.0.0.1
password: password
databases:
mydb:
- database: mydb
- table: mytable
- grant_option: False
- grants:
- all privileges

Usage
=====


+ 42
- 5
galera/server.sls Целия файл

@@ -56,17 +56,54 @@ restore_mysql_database_{{ database_name }}:

{%- if not grains.get('noservices', False) %}
{%- for user in server.get('users', []) %}

mysql_user_{{ user.name }}_{{ user.host }}:
{%- set user_hosts = user.get('hosts', user.get('host', 'localhost'))|sequence %}
{%- for host in user_hosts %}
mysql_user_{{ user.name }}_{{ host }}:
mysql_user.present:
- host: '{{ user.host }}'
- name: '{{ user.name }}'
{%- if user.password is defined %}
- password: {{ user.password }}
{%- if user['password_hash'] is defined %}
- password_hash: '{{ user.password_hash }}'
{%- elif user['password'] is defined and user['password'] != None %}
- password: '{{ user.password }}'
{%- else %}
- allow_passwordless: True
{%- endif %}
- connection_charset: utf8

{%- if 'grants' in user %}
mysql_user_{{ user.name }}_{{ host }}_grants:
mysql_grants.present:
- name: {{ user.name }}
- grant: {{ user['grants']|sequence|join(",") }}
- database: '*.*'
- grant_option: {{ user['grant_option'] | default(False) }}
- user: {{ user.name }}
- host: '{{ host }}'
- connection_charset: utf8
- require:
- mysql_user_{{ user.name }}_{{ host }}
{%- endif %}

{%- if 'databases' in user %}
{% for db in user['databases'] %}
mysql_user_{{ user.name }}_{{ host }}_grants_db_{{ db }} ~ '_' ~ loop.index0:
mysql_grants.present:
- name: {{ user.name ~ '_' ~ db['database'] ~ '_' ~ db['table'] | default('all') }}
- grant: {{db['grants']|sequence|join(",")}}
- database: '{{ db['database'] }}.{{ db['table'] | default('*') }}'
- grant_option: {{ db['grant_option'] | default(False) }}
- user: {{ user.name }}
- host: '{{ host }}'
- connection_charset: utf8
- require:
- mysql_user_{{ user.name }}_{{ host }}
- mysql_database_{{ db }}
{%- endfor %}
{%- endif %}

{%- endfor %}
{%- endfor %}

{%- endif %}
{%- endif %}
{%- endif %}

+ 16
- 0
tests/pillar/master_cluster.sls Целия файл

@@ -25,3 +25,19 @@
host: '%'
- name: haproxy
host: 127.0.0.1
- name: clustercheck
#host: localhost
password: clustercheck
database: '*.*'
grants: PROCESS
grant_option: False
- name: inspector
host: 127.0.0.1
password: password
databases:
mydb:
- database: mydb
- table: mytable
- grant_option: False
- grants:
- all privileges

Loading…
Отказ
Запис