diff --git a/defaults/main.yml b/defaults/main.yml index d9af9a9..71d949d 100644 --- a/defaults/main.yml +++ b/defaults/main.yml @@ -1,9 +1,9 @@ # file: mysql/defaults/main.yml # Basic settings +mysql_root_password: 'pass' mysql_port: 3306 mysql_bind_address: "0.0.0.0" -mysql_root_password: 'pass' mysql_language: '/usr/share/mysql/' mysql_datadir: '/var/lib/mysql_datadir' diff --git a/tasks/install.yml b/tasks/install.yml index 645fdcd..dc1d30f 100644 --- a/tasks/install.yml +++ b/tasks/install.yml @@ -16,6 +16,10 @@ - percona-xtrabackup - python-mysqldb +- name: Stop percona + sudo: true + command: service mysql stop + - name: Ensure datadir exists sudo: true file: > @@ -42,26 +46,55 @@ notify: - restart percona -- name: Copy .my.cnf file into the root home folder - template: src=root-my-cnf.j2 dest=/root/.my.cnf owner=root mode=0600 - - name: Initialize the datadir if it's not already populated sudo: true - command: mysql_install_db --datadir={{ mysql_datadir }} + command: mysql_install_db --datadir={{ mysql_datadir }} --user=mysql + +- name: Force datadir to be owned by mysql because mysql_install_db is shit + sudo: true + command: chown -R mysql:mysql {{ mysql_datadir }} + +- name: Write custom server configuration + template: src=etc_mysql_my.cnf.j2 dest=/etc/mysql/my.cnf owner=root mode=0600 + +- name: Restart percona + sudo: true + command: service mysql start + +#- name: Update MySQL root password +# ignore_errors: true +# command: 'mysqladmin -u root password {{ mysql_root_password }}' + +#- name: Update MySQL root password +# ignore_errors: true +# mysql_user: > +# name=root +# password={{ mysql_root_password }} +# host={{ item }} +# with_items: +# - "{{ ansible_hostname }}" +# - 127.0.0.1 +# - localhost -- name: Update MySQL root password - ignore_errors: true - mysql_user: name=root host={{ item }} password={{ root_password }} login_user=root login_password= check_implicit_admin=yes +- name: update mysql root password for all root accounts + mysql_user: name=root host={{ item }} password={{ mysql_root_password }} with_items: - - "{{ ansible_hostname }}" - - 127.0.0.1 - - localhost + - "{{ ansible_hostname }}" + - 127.0.0.1 + - ::1 + - localhost + when: ansible_hostname != 'localhost' -- name: Ensure anonymous users are not in the database - mysql_user: name='' host={{ item }} state=absent +- name: update mysql root password for all root accounts + mysql_user: name=root host={{ item }} password={{ mysql_root_password }} with_items: - - "{{ ansible_hostname }}" - - localhost + - 127.0.0.1 + - ::1 + - localhost + when: ansible_hostname == 'localhost' + +- name: Copy .my.cnf file into the root home folder + template: src=root-my-cnf.j2 dest=~/.my.cnf owner=root mode=0600 - name: Ensure anonymous users are not in the database mysql_user: name='' host={{ item }} state=absent @@ -72,7 +105,3 @@ - name: remove test database mysql_db: name=test state=absent -- name: Write custom server configuration - template: src=etc_mysql_my.cnf.j2 dest=/etc/mysql/my.cnf owner=root mode=0600 - notify: - - restart percona diff --git a/templates/etc_mysql_my.cnf.j2 b/templates/etc_mysql_my.cnf.j2 index 8d3b326..8ec6d56 100644 --- a/templates/etc_mysql_my.cnf.j2 +++ b/templates/etc_mysql_my.cnf.j2 @@ -28,7 +28,7 @@ skip-external-locking # * Fine Tuning -key_buffer = {{ mysql_key_buffer }} +key_buffer_size = {{ mysql_key_buffer }} max_allowed_packet = {{ mysql_max_allowed_packet }} thread_stack = {{ mysql_thread_stack }} thread_cache_size = {{ mysql_cache_size }} diff --git a/templates/root-my-cnf.j2 b/templates/root-my-cnf.j2 index 44e33e6..b63b4e6 100644 --- a/templates/root-my-cnf.j2 +++ b/templates/root-my-cnf.j2 @@ -1,3 +1,3 @@ [client] user=root -password={{ root_password }} +password={{ mysql_root_password }}