Merge pull request #41 from Cottser/user-dict

Use a dict instead of a list for users
This commit is contained in:
Nitin Madhok 2014-11-02 01:33:15 -04:00
commit d0cfc8fa7d
3 changed files with 10 additions and 10 deletions

View file

@ -56,7 +56,7 @@ for user in users:
""" PRINT EXAMPLE """ PRINT EXAMPLE
mysql: mysql:
user: user:
- name: user username:
host: host host: host
password_hash: '*2792A97371B2D17789364A22A9B35D180166571A' password_hash: '*2792A97371B2D17789364A22A9B35D180166571A'
databases: databases:
@ -67,7 +67,7 @@ mysql:
print "mysql:" print "mysql:"
print " user:" print " user:"
for user in users: for user in users:
print " - name: %s" % user['name'] print " %s:" % user['name']
print " host: '%s'" % user['host'] print " host: '%s'" % user['host']
if ('password' in user): if ('password' in user):
print " password_hash: '%s'" % user['password'] print " password_hash: '%s'" % user['password']

View file

@ -7,11 +7,11 @@
include: include:
- mysql.python - mysql.python
{% for user in salt['pillar.get']('mysql:user', []) %} {% for name, user in salt['pillar.get']('mysql:user', {}).items() %}
{% set state_id = 'mysql_user_' ~ loop.index0 %} {% set state_id = 'mysql_user_' ~ loop.index0 %}
{{ state_id }}: {{ state_id }}:
mysql_user.present: mysql_user.present:
- name: {{ user['name'] }} - name: {{ name }}
- host: '{{ user['host'] }}' - host: '{{ user['host'] }}'
{%- if user['password_hash'] is defined %} {%- if user['password_hash'] is defined %}
- password_hash: '{{ user['password_hash'] }}' - password_hash: '{{ user['password_hash'] }}'
@ -30,11 +30,11 @@ include:
{% for db in user['databases'] %} {% for db in user['databases'] %}
{{ state_id ~ '_' ~ loop.index0 }}: {{ state_id ~ '_' ~ loop.index0 }}:
mysql_grants.present: mysql_grants.present:
- name: {{ user['name'] ~ '_' ~ db['database'] ~ '_' ~ db['table'] | default('all') }} - name: {{ name ~ '_' ~ db['database'] ~ '_' ~ db['table'] | default('all') }}
- grant: {{db['grants']|join(",")}} - grant: {{db['grants']|join(",")}}
- 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: {{ user['name'] }} - user: {{ name }}
- host: '{{ user['host'] }}' - host: '{{ user['host'] }}'
- connection_host: localhost - connection_host: localhost
- connection_user: root - connection_user: root
@ -43,7 +43,7 @@ include:
{% endif %} {% endif %}
- connection_charset: utf8 - connection_charset: utf8
- require: - require:
- mysql_user: {{ user['name'] }} - mysql_user: {{ name }}
{% endfor %} {% endfor %}
{% do user_states.append(state_id) %} {% do user_states.append(state_id) %}

View file

@ -29,7 +29,7 @@ mysql:
# Manage users # Manage users
# you can get pillar for existent server using import_users.py script # you can get pillar for existent server using import_users.py script
user: user:
- name: frank frank:
password: 'somepass' password: 'somepass'
host: localhost host: localhost
databases: databases:
@ -37,7 +37,7 @@ mysql:
grants: ['select', 'insert', 'update'] grants: ['select', 'insert', 'update']
- database: bar - database: bar
grants: ['all privileges'] grants: ['all privileges']
- name: bob bob:
password_hash: '*6C8989366EAF75BB670AD8EA7A7FC1176A95CEF4' password_hash: '*6C8989366EAF75BB670AD8EA7A7FC1176A95CEF4'
host: localhost host: localhost
databases: databases:
@ -47,7 +47,7 @@ mysql:
- database: bar - database: bar
table: foobar table: foobar
grants: ['select', 'insert', 'update', 'delete'] grants: ['select', 'insert', 'update', 'delete']
- name: nopassuser nopassuser:
password: ~ password: ~
host: localhost host: localhost
databases: [] databases: []