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.

slave.sls 2.7KB

9 years ago
8 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. {%- from "galera/map.jinja" import slave with context %}
  2. {%- if slave.enabled %}
  3. {%- if grains.os_family == 'RedHat' %}
  4. xtrabackup_repo:
  5. pkg.installed:
  6. - sources:
  7. - percona-release: {{ slave.xtrabackup_repo }}
  8. - require_in:
  9. - pkg: galera_packages
  10. # Workaround https://bugs.launchpad.net/percona-server/+bug/1490144
  11. xtrabackup_repo_fix:
  12. cmd.run:
  13. - name: |
  14. sed -i 's,enabled\ =\ 1,enabled\ =\ 1\nexclude\ =\ Percona-XtraDB-\*\ Percona-Server-\*,g' /etc/yum.repos.d/percona-release.repo
  15. - unless: 'grep "exclude = Percona-XtraDB-\*" /etc/yum.repos.d/percona-release.repo'
  16. - watch:
  17. - pkg: xtrabackup_repo
  18. - require_in:
  19. - pkg: galera_packages
  20. {%- endif %}
  21. {%- if grains.os_family == 'Debian' %}
  22. mariadb_repo:
  23. file.managed:
  24. - name: /etc/apt/sources.list.d/mariadb_10-1.list
  25. - source: salt://galera/files/mariadb.list
  26. mariadb_key:
  27. file.managed:
  28. - name: /root/mariadb.key
  29. - source: salt://galera/files/mariadb.key
  30. - mode: 660
  31. install_mariadb_key:
  32. cmd.run:
  33. - name: 'cat /root/mariadb.key | apt-key add -'
  34. - require:
  35. - file: mariadb_key
  36. - file: mariadb_repo
  37. {%- endif %}
  38. mariadb_etc_dir:
  39. file.directory:
  40. - name: /etc/mysql
  41. - makedirs: true
  42. - mode: 755
  43. mariadb-common-pkgs:
  44. pkg.installed:
  45. - names:
  46. - mariadb-common
  47. galera_config:
  48. file.managed:
  49. - name: /etc/mysql/my.cnf
  50. - source: salt://galera/files/my.cnf
  51. - mode: 644
  52. - template: jinja
  53. - require:
  54. - pkg: mariadb-common-pkgs
  55. galera_debian_config:
  56. file.managed:
  57. - name: /etc/mysql/debian.cnf
  58. - source: salt://galera/files/debian.cnf_slave
  59. - mode: 644
  60. - template: jinja
  61. - require:
  62. - pkg: mariadb-common-pkgs
  63. galera_packages:
  64. pkg.installed:
  65. - names: {{ slave.pkgs }}
  66. - refresh: true
  67. - require:
  68. - cmd: install_mariadb_key
  69. - file: galera_config
  70. - file: galera_debian_config
  71. galera_log_dir:
  72. file.directory:
  73. - name: /var/log/mysql
  74. - makedirs: true
  75. - mode: 755
  76. - require:
  77. - pkg: galera_packages
  78. galera_start_service:
  79. service.running:
  80. - name: mysql
  81. - enable: True
  82. - require:
  83. - file: galera_config
  84. galera_bootstrap_set_root_password:
  85. cmd.run:
  86. - name: mysqladmin password "{{ slave.admin.password }}"
  87. - require:
  88. - service: galera_start_service
  89. - unless: 'mysql --user="root" --password="{{ salt['pillar.get']('galera:slave:admin:password') }}" --database="mysql" --execute="show tables"'
  90. mysql_bootstrap_update_maint_password:
  91. cmd.run:
  92. - name: mysql -u root -p{{ slave.admin.password }} -e "GRANT ALL PRIVILEGES ON *.* TO 'debian-sys-maint'@'localhost' IDENTIFIED BY '{{ slave.maintenance_password }}';"
  93. - require:
  94. - cmd: galera_bootstrap_set_root_password
  95. {%- endif %}