mysql.yml 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. - name: 'Install MySQL server related packages'
  2. apt:
  3. pkg:
  4. - 'mysql-server'
  5. - 'mysql-client'
  6. state: 'present'
  7. when: with_mysql|bool and ansible_lsb.major_release|int < 10
  8. tags:
  9. - 'mysql'
  10. - 'sql'
  11. - name: 'Install MariaDB server related packages'
  12. apt:
  13. pkg:
  14. - 'mariadb-server'
  15. - 'mariadb-client'
  16. state: 'present'
  17. when: with_mariadb|bool or (with_mysql|bool and ansible_lsb.major_release|int >= 10)
  18. tags:
  19. - 'mysql'
  20. - 'sql'
  21. - name: 'Install MySQL or MariaDB backup related packages (automysqlbackup)'
  22. apt:
  23. pkg:
  24. - 'automysqlbackup'
  25. state: 'present'
  26. when: with_mysql_backup|bool
  27. tags:
  28. - 'mysql'
  29. - 'sql'
  30. - name: 'Fix automysqlbackup to handle events properly'
  31. lineinfile:
  32. dest: '/usr/sbin/automysqlbackup'
  33. regexp: '^OPT='
  34. line: 'OPT="--quote-names --events" # OPT string for use with mysqldump ( see man mysqldump )'
  35. when: with_mysql_backup|bool
  36. tags:
  37. - 'mysql'
  38. - 'sql'
  39. - name: 'Change MySQL or MariaDB root default password'
  40. raw: if ! echo "SELECT VERSION();" | mysql -u root --password='{{ mysql_root_password }}' >/dev/null 2>&1 ; then echo "UPDATE mysql.user SET Password=PASSWORD('{{ mysql_root_password }}') WHERE User IN ('', 'root'); FLUSH PRIVILEGES;" | mysql --defaults-file=/etc/mysql/debian.cnf ; fi
  41. changed_when: False
  42. when: mysql_root_password|length > 0
  43. tags:
  44. - 'mysql'
  45. - 'sql'
  46. - name: 'Add MySQL or MariaDB admin account'
  47. raw: if ! echo "SELECT VERSION();" | mysql -u admin --password='{{ mysql_admin_password }}' >/dev/null 2>&1 ; then echo "CREATE USER 'admin'@'localhost' IDENTIFIED BY '{{ mysql_admin_password }}'; GRANT ALL PRIVILEGES ON * . * TO 'admin'@'localhost' WITH GRANT OPTION; FLUSH PRIVILEGES;" | mysql --defaults-file=/etc/mysql/debian.cnf ; fi
  48. changed_when: False
  49. when: mysql_admin_password|length > 0
  50. tags:
  51. - 'mysql'
  52. - 'sql'
  53. - name: 'Ensure MySQL or MariaDB is running'
  54. service:
  55. name: mysql
  56. state: started
  57. # vim: ft=yaml.ansible