Saltstack Official Galera Formula
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

70 lines
1.8KB

  1. {%- if pillar.get('mysql', {}).server is defined %}
  2. {%- set server = pillar.mysql.server %}
  3. {%- for database_name, database in server.get('database', {}).iteritems() %}
  4. mysql_database_{{ database_name }}:
  5. mysql_database.present:
  6. - name: {{ database_name }}
  7. {%- for user in database.users %}
  8. mysql_user_{{ user.name }}_{{ database_name }}_{{ user.host }}:
  9. mysql_user.present:
  10. - host: '{{ user.host }}'
  11. - name: '{{ user.name }}'
  12. - password: {{ user.password }}
  13. mysql_grants_{{ user.name }}_{{ database_name }}_{{ user.host }}:
  14. mysql_grants.present:
  15. - grant: {{ user.rights }}
  16. - database: '{{ database_name }}.*'
  17. - user: '{{ user.name }}'
  18. - host: '{{ user.host }}'
  19. - require:
  20. - mysql_user: mysql_user_{{ user.name }}_{{ database_name }}_{{ user.host }}
  21. - mysql_database: mysql_database_{{ database_name }}
  22. {%- endfor %}
  23. {%- if database.initial_data is defined %}
  24. /root/mysql/scripts/restore_{{ database_name }}.sh:
  25. file.managed:
  26. - source: salt://mysql/conf/restore.sh
  27. - mode: 770
  28. - template: jinja
  29. - defaults:
  30. database_name: {{ database_name }}
  31. - require:
  32. - file: mysql_dirs
  33. - mysql_database: mysql_database_{{ database_name }}
  34. restore_mysql_database_{{ database_name }}:
  35. cmd.run:
  36. - name: /root/mysql/scripts/restore_{{ database_name }}.sh
  37. - unless: "[ -f /root/mysql/flags/{{ database_name }}-installed ]"
  38. - cwd: /root
  39. - require:
  40. - file: /root/mysql/scripts/restore_{{ database_name }}.sh
  41. {%- endif %}
  42. {%- endfor %}
  43. {%- for user in server.get('users', []) %}
  44. mysql_user_{{ user.name }}_{{ user.host }}:
  45. mysql_user.present:
  46. - host: '{{ user.host }}'
  47. - name: '{{ user.name }}'
  48. {%- if user.password is defined %}
  49. - password: {{ user.password }}
  50. {%- else %}
  51. - allow_passwordless: True
  52. {%- endif %}
  53. {%- endfor %}
  54. {%- endif %}