Saltstack Official Galera Formula
您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

142 行
4.7KB

  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. mysql_database_{{ database_name }}:
  6. mysql_database.present:
  7. - name: {{ database_name }}
  8. - character_set: {{ database.get('encoding', 'utf8') }}
  9. #- connection_user: {{ connection.user }}
  10. #- connection_pass: {{ connection.password }}
  11. #- connection_charset: {{ connection.charset }}
  12. {%- if grains.get('noservices') %}
  13. - onlyif: /bin/false
  14. {%- endif %}
  15. {%- for user in database.get('users', {}) %}
  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. {%- if grains.get('noservices') %}
  29. - onlyif: /bin/false
  30. {%- endif %}
  31. mysql_grants_{{ user.name }}_{{ database_name }}_{{ user.host }}:
  32. mysql_grants.present:
  33. - grant: {{ user.rights }}
  34. - database: '{{ database_name }}.*'
  35. - user: '{{ user.name }}'
  36. - host: '{{ user.host }}'
  37. #- connection_user: {{ connection.user }}
  38. #- connection_pass: {{ connection.password }}
  39. #- connection_charset: {{ connection.charset }}
  40. - require:
  41. - mysql_user: mysql_user_{{ user.name }}_{{ database_name }}_{{ user.host }}
  42. - mysql_database: mysql_database_{{ database_name }}
  43. {%- if grains.get('noservices') %}
  44. - onlyif: /bin/false
  45. {%- endif %}
  46. {%- endfor %}
  47. {%- if database.initial_data is defined %}
  48. /root/mysql/scripts/restore_{{ database_name }}.sh:
  49. file.managed:
  50. - source: salt://mysql/conf/restore.sh
  51. - mode: 770
  52. - template: jinja
  53. - defaults:
  54. database_name: {{ database_name }}
  55. database: {{ database }}
  56. - require:
  57. - file: mysql_dirs
  58. - mysql_database: mysql_database_{{ database_name }}
  59. restore_mysql_database_{{ database_name }}:
  60. cmd.run:
  61. - name: /root/mysql/scripts/restore_{{ database_name }}.sh
  62. - unless: "[ -f /root/mysql/flags/{{ database_name }}-installed ]"
  63. - cwd: /root
  64. - require:
  65. - file: /root/mysql/scripts/restore_{{ database_name }}.sh
  66. {%- endif %}
  67. {%- endfor %}
  68. {%- for user in server.get('users', []) %}
  69. {%- for host in user.get('hosts', user.get('host', 'localhost'))|sequence %}
  70. mysql_user_{{ user.name }}_{{ host }}:
  71. mysql_user.present:
  72. - host: '{{ host }}'
  73. - name: '{{ user.name }}'
  74. {%- if user['password_hash'] is defined %}
  75. - password_hash: '{{ user.password_hash }}'
  76. {%- elif user['password'] is defined and user['password'] != None %}
  77. - password: '{{ user.password }}'
  78. {%- else %}
  79. - allow_passwordless: True
  80. {%- endif %}
  81. #- connection_user: {{ connection.user }}
  82. #- connection_pass: {{ connection.password }}
  83. #- connection_charset: {{ connection.charset }}
  84. {%- if grains.get('noservices') %}
  85. - onlyif: /bin/false
  86. {%- endif %}
  87. {%- if 'grants' in user %}
  88. mysql_user_{{ user.name }}_{{ host }}_grants:
  89. mysql_grants.present:
  90. - name: {{ user.name }}
  91. - grant: {{ user['grants']|sequence|join(",") }}
  92. - database: '{{ user.get('database','*.*') }}'
  93. - grant_option: {{ user['grant_option'] | default(False) }}
  94. - user: {{ user.name }}
  95. - host: '{{ host }}'
  96. #- connection_user: {{ connection.user }}
  97. #- connection_pass: {{ connection.password }}
  98. #- connection_charset: {{ connection.charset }}
  99. - require:
  100. - mysql_user_{{ user.name }}_{{ host }}
  101. {%- if grains.get('noservices') %}
  102. - onlyif: /bin/false
  103. {%- endif %}
  104. {%- endif %}
  105. {%- if 'databases' in user %}
  106. {%- for db in user['databases'] %}
  107. mysql_user_{{ user.name }}_{{ host }}_grants_db_{{ db.database }}_{{ loop.index0 }}:
  108. mysql_grants.present:
  109. - name: {{ user.name ~ '_' ~ db['database'] ~ '_' ~ db['table'] | default('all') }}
  110. - grant: {{ db['grants']|sequence|join(",") }}
  111. - database: '{{ db['database'] }}.{{ db['table'] | default('*') }}'
  112. - grant_option: {{ db['grant_option'] | default(False) }}
  113. - user: {{ user.name }}
  114. - host: '{{ host }}'
  115. #- connection_user: {{ connection.user }}
  116. #- connection_pass: {{ connection.password }}
  117. #- connection_charset: {{ connection.charset }}
  118. - require:
  119. - mysql_user_{{ user.name }}_{{ host }}
  120. # the following line is not mandatory as database might not be managed by salt formula
  121. #- mysql_database_{{ db.database }}
  122. {%- if grains.get('noservices') %}
  123. - onlyif: /bin/false
  124. {%- endif %}
  125. {%- endfor %}
  126. {%- endif %}
  127. {%- endfor %}
  128. {%- endfor %}
  129. {%- endif %}