Skip to content

Instantly share code, notes, and snippets.

@metalrufflez
Last active August 29, 2015 14:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save metalrufflez/c4c6da9deafc2b31668c to your computer and use it in GitHub Desktop.
Save metalrufflez/c4c6da9deafc2b31668c to your computer and use it in GitHub Desktop.
Create Database Users
include:
- salt.mysql
{% for db, db_details in pillar.get('db_config', {}).items() %}
{{ db }}_database:
mysql_database.present:
- name: {{ db }}
{% for user, user_details in db_details['users'].items() %}
{{ user }}_user_in_{{ db }}:
mysql_user.present:
- name: {{ user }}
- host: '{{ user_details['host'] }}'
- password: {{ user_details['pass'] }}
{% for grant, grant_details in user_details['grants'].items() %}
{{ grant }}_grant_for_{{ user }}_in_{{ db }}:
mysql_grants.present:
- user: {{ user }}
- host: '{{ user_details['host'] }}'
- grant: {{ grant_details['grant'] }}
- database: '{{ db }}.{{ grant_details['table'] }}'
- require:
- mysql_database: {{ db }}
- mysql_user: {{ user }}
{% endfor %}
{% endfor %}
{% endfor %}
{% set app_name = "api" %}
db_config:
{{ app_name }}:
users:
{{ app_name }}_{{ grains['env'] }}:
host: '%'
pass: '$;B}ia=,2_'
grants:
all_on_all:
grant: all privileges
table: '*'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment