- query: "UPDATE mysql.user SET Password=PASSWORD('{%- include 'secure/passwords/root_db_password.txt' -%}') WHERE User='root';FLUSH PRIVILEGES;"
- onchanges:
- cmd: initialize_mysql
secure_mysql:
mysql_query.run:
- database: mysql
- query: "DELETE FROM mysql.user WHERE User='';DELETE FROM mysql.user WHERE User='root' AND Host NOT IN ('localhost', '127.0.0.1', '::1');DROP DATABASE IF EXISTS test;DELETE FROM mysql.db WHERE Db='test' OR Db='test\\_%';FLUSH PRIVILEGES;"
- connection_user: root
- connection_pass: "{%- include 'secure/passwords/root_db_password.txt' -%}"
#create salt db user
user_salt:
mysql_user.present:
- name: salt
- host: "localhost"
- password: "{%- include 'secure/passwords/salt_db_password.txt' -%}"
- connection_user: root
- connection_pass: "{%- include 'secure/passwords/root_db_password.txt' -%}"
grant_salt:
mysql_grants.present:
- grant: all privileges
- database: "*.*"
- user: salt
- host: "localhost"
- grant_option: true
- revoke_first: true
- connection_user: root
- connection_pass: "{%- include 'secure/passwords/root_db_password.txt' -%}"
{##ensure that database pillar exists##}
{%- if pillar['database'] is defined -%}
{%- if pillar['database']['users'] is defined -%}
{%- for user in pillar['database']['users'] %}
user_{{user}}:
mysql_user.present:
- name: {{user}}
{%- if pillar['database']['users'][user]['host'] is defined %}