Saltstack Official Galera Formula
Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

130 rindas
4.3KB

  1. {%- if pillar.get('mysql', {}).server is defined %}
  2. {%- from "mysql/map.jinja" import mysql_connection_args as connection with context %}
  3. {%- set server = pillar.mysql.server %}
  4. {%- for database_name, database in server.get('database', {}).iteritems() %}
  5. {%- if not grains.get('noservices', False) %}
  6. mysql_database_{{ database_name }}:
  7. mysql_database.present:
  8. - name: {{ database_name }}
  9. - character_set: {{ database.get('encoding', 'utf8') }}
  10. #- connection_user: {{ connection.user }}
  11. #- connection_pass: {{ connection.password }}
  12. #- connection_charset: {{ connection.charset }}
  13. {%- endif %}
  14. {%- for user in database.users %}
  15. {%- if not grains.get('noservices', False) %}
  16. mysql_user_{{ user.name }}_{{ database_name }}_{{ user.host }}:
  17. mysql_user.present:
  18. - host: '{{ user.host }}'
  19. - name: '{{ user.name }}'
  20. {%- if user.password is defined %}
  21. - password: {{ user.password }}
  22. {%- else %}
  23. - allow_passwordless: true
  24. {%- endif %}
  25. #- connection_user: {{ connection.user }}
  26. #- connection_pass: {{ connection.password }}
  27. #- connection_charset: {{ connection.charset }}
  28. mysql_grants_{{ user.name }}_{{ database_name }}_{{ user.host }}:
  29. mysql_grants.present:
  30. - grant: {{ user.rights }}
  31. - database: '{{ database_name }}.*'
  32. - user: '{{ user.name }}'
  33. - host: '{{ user.host }}'
  34. #- connection_user: {{ connection.user }}
  35. #- connection_pass: {{ connection.password }}
  36. #- connection_charset: {{ connection.charset }}
  37. - require:
  38. - mysql_user: mysql_user_{{ user.name }}_{{ database_name }}_{{ user.host }}
  39. - mysql_database: mysql_database_{{ database_name }}
  40. {%- endif %}
  41. {%- endfor %}
  42. {%- if database.initial_data is defined %}
  43. /root/mysql/scripts/restore_{{ database_name }}.sh:
  44. file.managed:
  45. - source: salt://mysql/conf/restore.sh
  46. - mode: 770
  47. - template: jinja
  48. - defaults:
  49. database_name: {{ database_name }}
  50. database: {{ database }}
  51. - require:
  52. - file: mysql_dirs
  53. - mysql_database: mysql_database_{{ database_name }}
  54. restore_mysql_database_{{ database_name }}:
  55. cmd.run:
  56. - name: /root/mysql/scripts/restore_{{ database_name }}.sh
  57. - unless: "[ -f /root/mysql/flags/{{ database_name }}-installed ]"
  58. - cwd: /root
  59. - require:
  60. - file: /root/mysql/scripts/restore_{{ database_name }}.sh
  61. {%- endif %}
  62. {%- endfor %}
  63. {%- for user in server.get('users', []) %}
  64. {%- for host in user.get('hosts', user.get('host', 'localhost'))|sequence %}
  65. {%- if not grains.get('noservices', False) %}
  66. mysql_user_{{ user.name }}_{{ host }}:
  67. mysql_user.present:
  68. - host: '{{ host }}'
  69. - name: '{{ user.name }}'
  70. {%- if user['password_hash'] is defined %}
  71. - password_hash: '{{ user.password_hash }}'
  72. {%- elif user['password'] is defined and user['password'] != None %}
  73. - password: '{{ user.password }}'
  74. {%- else %}
  75. - allow_passwordless: True
  76. {%- endif %}
  77. #- connection_user: {{ connection.user }}
  78. #- connection_pass: {{ connection.password }}
  79. #- connection_charset: {{ connection.charset }}
  80. {%- if 'grants' in user %}
  81. mysql_user_{{ user.name }}_{{ host }}_grants:
  82. mysql_grants.present:
  83. - name: {{ user.name }}
  84. - grant: {{ user['grants']|sequence|join(",") }}
  85. - database: '{{ user.get('database','*.*') }}'
  86. - grant_option: {{ user['grant_option'] | default(False) }}
  87. - user: {{ user.name }}
  88. - host: '{{ host }}'
  89. #- connection_user: {{ connection.user }}
  90. #- connection_pass: {{ connection.password }}
  91. #- connection_charset: {{ connection.charset }}
  92. - require:
  93. - mysql_user_{{ user.name }}_{{ host }}
  94. {%- endif %}
  95. {%- if 'databases' in user %}
  96. {%- for db in user['databases'] %}
  97. mysql_user_{{ user.name }}_{{ host }}_grants_db_{{ db.database }}_{{ loop.index0 }}:
  98. mysql_grants.present:
  99. - name: {{ user.name ~ '_' ~ db['database'] ~ '_' ~ db['table'] | default('all') }}
  100. - grant: {{ db['grants']|sequence|join(",") }}
  101. - database: '{{ db['database'] }}.{{ db['table'] | default('*') }}'
  102. - grant_option: {{ db['grant_option'] | default(False) }}
  103. - user: {{ user.name }}
  104. - host: '{{ host }}'
  105. #- connection_user: {{ connection.user }}
  106. #- connection_pass: {{ connection.password }}
  107. #- connection_charset: {{ connection.charset }}
  108. - require:
  109. - mysql_user_{{ user.name }}_{{ host }}
  110. - mysql_database_{{ db.database }}
  111. {%- endfor %}
  112. {%- endif %}
  113. {%- endif %}
  114. {%- endfor %}
  115. {%- endfor %}
  116. {%- endif %}