Skip to content

Instantly share code, notes, and snippets.

@thecodeassassin
Created August 30, 2013 09:50
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 thecodeassassin/8d8f2df0f3870e41cb0d to your computer and use it in GitHub Desktop.
Save thecodeassassin/8d8f2df0f3870e41cb0d to your computer and use it in GitHub Desktop.
db-user:
service:
- name: mysql
- running
- enable: True
- reload: True
- require:
- sls: database
# create all the required users
{% for user in pillar.get('database-users')}
mysql_user.present:
- name: {{ user["name"] }}
- password: {{ user["password"] }}
- allow_passwordless: False
- host: 'localhost'
- connection_user: root
- connection_pass: {{ pillar["root_password"] }}
- require:
- service: mysql
- sls: database
- mysql_user.present: root
# create all the databases for the given users
{% for database in user["databases"] %}
mysql_database.present:
- name: {{ database }}
- require: mysql_user.present: {{ user["name"] }}
mysql_grants.present:
- grant: 'ALL PRIVILEGES'
- database: {{ database }}
- host: '%'
- grant_option: False
- user: {{ user["name"] }}
- connection_user: root
- connection_pass: {{ pillar["root_password"] }}
- require:
- mysql_database.present: {{ database }}
- sls: database
{% endfor }
{% endfor %}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment