mysql.yml 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637
  1. - name: Install MySQL server related packages
  2. apt: pkg={{ item }} state=installed
  3. with_items:
  4. - mysql-server
  5. - mysql-client
  6. when: with_mysql
  7. - name: Install MariaDB server related packages
  8. apt: pkg={{ item }} state=installed
  9. with_items:
  10. - mariadb-server
  11. - mariadb-client
  12. when: with_mariadb
  13. - name: Install MySQL or MariaDB backup related packages (automysqlbackup)
  14. apt: pkg=automysqlbackup state=installed
  15. when: with_mysql_backup
  16. - name: Fix automysqlbackup to handle events properly
  17. lineinfile:
  18. dest: /usr/sbin/automysqlbackup
  19. regexp: "^OPT="
  20. line: 'OPT="--quote-names --events" # OPT string for use with mysqldump ( see man mysqldump )'
  21. when: with_mysql_backup
  22. - name: Change MySQL or MariaDB root default password
  23. 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
  24. changed_when: False
  25. when: mysql_root_password != ''
  26. - name: Add MySQL or MariaDB admin account
  27. 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
  28. changed_when: False
  29. when: mysql_admin_password != ''
  30. - name: Ensure MySQL or MariaDB is running
  31. service: name=mysql state=started