Coder Social home page Coder Social logo

ansible-role-mysql's Introduction

Ansible Role: MySQL

CI

Installs and configures MySQL or MariaDB server on RHEL/CentOS or Debian/Ubuntu servers.

Requirements

No special requirements; note that this role requires root access, so either run it in a playbook with a global become: yes, or invoke the role in your playbook like:

- hosts: database
  roles:
    - role: geerlingguy.mysql
      become: yes

Role Variables

Available variables are listed below, along with default values (see defaults/main.yml):

mysql_user_home: /root
mysql_user_name: root
mysql_user_password: root

The home directory inside which Python MySQL settings will be stored, which Ansible will use when connecting to MySQL. This should be the home directory of the user which runs this Ansible role. The mysql_user_name and mysql_user_password can be set if you are running this role under a non-root user account and want to set a non-root user.

mysql_root_home: /root
mysql_root_username: root
mysql_root_password: root

The MySQL root user account details.

mysql_root_password_update: false

Whether to force update the MySQL root user's password. By default, this role will only change the root user's password when MySQL is first configured. You can force an update by setting this to yes.

Note: If you get an error like ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: YES) after a failed or interrupted playbook run, this usually means the root password wasn't originally updated to begin with. Try either removing the .my.cnf file inside the configured mysql_user_home or updating it and setting password='' (the insecure default password). Run the playbook again, with mysql_root_password_update set to yes, and the setup should complete.

Note: If you get an error like ERROR 1698 (28000): Access denied for user 'root'@'localhost' (using password: YES) when trying to log in from the CLI you might need to run as root or sudoer.

mysql_enabled_on_startup: true

Whether MySQL should be enabled on startup.

mysql_config_file: *default value depends on OS*
mysql_config_include_dir: *default value depends on OS*

The main my.cnf configuration file and include directory.

overwrite_global_mycnf: true

Whether the global my.cnf should be overwritten each time this role is run. Setting this to no tells Ansible to only create the my.cnf file if it doesn't exist. This should be left at its default value (yes) if you'd like to use this role's variables to configure MySQL.

mysql_config_include_files: []

A list of files that should override the default global my.cnf. Each item in the array requires a "src" parameter which is a path to a file. An optional "force" parameter can force the file to be updated each time ansible runs.

mysql_databases: []

The MySQL databases to create. A database has the values name, encoding (defaults to utf8), collation (defaults to utf8_general_ci) and replicate (defaults to 1, only used if replication is configured). The formats of these are the same as in the mysql_db module.

You can also delete a database (or ensure it's not on the server) by setting state to absent (defaults to present).

mysql_users: []

The MySQL users and their privileges. A user has the values:

  • name
  • host (defaults to localhost)
  • password (can be plaintext or encrypted—if encrypted, set encrypted: yes)
  • encrypted (defaults to no)
  • priv (defaults to *.*:USAGE)
  • append_privs (defaults to no)
  • state (defaults to present)

The formats of these are the same as in the mysql_user module.

mysql_packages:
  - mysql
  - mysql-server

(OS-specific, RedHat/CentOS defaults listed here) Packages to be installed. In some situations, you may need to add additional packages, like mysql-devel.

mysql_enablerepo: ""

(RedHat/CentOS only) If you have enabled any additional repositories (might I suggest geerlingguy.repo-epel or geerlingguy.repo-remi), those repositories can be listed under this variable (e.g. remi,epel). This can be handy, as an example, if you want to install later versions of MySQL.

mysql_python_package_debian: python3-mysqldb

(Ubuntu/Debian only) If you need to explicitly override the MySQL Python package, you can set it here. Set this to python-mysqldb if using older distributions running Python 2.

mysql_port: "3306"
mysql_bind_address: '0.0.0.0'
mysql_datadir: /var/lib/mysql
mysql_socket: *default value depends on OS*
mysql_pid_file: *default value depends on OS*

Default MySQL connection configuration.

mysql_log_file_group: mysql *adm on Debian*
mysql_log: ""
mysql_log_error: *default value depends on OS*
mysql_syslog_tag: *default value depends on OS*
```yaml

MySQL logging configuration. Setting `mysql_log` (the general query log) or `mysql_log_error` to `syslog` will make MySQL log to syslog using the `mysql_syslog_tag`.

```yaml
mysql_slow_query_log_enabled: false
mysql_slow_query_log_file: *default value depends on OS*
mysql_slow_query_time: 2

Slow query log settings. Note that the log file will be created by this role, but if you're running on a server with SELinux or AppArmor, you may need to add this path to the allowed paths for MySQL, or disable the mysql profile. For example, on Debian/Ubuntu, you can run sudo ln -s /etc/apparmor.d/usr.sbin.mysqld /etc/apparmor.d/disable/usr.sbin.mysqld && sudo service apparmor restart.

mysql_key_buffer_size: "256M"
mysql_max_allowed_packet: "64M"
mysql_table_open_cache: "256"
...

The rest of the settings in defaults/main.yml control MySQL's memory usage and some other common settings. The default values are tuned for a server where MySQL can consume 512 MB RAM, so you should consider adjusting them to suit your particular server better.

mysql_server_id: "1"
mysql_max_binlog_size: "100M"
mysql_binlog_format: "ROW"
mysql_expire_logs_days: "10"
mysql_replication_role: ''
mysql_replication_master: ''
mysql_replication_user: {}

Replication settings. Set mysql_server_id and mysql_replication_role by server (e.g. the master would be ID 1, with the mysql_replication_role of master, and the slave would be ID 2, with the mysql_replication_role of slave). The mysql_replication_user uses the same keys as individual list items in mysql_users, and is created on master servers, and used to replicate on all the slaves.

mysql_replication_master needs to resolve to an IP or a hostname which is accessable to the Slaves (this could be a /etc/hosts injection or some other means), otherwise the slaves cannot communicate to the master.

If the replication master has different IP addresses where you are running ansible and where the mysql replica is running, you can optionally specify a mysql_replication_master_inventory_host to access the machine (e.g. you run ansible on your local machine, but the mysql master and replica need to communicate on a different network)

mysql_hide_passwords: false

Do you need to hide tasks' output which contain passwords during the execution ?

Later versions of MySQL on CentOS 7

If you want to install MySQL from the official repository instead of installing the system default MariaDB equivalents, you can add the following pre_tasks task in your playbook:

  pre_tasks:
    - name: Install the MySQL repo.
      yum:
        name: http://repo.mysql.com/mysql-community-release-el7-5.noarch.rpm
        state: present
      when: ansible_os_family == "RedHat"
  
    - name: Override variables for MySQL (RedHat).
      set_fact:
        mysql_daemon: mysqld
        mysql_packages: ['mysql-server']
        mysql_log_error: /var/log/mysqld.err
        mysql_syslog_tag: mysqld
        mysql_pid_file: /var/run/mysqld/mysqld.pid
        mysql_socket: /var/lib/mysql/mysql.sock
      when: ansible_os_family == "RedHat"

MariaDB usage

This role works with either MySQL or a compatible version of MariaDB. On RHEL/CentOS 7+, the mariadb database engine was substituted as the default MySQL replacement package. No modifications are necessary though all of the variables still reference 'mysql' instead of mariadb.

Ubuntu 14.04 and 16.04 MariaDB configuration

On Ubuntu, the package names are named differently, so the mysql_package variable needs to be altered. Set the following variables (at a minimum):

mysql_packages:
  - mariadb-client
  - mariadb-server
  - python-mysqldb

Dependencies

If you have ansible installed (e.g. pip3 install ansible), none.

If you have only installed ansible-core, be sure to require community.mysql in your collections/requirements.yml or install it manually with ansible-galaxy collection install community.mysql.

Example Playbook

- hosts: db-servers
  become: yes
  vars_files:
    - vars/main.yml
  roles:
    - { role: geerlingguy.mysql }

Inside vars/main.yml:

mysql_root_password: super-secure-password
mysql_databases:
  - name: example_db
    encoding: latin1
    collation: latin1_general_ci
mysql_users:
  - name: example_user
    host: "%"
    password: similarly-secure-password
    priv: "example_db.*:ALL"

License

MIT / BSD

Author Information

This role was created in 2014 by Jeff Geerling, author of Ansible for DevOps.

ansible-role-mysql's People

Contributors

030 avatar abelboldu avatar aguay-val avatar andreykaipov avatar aniro avatar aruhier avatar caseycs avatar caspark avatar eradical avatar geerlingguy avatar giorgioma avatar jbucki avatar jeroenvdgulik avatar joelpittet avatar jonpugh avatar m3nu avatar maelstromeous avatar mhitza avatar mtze avatar nerzhul avatar nkakouros avatar oxyc avatar ptomas-adacis avatar pulse-mind avatar raistlin avatar schwarz-b5c avatar smallsam avatar ssbarnea avatar stuwil avatar unrealquester avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

ansible-role-mysql's Issues

Updating root password fails

I've just recently started seeing the following errors:

==> default: TASK: [ansible-role-mysql | Update MySQL root password for localhost root account.] *** 
==> default: failed: [localhost] => (item=mysql) => {"failed": true, "item": "mysql"}
==> default: msg: unable to connect to database, check login_user and login_password are correct or ~/.my.cnf has the credentials
==> default: failed: [localhost] => (item=127.0.0.1) => {"failed": true, "item": "127.0.0.1"}
==> default: msg: unable to connect to database, check login_user and login_password are correct or ~/.my.cnf has the credentials
==> default: failed: [localhost] => (item=::1) => {"failed": true, "item": "::1"}
==> default: msg: unable to connect to database, check login_user and login_password are correct or ~/.my.cnf has the credentials
==> default: failed: [localhost] => (item=localhost) => {"failed": true, "item": "localhost"}
==> default: msg: unable to connect to database, check login_user and login_password are correct or ~/.my.cnf has the credentials

mysql doesn't start on centos 7.0/7.1

I tried running this role on a centos 7.1 box. mysql fails to start. I did not change any settings/vars in the role. If I just install mysql and start it, works fine. Seems like whatever the defaults are in this role do not work for centos 7.

Ansible 2.x role cleanup

A couple warnings appear when running the playbook under Ansible 2.x (which will be released soon):

TASK [geerlingguy.mysql : Delete innodb log files created by apt package after initial install.] ***
changed: [drupalvm]
 [WARNING]: Consider using file module with state=absent rather than running rm

...

TASK [geerlingguy.mysql : Create slow query log file (if configured).] *********
changed: [drupalvm]
 [WARNING]: Consider using file module with state=touch rather than running
touch

MySQL takes time to restart, causing successive steps to sometimes fail

When provisioning a Vagrant VM on Ubuntu 14.04, we occasionally see something like the below. Unfortunately, it appears to be intermittent, and I've only been able to reproduce this behaviour once.

[...]
==> valkyrie: NOTIFIED: [geerlingguy.mysql | restart mysql] ********************************* 
==> valkyrie: failed: [localhost] => {"failed": true}
==> valkyrie: msg:  * Stopping MySQL database server mysqld
==> valkyrie:    ...done.
==> valkyrie:  * Starting MySQL database server mysqld
==> valkyrie:    ...fail!
==> valkyrie: 
==> valkyrie: 
==> valkyrie: FATAL: all hosts have already failed -- aborting

Looking in the mysql error log shows the following:

[...]
# tail -30 /var/log/mysqld.log
InnoDB: Unable to lock ./ibdata1, error: 11
InnoDB: Check that you do not already have another mysqld process
InnoDB: using the same InnoDB data or log files.
InnoDB: Unable to lock ./ibdata1, error: 11
InnoDB: Check that you do not already have another mysqld process
InnoDB: using the same InnoDB data or log files.
InnoDB: Unable to lock ./ibdata1, error: 11
InnoDB: Check that you do not already have another mysqld process
InnoDB: using the same InnoDB data or log files.
150417 20:15:46  InnoDB: Unable to open the first data file
InnoDB: Error in opening ./ibdata1
150417 20:15:46  InnoDB: Operating system error number 11 in a file operation.
InnoDB: Error number 11 means 'Resource temporarily unavailable'.
InnoDB: Some operating system error numbers are described at
InnoDB: http://dev.mysql.com/doc/refman/5.5/en/operating-system-error-codes.html
150417 20:15:46 InnoDB: Could not open or create data files.
150417 20:15:46 InnoDB: If you tried to add new data files, and it failed here,
150417 20:15:46 InnoDB: you should now edit innodb_data_file_path in my.cnf back
150417 20:15:46 InnoDB: to what it was, and remove the new ibdata files InnoDB created
150417 20:15:46 InnoDB: in this failed attempt. InnoDB only wrote those files full of
150417 20:15:46 InnoDB: zeros, but did not yet use them in any way. But be careful: do not
150417 20:15:46 InnoDB: remove old data files which contain your precious data!
150417 20:15:46 [ERROR] Plugin 'InnoDB' init function returned error.
150417 20:15:46 [ERROR] Plugin 'InnoDB' registration as a STORAGE ENGINE failed.
150417 20:15:46 [ERROR] Unknown/unsupported storage engine: InnoDB
150417 20:15:46 [ERROR] Aborting

150417 20:15:46 [Note] /usr/sbin/mysqld: Shutdown complete

150417 20:15:46 mysqld_safe mysqld from pid file /var/run/mysqld/mysqld.pid ended

Note that i believe this is the underlying issue behind GetValkyrie/valkyrie#54, and it is in that context that I came across it.

Errors while installing on Debian 8

failed: [localhost] => (item=mysql-common,mysql-server) => {"failed": true, "item": "mysql-common,mysql-server"}
stderr: E: Sub-process /usr/bin/dpkg returned an error code (1)

stdout: Reading package lists...
Building dependency tree...
Reading state information...
The following extra packages will be installed:
  libaio1 libdbd-mysql-perl libdbi-perl libhtml-template-perl
  libterm-readkey-perl mysql-client-5.5 mysql-server-5.5 mysql-server-core-5.5
Suggested packages:
  libclone-perl libmldbm-perl libnet-daemon-perl libsql-statement-perl
  libipc-sharedcache-perl tinyca
The following NEW packages will be installed:
  libaio1 libdbd-mysql-perl libdbi-perl libhtml-template-perl
  libterm-readkey-perl mysql-client-5.5 mysql-server mysql-server-5.5
  mysql-server-core-5.5
0 upgraded, 9 newly installed, 0 to remove and 0 not upgraded.
Need to get 7912 kB of archives.
After this operation, 92.2 MB of additional disk space will be used.
Get:1 http://security.debian.org/ jessie/updates/main mysql-client-5.5 amd64 5.5.46-0+deb8u1 [1662 kB]
Get:2 http://httpredir.debian.org/debian/ jessie/main libaio1 amd64 0.3.110-1 [9312 B]
Get:3 http://httpredir.debian.org/debian/ jessie/main libdbi-perl amd64 1.631-3+b1 [816 kB]
Get:4 http://httpredir.debian.org/debian/ jessie/main libdbd-mysql-perl amd64 4.028-2+b1 [119 kB]
Get:5 http://httpredir.debian.org/debian/ jessie/main libterm-readkey-perl amd64 2.32-1+b1 [28.0 kB]
Get:6 http://security.debian.org/ jessie/updates/main mysql-server-core-5.5 amd64 5.5.46-0+deb8u1 [3351 kB]
Get:7 http://httpredir.debian.org/debian/ jessie/main libhtml-template-perl all 2.95-1 [66.8 kB]
Get:8 http://security.debian.org/ jessie/updates/main mysql-server-5.5 amd64 5.5.46-0+deb8u1 [1776 kB]
Get:9 http://security.debian.org/ jessie/updates/main mysql-server all 5.5.46-0+deb8u1 [83.7 kB]
Preconfiguring packages ...
Fetched 7912 kB in 5s (1412 kB/s)
Selecting previously unselected package libaio1:amd64.
(Reading database ... 16045 files and directories currently installed.)
Preparing to unpack .../libaio1_0.3.110-1_amd64.deb ...
Unpacking libaio1:amd64 (0.3.110-1) ...
Selecting previously unselected package libdbi-perl.
Preparing to unpack .../libdbi-perl_1.631-3+b1_amd64.deb ...
Unpacking libdbi-perl (1.631-3+b1) ...
Selecting previously unselected package libdbd-mysql-perl.
Preparing to unpack .../libdbd-mysql-perl_4.028-2+b1_amd64.deb ...
Unpacking libdbd-mysql-perl (4.028-2+b1) ...
Selecting previously unselected package libterm-readkey-perl.
Preparing to unpack .../libterm-readkey-perl_2.32-1+b1_amd64.deb ...
Unpacking libterm-readkey-perl (2.32-1+b1) ...
Selecting previously unselected package mysql-client-5.5.
Preparing to unpack .../mysql-client-5.5_5.5.46-0+deb8u1_amd64.deb ...
Unpacking mysql-client-5.5 (5.5.46-0+deb8u1) ...
Selecting previously unselected package mysql-server-core-5.5.
Preparing to unpack .../mysql-server-core-5.5_5.5.46-0+deb8u1_amd64.deb ...
Unpacking mysql-server-core-5.5 (5.5.46-0+deb8u1) ...
Selecting previously unselected package mysql-server-5.5.
Preparing to unpack .../mysql-server-5.5_5.5.46-0+deb8u1_amd64.deb ...
Aborting downgrade from (at least) 10.0 to 5.5.
If are sure you want to downgrade to 5.5, remove the file
/var/lib/mysql/debian-*.flag and try installing again.
dpkg: error processing archive /var/cache/apt/archives/mysql-server-5.5_5.5.46-0+deb8u1_amd64.deb (--unpack):
 subprocess new pre-installation script returned error exit status 1
Selecting previously unselected package libhtml-template-perl.
Preparing to unpack .../libhtml-template-perl_2.95-1_all.deb ...
Unpacking libhtml-template-perl (2.95-1) ...
Selecting previously unselected package mysql-server.
Preparing to unpack .../mysql-server_5.5.46-0+deb8u1_all.deb ...
Unpacking mysql-server (5.5.46-0+deb8u1) ...
Errors were encountered while processing:
 /var/cache/apt/archives/mysql-server-5.5_5.5.46-0+deb8u1_amd64.deb

msg: '/usr/bin/apt-get -y -o "Dpkg::Options::=--force-confdef" -o "Dpkg::Options::=--force-confold"   install 'mysql-server'' failed: E: Sub-process /usr/bin/dpkg returned an error code (1)


FATAL: all hosts have already failed -- aborting

Running role on ubuntu 15.04/16.04 fails

I used the following vagrant box: https://github.com/kraksoft/vagrant-box-ubuntu/releases/download/15.04/ubuntu-15.04-amd64.box Ubuntu 15.04 (based on amd64 server iso file)

$ vagrant up

[...]
skipping: [default]
 _______________________________________________________
/ TASK: geerlingguy.mysql | Ensure MySQL is started and \
\ enabled on boot.                                      /
 -------------------------------------------------------
        \   ^__^
         \  (oo)\_______
            (__)\       )\/\
                ||----w |
                ||     ||


failed: [default] => {"failed": true}
msg: Job for mysql.service failed. See "systemctl status mysql.service" and "journalctl -xe" for details.


FATAL: all hosts have already failed -- aborting
 ____________
< PLAY RECAP >
 ------------
        \   ^__^
         \  (oo)\_______
            (__)\       )\/\
                ||----w |
                ||     ||


           to retry, use: --limit @/home/peteraba/site.retry

default                    : ok=18   changed=8    unreachable=0    failed=1   

Ansible failed to complete successfully. Any error output should be
visible above. Please fix these errors and try again.
vagrant up  190.06s user 7.51s system 12% cpu 26:17.54 total

$ vagrant ssh

Welcome to Ubuntu 15.04 (GNU/Linux 3.19.0-15-generic x86_64)

 * Documentation:  https://help.ubuntu.com/
Last login: Sun Oct  4 09:38:18 2015 from 10.0.2.2

vagrant@vagrant-ubuntu-trusty:~$ systemctl status mysql.service

● mysql.service - MySQL Community Server
   Loaded: loaded (/lib/systemd/system/mysql.service; enabled; vendor preset: enabled)
   Active: activating (start-post) (Result: exit-code) since Sun 2015-10-04 09:48:19 GMT; 3min 22s ago
  Process: 10148 ExecStart=/usr/bin/mysqld_safe (code=exited, status=2)
  Process: 10145 ExecStartPre=/usr/share/mysql/mysql-systemd-start pre (code=exited, status=0/SUCCESS)
 Main PID: 10148 (code=exited, status=2);         : 10149 (mysql-systemd-s)
   CGroup: /system.slice/mysql.service
           └─control
             ├─10149 /bin/bash /usr/share/mysql/mysql-systemd-start post
             └─11170 sleep 1

Oct 04 09:48:19 vagrant-ubuntu-trusty mysqld_safe[10148]: chmod: cannot access ‘/var/log/mysql.err’: No such file or directory
Oct 04 09:48:19 vagrant-ubuntu-trusty mysqld_safe[10148]: 151004 09:48:19 mysqld_safe Starting mysqld daemon with databases from /var/lib/mysql
Oct 04 09:48:19 vagrant-ubuntu-trusty mysqld_safe[10148]: /usr/bin/mysqld_safe: 126: /usr/bin/mysqld_safe: cannot create /var/log/mysql.err: Permission denied
Oct 04 09:48:19 vagrant-ubuntu-trusty mysqld_safe[10148]: /usr/bin/mysqld_safe: 1: eval: cannot create /var/log/mysql.err: Permission denied
Oct 04 09:48:19 vagrant-ubuntu-trusty mysqld_safe[10148]: touch: cannot touch ‘/var/log/mysql.err’: Permission denied
Oct 04 09:48:19 vagrant-ubuntu-trusty mysqld_safe[10148]: chown: cannot access ‘/var/log/mysql.err’: No such file or directory
Oct 04 09:48:19 vagrant-ubuntu-trusty mysqld_safe[10148]: chmod: cannot access ‘/var/log/mysql.err’: No such file or directory
Oct 04 09:48:19 vagrant-ubuntu-trusty mysqld_safe[10148]: 151004 09:48:19 mysqld_safe mysqld from pid file /var/run/mysqld/mysqld.pid ended
Oct 04 09:48:19 vagrant-ubuntu-trusty mysqld_safe[10148]: /usr/bin/mysqld_safe: 126: /usr/bin/mysqld_safe: cannot create /var/log/mysql.err: Permission denied
Oct 04 09:48:19 vagrant-ubuntu-trusty systemd[1]: mysql.service: main process exited, code=exited, status=2/INVALIDARGUMENT

vagrant@vagrant-ubuntu-trusty:~$ journalctl -xe

Oct 04 09:48:19 vagrant-ubuntu-trusty systemd[1]: Unit mysql.service entered failed state.
Oct 04 09:48:19 vagrant-ubuntu-trusty systemd[1]: mysql.service failed.
Oct 04 09:48:19 vagrant-ubuntu-trusty sudo[7954]: pam_unix(sudo:session): session closed for user root
Oct 04 09:48:19 vagrant-ubuntu-trusty sshd[634]: pam_unix(sshd:session): session closed for user vagrant
Oct 04 09:48:19 vagrant-ubuntu-trusty systemd[1]: mysql.service holdoff time over, scheduling restart.
Oct 04 09:48:19 vagrant-ubuntu-trusty systemd[1]: Starting MySQL Community Server...
-- Subject: Unit mysql.service has begun start-up
-- Defined-By: systemd
-- Support: http://lists.freedesktop.org/mailman/listinfo/systemd-devel
-- 
-- Unit mysql.service has begun starting up.
Oct 04 09:48:19 vagrant-ubuntu-trusty mysqld_safe[10148]: 151004 09:48:19 mysqld_safe Logging to '/var/log/mysql.err'.
Oct 04 09:48:19 vagrant-ubuntu-trusty mysqld_safe[10148]: touch: cannot touch ‘/var/log/mysql.err’: Permission denied
Oct 04 09:48:19 vagrant-ubuntu-trusty mysqld_safe[10148]: chmod: cannot access ‘/var/log/mysql.err’: No such file or directory
Oct 04 09:48:19 vagrant-ubuntu-trusty mysqld_safe[10148]: 151004 09:48:19 mysqld_safe Starting mysqld daemon with databases from /var/lib/mysql
Oct 04 09:48:19 vagrant-ubuntu-trusty mysqld_safe[10148]: /usr/bin/mysqld_safe: 126: /usr/bin/mysqld_safe: cannot create /var/log/mysql.err: Permission denied
Oct 04 09:48:19 vagrant-ubuntu-trusty mysqld_safe[10148]: /usr/bin/mysqld_safe: 1: eval: cannot create /var/log/mysql.err: Permission denied
Oct 04 09:48:19 vagrant-ubuntu-trusty mysqld_safe[10148]: touch: cannot touch ‘/var/log/mysql.err’: Permission denied
Oct 04 09:48:19 vagrant-ubuntu-trusty mysqld_safe[10148]: chown: cannot access ‘/var/log/mysql.err’: No such file or directory
Oct 04 09:48:19 vagrant-ubuntu-trusty mysqld_safe[10148]: chmod: cannot access ‘/var/log/mysql.err’: No such file or directory
Oct 04 09:48:19 vagrant-ubuntu-trusty mysqld_safe[10148]: 151004 09:48:19 mysqld_safe mysqld from pid file /var/run/mysqld/mysqld.pid ended
Oct 04 09:48:19 vagrant-ubuntu-trusty mysqld_safe[10148]: /usr/bin/mysqld_safe: 126: /usr/bin/mysqld_safe: cannot create /var/log/mysql.err: Permission denied
Oct 04 09:48:19 vagrant-ubuntu-trusty systemd[1]: mysql.service: main process exited, code=exited, status=2/INVALIDARGUMENT
Oct 04 09:49:19 vagrant-ubuntu-trusty sshd[4161]: Received disconnect from 10.0.2.2: 11: disconnected by user
Oct 04 09:49:19 vagrant-ubuntu-trusty sshd[4143]: pam_unix(sshd:session): session closed for user vagrant
Oct 04 09:49:19 vagrant-ubuntu-trusty systemd-logind[413]: Removed session 3.
-- Subject: Session 3 has been terminated
-- Defined-By: systemd
-- Support: http://lists.freedesktop.org/mailman/listinfo/systemd-devel
-- Documentation: http://www.freedesktop.org/wiki/Software/systemd/multiseat
-- 
-- A session with the ID 3 has been terminated.
Oct 04 09:51:37 vagrant-ubuntu-trusty sshd[11128]: Accepted publickey for vagrant from 10.0.2.2 port 57754 ssh2: RSA b2:76:da:59:08:26:0e:13:54:61:dc:48:9a:d2:71:ba
Oct 04 09:51:37 vagrant-ubuntu-trusty sshd[11128]: pam_unix(sshd:session): session opened for user vagrant by (uid=0)
Oct 04 09:51:37 vagrant-ubuntu-trusty systemd[1]: Started Session 4 of user vagrant.
-- Subject: Unit session-4.scope has finished start-up
-- Defined-By: systemd
-- Support: http://lists.freedesktop.org/mailman/listinfo/systemd-devel
-- 
-- Unit session-4.scope has finished starting up.
-- 
-- The start-up result is done.
Oct 04 09:51:37 vagrant-ubuntu-trusty systemd-logind[413]: New session 4 of user vagrant.
-- Subject: A new session 4 has been created for user vagrant
-- Defined-By: systemd
-- Support: http://lists.freedesktop.org/mailman/listinfo/systemd-devel
-- Documentation: http://www.freedesktop.org/wiki/Software/systemd/multiseat
-- 
-- A new session with the ID 4 has been created for the user vagrant.
-- 
-- The leading process of the session is 11128.
Oct 04 09:51:37 vagrant-ubuntu-trusty systemd[1]: Starting Session 4 of user vagrant.
-- Subject: Unit session-4.scope has begun start-up
-- Defined-By: systemd
-- Support: http://lists.freedesktop.org/mailman/listinfo/systemd-devel
-- 
-- Unit session-4.scope has begun starting up.

vagrant@vagrant-ubuntu-trusty:~$ cat /var/log/mysql/error.log

2015-10-04 09:37:37 7335 [Warning] Using unique option prefix myisam-recover instead of myisam-recover-options is deprecated and will be removed in a future release. Please use the full name instead.
2015-10-04 09:37:37 7335 [Note] Plugin 'FEDERATED' is disabled.
2015-10-04 09:37:37 7335 [Note] InnoDB: Using atomics to ref count buffer pool pages
2015-10-04 09:37:37 7335 [Note] InnoDB: The InnoDB memory heap is disabled
2015-10-04 09:37:37 7335 [Note] InnoDB: Mutexes and rw_locks use GCC atomic builtins
2015-10-04 09:37:37 7335 [Note] InnoDB: Memory barrier is not used
2015-10-04 09:37:37 7335 [Note] InnoDB: Compressed tables use zlib 1.2.8
2015-10-04 09:37:37 7335 [Note] InnoDB: Using Linux native AIO
2015-10-04 09:37:37 7335 [Note] InnoDB: Not using CPU crc32 instructions
2015-10-04 09:37:37 7335 [Note] InnoDB: Initializing buffer pool, size = 128.0M
2015-10-04 09:37:37 7335 [Note] InnoDB: Completed initialization of buffer pool
2015-10-04 09:37:37 7335 [Note] InnoDB: The first specified data file ./ibdata1 did not exist: a new database to be created!
2015-10-04 09:37:37 7335 [Note] InnoDB: Setting file ./ibdata1 size to 12 MB
2015-10-04 09:37:37 7335 [Note] InnoDB: Database physically writes the file full: wait...
2015-10-04 09:37:37 7335 [Note] InnoDB: Setting log file ./ib_logfile101 size to 48 MB
2015-10-04 09:37:37 7335 [Note] InnoDB: Setting log file ./ib_logfile1 size to 48 MB
2015-10-04 09:37:37 7335 [Note] InnoDB: Renaming log file ./ib_logfile101 to ./ib_logfile0
2015-10-04 09:37:37 7335 [Warning] InnoDB: New log files created, LSN=45781
2015-10-04 09:37:37 7335 [Note] InnoDB: Doublewrite buffer not found: creating new
2015-10-04 09:37:38 7335 [Note] InnoDB: Doublewrite buffer created
2015-10-04 09:37:38 7335 [Note] InnoDB: 128 rollback segment(s) are active.
2015-10-04 09:37:38 7335 [Warning] InnoDB: Creating foreign key constraint system tables.
2015-10-04 09:37:39 7335 [Note] InnoDB: Foreign key constraint system tables created
2015-10-04 09:37:39 7335 [Note] InnoDB: Creating tablespace and datafile system tables.
2015-10-04 09:37:39 7335 [Note] InnoDB: Tablespace and datafile system tables created.
2015-10-04 09:37:39 7335 [Note] InnoDB: Waiting for purge to start
2015-10-04 09:37:39 7335 [Note] InnoDB: 5.6.25 started; log sequence number 0
2015-10-04 09:37:40 7335 [Note] Binlog end
2015-10-04 09:37:40 7335 [Note] InnoDB: FTS optimize thread exiting.
2015-10-04 09:37:40 7335 [Note] InnoDB: Starting shutdown...
2015-10-04 09:37:43 7335 [Note] InnoDB: Shutdown completed; log sequence number 1625977
2015-10-04 09:37:43 7372 [Warning] Using unique option prefix myisam-recover instead of myisam-recover-options is deprecated and will be removed in a future release. Please use the full name instead.
2015-10-04 09:37:43 7372 [Note] Plugin 'FEDERATED' is disabled.
2015-10-04 09:37:43 7372 [Note] InnoDB: Using atomics to ref count buffer pool pages
2015-10-04 09:37:43 7372 [Note] InnoDB: The InnoDB memory heap is disabled
2015-10-04 09:37:43 7372 [Note] InnoDB: Mutexes and rw_locks use GCC atomic builtins
2015-10-04 09:37:43 7372 [Note] InnoDB: Memory barrier is not used
2015-10-04 09:37:43 7372 [Note] InnoDB: Compressed tables use zlib 1.2.8
2015-10-04 09:37:43 7372 [Note] InnoDB: Using Linux native AIO
2015-10-04 09:37:43 7372 [Note] InnoDB: Not using CPU crc32 instructions
2015-10-04 09:37:43 7372 [Note] InnoDB: Initializing buffer pool, size = 128.0M
2015-10-04 09:37:43 7372 [Note] InnoDB: Completed initialization of buffer pool
2015-10-04 09:37:43 7372 [Note] InnoDB: Highest supported file format is Barracuda.
2015-10-04 09:37:43 7372 [Note] InnoDB: 128 rollback segment(s) are active.
2015-10-04 09:37:43 7372 [Note] InnoDB: Waiting for purge to start
2015-10-04 09:37:43 7372 [Note] InnoDB: 5.6.25 started; log sequence number 1625977
2015-10-04 09:37:43 7372 [Note] Binlog end
2015-10-04 09:37:43 7372 [Note] InnoDB: FTS optimize thread exiting.
2015-10-04 09:37:43 7372 [Note] InnoDB: Starting shutdown...
2015-10-04 09:37:45 7372 [Note] InnoDB: Shutdown completed; log sequence number 1625987
2015-10-04 09:37:45 7397 [Warning] Using unique option prefix myisam-recover instead of myisam-recover-options is deprecated and will be removed in a future release. Please use the full name instead.
2015-10-04 09:37:45 7397 [Note] Plugin 'FEDERATED' is disabled.
2015-10-04 09:37:45 7397 [Note] InnoDB: Using atomics to ref count buffer pool pages
2015-10-04 09:37:45 7397 [Note] InnoDB: The InnoDB memory heap is disabled
2015-10-04 09:37:45 7397 [Note] InnoDB: Mutexes and rw_locks use GCC atomic builtins
2015-10-04 09:37:45 7397 [Note] InnoDB: Memory barrier is not used
2015-10-04 09:37:45 7397 [Note] InnoDB: Compressed tables use zlib 1.2.8
2015-10-04 09:37:45 7397 [Note] InnoDB: Using Linux native AIO
2015-10-04 09:37:45 7397 [Note] InnoDB: Not using CPU crc32 instructions
2015-10-04 09:37:45 7397 [Note] InnoDB: Initializing buffer pool, size = 128.0M
2015-10-04 09:37:45 7397 [Note] InnoDB: Completed initialization of buffer pool
2015-10-04 09:37:45 7397 [Note] InnoDB: Highest supported file format is Barracuda.
2015-10-04 09:37:45 7397 [Note] InnoDB: 128 rollback segment(s) are active.
2015-10-04 09:37:45 7397 [Note] InnoDB: Waiting for purge to start
2015-10-04 09:37:45 7397 [Note] InnoDB: 5.6.25 started; log sequence number 1625987
2015-10-04 09:37:45 7397 [Note] Binlog end
2015-10-04 09:37:45 7397 [Note] InnoDB: FTS optimize thread exiting.
2015-10-04 09:37:45 7397 [Note] InnoDB: Starting shutdown...
2015-10-04 09:37:47 7397 [Note] InnoDB: Shutdown completed; log sequence number 1625997
151004 09:37:48 mysqld_safe Starting mysqld daemon with databases from /var/lib/mysql
2015-10-04 09:37:48 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2015-10-04 09:37:48 0 [Note] /usr/sbin/mysqld (mysqld 5.6.25-0ubuntu0.15.04.1) starting as process 7845 ...
2015-10-04 09:37:48 7845 [Warning] Buffered warning: Changed limits: max_open_files: 1024 (requested 5000)

2015-10-04 09:37:48 7845 [Warning] Buffered warning: Changed limits: table_open_cache: 431 (requested 2000)

2015-10-04 09:37:48 7845 [Warning] Using unique option prefix myisam-recover instead of myisam-recover-options is deprecated and will be removed in a future release. Please use the full name instead.
2015-10-04 09:37:48 7845 [Note] Plugin 'FEDERATED' is disabled.
2015-10-04 09:37:48 7845 [ERROR] Function 'innodb' already exists
2015-10-04 09:37:48 7845 [Warning] Couldn't load plugin named 'innodb' with soname 'ha_innodb.so'.
2015-10-04 09:37:48 7845 [ERROR] Function 'federated' already exists
2015-10-04 09:37:48 7845 [Warning] Couldn't load plugin named 'federated' with soname 'ha_federated.so'.
2015-10-04 09:37:48 7845 [ERROR] Function 'blackhole' already exists
2015-10-04 09:37:48 7845 [Warning] Couldn't load plugin named 'blackhole' with soname 'ha_blackhole.so'.
2015-10-04 09:37:48 7845 [ERROR] Function 'archive' already exists
2015-10-04 09:37:48 7845 [Warning] Couldn't load plugin named 'archive' with soname 'ha_archive.so'.
2015-10-04 09:37:48 7845 [Note] InnoDB: Using atomics to ref count buffer pool pages
2015-10-04 09:37:48 7845 [Note] InnoDB: The InnoDB memory heap is disabled
2015-10-04 09:37:48 7845 [Note] InnoDB: Mutexes and rw_locks use GCC atomic builtins
2015-10-04 09:37:48 7845 [Note] InnoDB: Memory barrier is not used
2015-10-04 09:37:48 7845 [Note] InnoDB: Compressed tables use zlib 1.2.8
2015-10-04 09:37:48 7845 [Note] InnoDB: Using Linux native AIO
2015-10-04 09:37:48 7845 [Note] InnoDB: Not using CPU crc32 instructions
2015-10-04 09:37:48 7845 [Note] InnoDB: Initializing buffer pool, size = 128.0M
2015-10-04 09:37:48 7845 [Note] InnoDB: Completed initialization of buffer pool
2015-10-04 09:37:48 7845 [Note] InnoDB: Highest supported file format is Barracuda.
2015-10-04 09:37:48 7845 [Note] InnoDB: 128 rollback segment(s) are active.
2015-10-04 09:37:48 7845 [Note] InnoDB: Waiting for purge to start
2015-10-04 09:37:48 7845 [Note] InnoDB: 5.6.25 started; log sequence number 1625997
2015-10-04 09:37:48 7845 [Warning] No existing UUID has been found, so we assume that this is the first time that this server has been started. Generating a new UUID: 93249e5b-6a7b-11e5-83e2-0800274ac42f.
2015-10-04 09:37:48 7845 [Note] Server hostname (bind-address): '127.0.0.1'; port: 3306
2015-10-04 09:37:48 7845 [Note]   - '127.0.0.1' resolves to '127.0.0.1';
2015-10-04 09:37:48 7845 [Note] Server socket created on IP: '127.0.0.1'.
2015-10-04 09:37:48 7845 [Note] Event Scheduler: Loaded 0 events
2015-10-04 09:37:48 7845 [Note] /usr/sbin/mysqld: ready for connections.
Version: '5.6.25-0ubuntu0.15.04.1'  socket: '/var/run/mysqld/mysqld.sock'  port: 3306  (Ubuntu)
2015-10-04 09:38:16 7845 [Note] /usr/sbin/mysqld: Normal shutdown

2015-10-04 09:38:16 7845 [Note] Giving 0 client threads a chance to die gracefully
2015-10-04 09:38:16 7845 [Note] Event Scheduler: Purging the queue. 0 events
2015-10-04 09:38:16 7845 [Note] Shutting down slave threads
2015-10-04 09:38:16 7845 [Note] Forcefully disconnecting 0 remaining clients
2015-10-04 09:38:16 7845 [Note] Binlog end
2015-10-04 09:38:16 7845 [Note] Shutting down plugin 'partition'
2015-10-04 09:38:16 7845 [Note] Shutting down plugin 'INNODB_SYS_DATAFILES'
2015-10-04 09:38:16 7845 [Note] Shutting down plugin 'INNODB_SYS_TABLESPACES'
2015-10-04 09:38:16 7845 [Note] Shutting down plugin 'INNODB_SYS_FOREIGN_COLS'
2015-10-04 09:38:16 7845 [Note] Shutting down plugin 'INNODB_SYS_FOREIGN'
2015-10-04 09:38:16 7845 [Note] Shutting down plugin 'INNODB_SYS_FIELDS'
2015-10-04 09:38:16 7845 [Note] Shutting down plugin 'INNODB_SYS_COLUMNS'
2015-10-04 09:38:16 7845 [Note] Shutting down plugin 'INNODB_SYS_INDEXES'
2015-10-04 09:38:16 7845 [Note] Shutting down plugin 'INNODB_SYS_TABLESTATS'
2015-10-04 09:38:16 7845 [Note] Shutting down plugin 'INNODB_SYS_TABLES'
2015-10-04 09:38:16 7845 [Note] Shutting down plugin 'INNODB_FT_INDEX_TABLE'
2015-10-04 09:38:16 7845 [Note] Shutting down plugin 'INNODB_FT_INDEX_CACHE'
2015-10-04 09:38:16 7845 [Note] Shutting down plugin 'INNODB_FT_CONFIG'
2015-10-04 09:38:16 7845 [Note] Shutting down plugin 'INNODB_FT_BEING_DELETED'
2015-10-04 09:38:16 7845 [Note] Shutting down plugin 'INNODB_FT_DELETED'
2015-10-04 09:38:16 7845 [Note] Shutting down plugin 'INNODB_FT_DEFAULT_STOPWORD'
2015-10-04 09:38:16 7845 [Note] Shutting down plugin 'INNODB_METRICS'
2015-10-04 09:38:16 7845 [Note] Shutting down plugin 'INNODB_BUFFER_POOL_STATS'
2015-10-04 09:38:16 7845 [Note] Shutting down plugin 'INNODB_BUFFER_PAGE_LRU'
2015-10-04 09:38:16 7845 [Note] Shutting down plugin 'INNODB_BUFFER_PAGE'
2015-10-04 09:38:16 7845 [Note] Shutting down plugin 'INNODB_CMP_PER_INDEX_RESET'
2015-10-04 09:38:16 7845 [Note] Shutting down plugin 'INNODB_CMP_PER_INDEX'
2015-10-04 09:38:16 7845 [Note] Shutting down plugin 'INNODB_CMPMEM_RESET'
2015-10-04 09:38:16 7845 [Note] Shutting down plugin 'INNODB_CMPMEM'
2015-10-04 09:38:16 7845 [Note] Shutting down plugin 'INNODB_CMP_RESET'
2015-10-04 09:38:16 7845 [Note] Shutting down plugin 'INNODB_CMP'
2015-10-04 09:38:16 7845 [Note] Shutting down plugin 'INNODB_LOCK_WAITS'
2015-10-04 09:38:16 7845 [Note] Shutting down plugin 'INNODB_LOCKS'
2015-10-04 09:38:16 7845 [Note] Shutting down plugin 'INNODB_TRX'
2015-10-04 09:38:16 7845 [Note] Shutting down plugin 'InnoDB'
2015-10-04 09:38:16 7845 [Note] InnoDB: FTS optimize thread exiting.
2015-10-04 09:38:16 7845 [Note] InnoDB: Starting shutdown...
2015-10-04 09:38:17 7845 [Note] InnoDB: Shutdown completed; log sequence number 1626007
2015-10-04 09:38:17 7845 [Note] Shutting down plugin 'PERFORMANCE_SCHEMA'
2015-10-04 09:38:17 7845 [Note] Shutting down plugin 'ARCHIVE'
2015-10-04 09:38:17 7845 [Note] Shutting down plugin 'BLACKHOLE'
2015-10-04 09:38:17 7845 [Note] Shutting down plugin 'MRG_MYISAM'
2015-10-04 09:38:17 7845 [Note] Shutting down plugin 'CSV'
2015-10-04 09:38:17 7845 [Note] Shutting down plugin 'MEMORY'
2015-10-04 09:38:17 7845 [Note] Shutting down plugin 'MyISAM'
2015-10-04 09:38:17 7845 [Note] Shutting down plugin 'sha256_password'
2015-10-04 09:38:17 7845 [Note] Shutting down plugin 'mysql_old_password'
2015-10-04 09:38:17 7845 [Note] Shutting down plugin 'mysql_native_password'
2015-10-04 09:38:17 7845 [Note] Shutting down plugin 'binlog'
2015-10-04 09:38:17 7845 [Note] /usr/sbin/mysqld: Shutdown complete

151004 09:38:17 mysqld_safe mysqld from pid file /var/run/mysqld/mysqld.pid ended

Note that it does seem to work with 14.04.

Updating postfix doesn't belong

I don't understand why you are updating postfix in this role. Postfix should be managed by a postfix role (which is what I do).

Remove anonymous MySQL user fails

TASK: [geerlingguy.mysql | Remove anonymous MySQL user.] **********************
failed: [drupaldev] => {"failed": true}
msg: unable to connect to database, check login_user and login_password are correct or ~/.my.cnf has the credentials

FATAL: all hosts have already failed -- aborting

Problem restarting mysql service after configuration applied

Hi,

I'm currently using your role on a Debian wheezy (with vagrant and LXC).
I only set mysql_databases and mysql_users vars but at the end of the provisioning I get the following error:

failed: [default] => {"failed": true}
msg: Starting MySQL database server: mysqld . . . . . . . . . . . . . . failed!

The corresponding syslog logs are:

Dec 12 06:13:46 corep /etc/init.d/mysql[11915]: 0 processes alive and '/usr/bin/mysqladmin --defaults-file=/etc/mysql/debian.cnf ping' resulted in
Dec 12 06:13:46 corep /etc/init.d/mysql[11915]: #007/usr/bin/mysqladmin: connect to server at 'localhost' failed
Dec 12 06:13:46 corep /etc/init.d/mysql[11915]: error: 'Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2)'
Dec 12 06:13:46 corep /etc/init.d/mysql[11915]: Check that mysqld is running and that the socket: '/var/run/mysqld/mysqld.sock' exists!
Dec 12 06:13:46 corep /etc/init.d/mysql[11915]:

Any idea what went wrong during configuration?

Get list of hosts for the root user fails with access denied error

Just got the following while trying provision a Digital Ocean droplet:

TASK: [ansible-role-mysql | Get list of hosts for the root user.] *************
failed: [some.ip.address] => {"changed": false, "cmd": ["mysql", "-NBe", "SELECT Host FROM mysql.user WHERE User = \"root\" ORDER BY (Host=\"localhost\") ASC"], "delta": "0:00:00.007364", "end": "2015-06-04 12:54:13.586212", "rc": 1, "start": "2015-06-04 12:54:13.578848", "stdout_lines": [], "warnings": []}
stderr: ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: YES)

I've used this role with success in the past, having not used it in a while I pulled an updated version and re-ran today (first time I've seen this error).

Root password for hostname for local_action

Related to #22, if local_action is used with a mysql install ansible_hostname is localhost and not the hostname of the machine and the root password is not set.

Suggestion would be to grab the results of:

command: 'mysql -NBe 'SELECT Host from mysql.user WHERE User = "root" order by (Host="localhost") ASC'

Note that this orders the localhost last so that ansible doesn't lock itself out.

Not all anonymous users are being removed

Similar to the issue in #22, not all anonymous users are being removed, particularly the one with the host as the hostname.

BEFORE:

mysql> select Host,User from mysql.user;
+--------------------------+------+
| Host                     | User |
+--------------------------+------+
| 127.0.0.1                | root |
| ::1                      | root |
| localhost                |      |
| localhost                | root |
| vagrantdev.example.com |      |
| vagrantdev.example.com | root |
+--------------------------+------+
6 rows in set (0.00 sec)

AFTER:

mysql> select Host, User from user;
+--------------------------+------+
| Host                     | User |
+--------------------------+------+
| 127.0.0.1                | root |
| localhost                | root |
| vagrantdev               | root |
| vagrantdev.blackmesh.com |      |
| vagrantdev.blackmesh.com | root |
+--------------------------+------+
5 rows in set (0.00 sec)

Add replication configuration

I was originally planning on using a separate role for replication, since this role was geared towards my development/smaller servers rather than larger HA-style architecture... however, since the role has gotten more popular, and since I think it would benefit more people to be able to set up replication very simply using this existing role, I'd like to add it in.

I'm thinking of using a pattern similar to the one here (https://github.com/mogproject/ansible-playbooks/blob/master/mysql-replication/roles/mysql/tasks/main.yml), but I think I might have a few ways to make it simpler (and make it so the configuration either with or without replication wouldn't be quite as daunting).

Enabling drush connections from host

Hi Jeff,

I'm using a forked and slightly modified drupal-dev-vm that mounts my drupal directory via a shared folder over NFS. Previously, I was using a puppet-based dev environment, which required a setup step to "GRANT ALL PRIVILEGES ON . TO 'root'@'%' WITH GRANT OPTION;". This allowed our developers to configure the database to connect to mysql at the guest IP address (as opposed to 127.0.0.1), which is important for drush. The bind address in both setups appears to be 0.0.0.0. However, I haven't been able to get my host drush to connect to the guest mysql instance with the drupal-dev-vm. Any guidance on what I'm missing? Also, though I can get drush aliases to connect over ssh to the guest, that's not a viable solution in the long run.

Failing to install

❯ vagrant provision
==> default: Running provisioner: ansible...

PLAY [all] ********************************************************************

GATHERING FACTS ***************************************************************
ok: [default]

TASK: [geerlingguy.mysql | Include OS-specific variables.] ********************
ok: [default]

TASK: [geerlingguy.mysql | Update postfix to the latest version (if extra repositories enabled).] ***
skipping: [default]

TASK: [geerlingguy.mysql | Ensure MySQL packages are installed (RedHat).] *****
skipping: [default]

TASK: [geerlingguy.mysql | Ensure MySQL packages are installed (Debian).] *****
failed: [default] => (item=mysql-server,python-mysqldb) => {"failed": true, "item": "mysql-server,python-mysqldb"}
stderr: E: Could not open lock file /var/lib/dpkg/lock - open (13: Permission denied)
E: Unable to lock the administration directory (/var/lib/dpkg/), are you root?

msg: 'apt-get install 'mysql-server' 'python-mysqldb' ' failed: E: Could not open lock file /var/lib/dpkg/lock - open (13: Permission denied)
E: Unable to lock the administration directory (/var/lib/dpkg/), are you root?


FATAL: all hosts have already failed -- aborting

It's the first role running on the precise64 box. Any ideas how I can fix this?

Best way to use Percona

Hi,

First al all, thanks for making this awesome role. I'm trying to resist the urge to write my own and just use what's out there.
First of all, it's not really a bug. I got it to work.
But I am trying to understand how to go about this in the best possible way.

Percona has it's own Repo, package names and different deamon name.
Suppose my playbook is:


---
- hosts: all
  user: root
  vars_files:
      - vars/percona-vars.yml
      - vars/{{ansible_hostname}}.yml
  roles:
  - checks
  - geerlingguy.repo-epel
  - geerlingguy.ntp
  - geerlingguy.mysql

The variables that I need to override for this to work are:

mysql_daemon: mysql
mysql_enablerepo: "percona-release-x86_64"
mysql_packages:
  - Percona-Server-client-56
  - Percona-Server-server-56
  - MySQL-python

The odd thing is. If I put the mysql_daemon in vars/percona-vars.yml it would seem it gets overwritten by the value in the role. When I put it in {{ansible_hostname}}.yml it works fine.
I'm obviously doing something wrong. I'm going to assume this happens because the static file is evaluated first, then the roles and finally the dynamic vars file.

Any advice on how to do this properly?

Regards,

Barry

MariaDB not started with log_slow_queries = 1

Hi!

We use MariaDB on Debian 8 with slow_log enabled and mysql not started

If we remove log_slow_queries = 1 then it started

What do you think about to remove log_slow_queries = 1 from template my.cnf

Separate APT and YUM package list variable

Currently there is only one variable for packages: mysql_packages.

In case you want to use a playbook on both Debian and RedHat with extra packages, you can only define them for either Debian or Readhat. By using a separate variable, you can define both.

MySQL Replication

I think this part of config:

{% for db in mysql_databases %}
{% if db.replicate|default(1) %}
binlog_do_db = {{ db.name }}
{% else %}
binlog_ignore_db = {{ db.name }}
{% endif %}
{% endfor %}
{% endif %}

Not so good option for mysql replication, binlog_do_db have many caveats - http://dev.mysql.com/doc/refman/5.7/en/replication-options-binary-log.html#option_mysqld_binlog-do-db
And as i know restart of mysql server need to apply this settings, for high load database server its not good opition. So better ways is remove that part or add some additional settings, so admin can choose use this or not.

user password generated by role is not been hashed correctly into the user table

when create user with role can't authenticate into the mysql, y tested too many times and then put the same password by hand with sql update and the password hash is different.
other issue is the mysql_root_password works fine but the mysql_user not. I explain:

mysql_root_password: 'secret'

generate this:

| root             | *3B375FF2470854FD02220F5F0D8FB3B7DD3E7B0E | localhost |

but this:

mysql_users:
  - name: sast
    host: '%'
    password: 'secret'
    priv: '*.*:ALL'

generate this:

| sast             | *196BDEDE2AE4F84CA44C47D54D78478C7E2BD7B7 | %         |

and connect in the localhost and update this:

mysql> set password for 'sast'@'%'=PASSWORD('secret');
Query OK, 0 rows affected (0.01 sec)
mysql> select user,password,host from mysql.user where user = 'sast';
+------+-------------------------------------------+------+
| user | password                                  | host |
+------+-------------------------------------------+------+
| sast | *3B375FF2470854FD02220F5F0D8FB3B7DD3E7B0E | %    |
+------+-------------------------------------------+------+
1 row in set (0.00 sec)

then I think the problem is in mysql_users items but not in mysql_root_password process

Make MySQL user-related operations more robust

See #35, specifically, this commit in Valkyrie's fork of this role: GetValkyrie@fd00dc3

Basically, we should add check_implicit_admin to the mysql_user command (that helps a tiny bit with the first run), and then also use the explicit config_file parameter to set the config file to be used.

The second option is not available in Ansible 1.x, so I'm going to postpone this issue until Ansible 2.0 is released.

RHEL/CentOS 7 uses MariaDB instead of MySQL

Hello!

First of all thanks for you effort!

I found a small issue. On Centos 7 "default" Mysql is 'mariadb-server' as far as I understand.
So it falls with:

failed: [********] => (item=mysql,mysql-server,MySQL-python) => {"changed": false, "failed": true, "item": "mysql,mysql-server,MySQL-python", "rc": 0, "results": ["mariadb-5.5.40-1.el7_0.x86_64 providing mysql is already installed"]}
msg: No Package matching 'mysql-server' found available, installed or updated

FATAL: all hosts have already failed -- aborting

Some topics about mysql package in Centos 7:
https://www.centos.org/forums/viewtopic.php?f=48&t=47394
https://www.digitalocean.com/community/questions/can-t-install-mysql-on-centos-7

Make MySQL root user password settings more reliable

Per the mysql documentation, on *nix based installations there is also a 'root'@'host_name' user. I don't see this user's password being updated in the secure-installation.yml.

Be careful just grabbing ansible_hostname however, as it won't work for mysql being installed on localhost. I think the only way to solve is to register the results of select Host from mysql.user where User="root";

Allow configuration of mysql slow-query-log

The complication is that the variable changed in MySQL 5.6, I think. But I'd like to enable the slow query log with this role, and right now it's difficult to do so through Ansible :)

Error during install , "python mysqldb module is required"

I was reading the post at https://servercheck.in/blog/using-ansible-galaxy to set up my lamp install.

When running ansible, I get this error:

TASK: [../galaxy-roles/geerlingguy.mysql | Update MySQL root password for localhost root account.] ***
failed: [ec2-23-22-178-120.compute-1.amazonaws.com] => (item=ip-10-69-147-104) => {"failed": true, "item": "ip-10-69-147-104"}
msg: the python mysqldb module is required
failed: [ec2-23-22-178-120.compute-1.amazonaws.com] => (item=127.0.0.1) => {"failed": true, "item": "127.0.0.1"}
msg: the python mysqldb module is required
failed: [ec2-23-22-178-120.compute-1.amazonaws.com] => (item=::1) => {"failed": true, "item": "::1"}
msg: the python mysqldb module is required
failed: [ec2-23-22-178-120.compute-1.amazonaws.com] => (item=localhost) => {"failed": true, "item": "localhost"}
msg: the python mysqldb module is required

I checked for the mysqldb module by running python and typing "import mySQLdb" and there were no errors so everything does appear to be installed. I did go to several sites to see how to install the module and I believe everything is in place.

I'm using python 2.7 running on the current default Amazon Linux for ec2.

Root password not set properly

I am having an odd issue where I think the root password is not being set properly causing secure-installation.yml to fail at

TASK: [geerlingguy.mysql | Update MySQL root password for all root accounts.] *** 
failed: [*********] => (item=127.0.0.1) => {"failed": true, "item": "127.0.0.1"}
msg: unable to connect to database, check login_user and login_password are correct or ~/.my.cnf has the credentials
failed: [*********] => (item=::1) => {"failed": true, "item": "::1"}
msg: unable to connect to database, check login_user and login_password are correct or ~/.my.cnf has the credentials
failed: [*********] => (item=localhost) => {"failed": true, "item": "localhost"}
msg: unable to connect to database, check login_user and login_password are correct or ~/.my.cnf has the credentials
FATAL: all hosts have already failed -- aborting

My vars are


---
firewall_allowed_tcp_ports:
  - "22"
  - "3306"

mysql_server_id: ""
mysql_innodb_log_file_size: "5242880"

mysql_root_password: supersecret

Mysql is installed, but no password, root, or supersecret is not working when I try and connect on the db server.

ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: YES)

The .my.cnf file does not exist because I believe it isn't even created until two tasks later.

Issue with setting master log position

Hi,

I am trying to configure a Slave node in a Master/Slave setup, running Ansible 1.8.x on Ubuntu, and receive the following error:

failed: [mdldrdb2] => {"failed": true, "parsed": false} Change master Traceback (most recent call last):
File "/root/.ansible/tmp/ansible-tmp-1418041186.92-240395126581341/mysql_replication", line 1949, in
main()
File "/root/.ansible/tmp/ansible-tmp-1418041186.92-240395126581341/mysql_replication", line 367, in main
changemaster(cursor, chm, chm_params)
File "/root/.ansible/tmp/ansible-tmp-1418041186.92-240395126581341/mysql_replication", line 165, in changemaster
cursor.execute(query, chm_params)
File "/usr/lib64/python2.6/site-packages/MySQLdb/cursors.py", line 173, in execute
self.errorhandler(self, exc, value)
File "/usr/lib64/python2.6/site-packages/MySQLdb/connections.py", line 36, in defaulterrorhandler
raise errorclass, errorvalue
_mysql_exceptions.ProgrammingError: (1064, "You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ''106'' at line 1") OpenSSH_6.6.1, OpenSSL 1.0.1f 6 Jan 2014

However, setting the following property to a static, numerical value, works. I.e.:

master_log_pos: "{{ master.Position }}"
Changed to
master_log_pos: 106

This seems to be an issue with the formatting of the data? Please advise

Allow configuration of expire-logs-days

I just noticed that, on one of my super-heavy-write DB servers, the disk was almost out of space, and a little digging found that there were hundreds of 101MB mysql-bin.000XXX log files in /var/lib/mysql. While it's important to keep logs for replication, you don't need all the logs to the beginning of time!

I'd like to add configuration for the expire-logs-days setting, with a sane default.

CentOS 7 MySQL installation.

CentOS 7+ has mariadb database engine instead of mysql. I could see the steps to use this playbook to install MariaDB.

Is it possible to install MySQL in CentOS 7+using this playbook?

Access denied for user 'root'@'localhost' after password change

Getting this since I updated my MySQL root password in the config.

failed: [elm] => {"changed": false, "cmd": ["mysql", "-NBe", "SELECT Host FROM mysql.user WHERE User = \"root\" ORDER BY (Host=\"localhost\") ASC"], "delta": "0:00:00.017469", "end": "2015-08-19 22:23:51.071333", "rc": 1, "start": "2015-08-19 22:23:51.053864", "stdout_lines": [], "warnings": []}
stderr: ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: YES)

I have tried manually updating the passwords in the user database (all root/host combinations) and while I can log in fine with the new password over SSH, the role still fails.

I am running Ansible 1.9.2 and the server is Ubuntu 14.04.3.

Fails to start on Ubuntu 15.04 x64

At first I tried to do a fairly basic setup:

- role: mysql
  mysql_root_password: somepassword
  mysql_users:
    - name: rewards_admin
      host: "%"
      password: somepassword
      priv: "rewards_rewardsmate.*:ALL"
  mysql_databases:
    - name: rewards_rewardsmate

It just hangs on:

TASK: [mysql | Ensure MySQL is started and enabled on boot.] ******************

Then I tried it using only defaults:

- role: mysql

If I check service status mysql it says:

● mysql.service - MySQL Community Server
Loaded: loaded (/lib/systemd/system/mysql.service; enabled; vendor preset: enabled)
Active: activating (start-post) (Result: exit-code) since Thu 2015-08-20 01:48:19 EDT; 4min 5s ago
Process: 19538 ExecStart=/usr/bin/mysqld_safe (code=exited, status=2)
Process: 19537 ExecStartPre=/usr/share/mysql/mysql-systemd-start pre (code=exited, status=0/SUCCESS)
Main PID: 19538 (code=exited, status=2); : 19539 (mysql-systemd-s)
CGroup: /system.slice/mysql.service
└─control
├─19539 /bin/bash /usr/share/mysql/mysql-systemd-start post
└─20715 sleep 1

Aug 20 01:48:20 rewardsmate mysqld_safe[19538]: 150820 01:48:20 mysqld_safe Logging to '/var/log/mysql.err'.
Aug 20 01:48:20 rewardsmate mysqld_safe[19538]: touch: cannot touch '/var/log/mysql.err': Permission denied
Aug 20 01:48:20 rewardsmate mysqld_safe[19538]: chmod: cannot access '/var/log/mysql.err': No such file or directory
Aug 20 01:48:20 rewardsmate mysqld_safe[19538]: 150820 01:48:20 mysqld_safe Starting mysqld daemon with databas...ysql
Aug 20 01:48:20 rewardsmate mysqld_safe[19538]: /usr/bin/mysqld_safe: 126: /usr/bin/mysqld_safe: cannot create ...nied
Aug 20 01:48:20 rewardsmate mysqld_safe[19538]: /usr/bin/mysqld_safe: 1: eval: cannot create /var/log/mysql.err...nied
Aug 20 01:48:20 rewardsmate mysqld_safe[19538]: touch: cannot touch '/var/log/mysql.err': Permission denied
Aug 20 01:48:20 rewardsmate mysqld_safe[19538]: chown: cannot access '/var/log/mysql.err': No such file or directory
Aug 20 01:48:20 rewardsmate mysqld_safe[19538]: chmod: cannot access '/var/log/mysql.err': No such file or directory
Aug 20 01:48:20 rewardsmate systemd[1]: mysql.service: main process exited, code=exited, status=2/INVALIDARGUMENT
Hint: Some lines were ellipsized, use -l to show in full.

This is using a fresh Digital Ocean droplet only installing mysql. Ubuntu 14.04 x64 on DO works just fine.

Password should not be reset to the default password each time.

Currently the password is reset to the default every single time the role is run. The problem with this is that the user may have intentionally reset the password and running this role will now revert the password. Or, in cases where the password is set by a password lookup which has since been erased locally for security reasons (our situation), the root password is regenerated.

Related to our discussion in #22, the following shell command will grab the current password. If the result is empty, the password is not already set.

cat ~/.my.cnf 2>/dev/null | grep "password=" | cut -c10-

I suggest using the value found above if available, otherwise use the value provided by the mysql_root_password.

MYSQL Users Varibles

I seem to found some bugs on the mysql role. I have isolated the issue by trying to create 2 db users (1 root-user, 1 db-user).. running both users on the playbook vars gives out an error, running db-user alone gives out an error -- but running root-user alone gives no error. I tried running "mysql" as root and it directs me to the sql-shell which means that the ".my.cnf" worked properly.

I am running on Ubuntu14 hosted on Digital Ocean Cloud.


PLAYBOOK ERROR

TASK: [ansible-role-mysql | Ensure MySQL users are present.] ******************
failed: [128.199.222.xxx] => (item={'host': 'localhost', 'password': 'testserver-password', 'name': 'testserver-user', 'priv': '.:ALL'}) => {"failed": true, "item": {"host": "localhost", "name": "testserver-user", "password": "testserver-password", "priv": ".:ALL"}}
msg: (1045, "Access denied for user 'root'@'localhost' (using password: YES)")

FATAL: all hosts have already failed -- aborting


PLAYBOOK VARS

mysql_root_password: P4$$w0rd
overwrite_global_mycnf: yes
mysql_root_password_update: yes
mysql_databases:
 - name: testserver-db
   encoding: latin1
   collation: latin1_general_ci
mysql_users:
# - name: testserver-user
#   host: "localhost"
#   password: testserver-password
#   priv: "testserver-db.*:ALL"

- name: root
host: "localhost"
password: P4$$w0rd
priv: "*.*:ALL"

Better OS/vendor matrix

I saw a very clever solution for supporting multiple vendors:

https://github.com/HanXHX/ansible-mysql

However, it does not support multiple OS Families.

Here is a support matrix that I could imagine:

  • Family: Debian, RedHat
  • Vendor: MySQL, MariaDB, Percona, Other (?)

For each OS-Vendor pair you could provide a variable list (packages, daemon, etc) and an installation file (Debian/mysql.yml).

This way you could bundle any number of installation profiles out-of-the-box (without the need for overriding packages for mariadb, etc.)

Clarify running by root requirement in documentation

I've tried to run this role on my vagrant with following configuration:

- hosts: all
  remote_user: vagrant
  sudo: yes
  vars:
    mysql_user_home: /home/vagrant
    mysql_root_password: root
    mysql_databases:
      - name: sgt
    mysql_users:
      - name: sgt
        host: localhost
        password: verysecure
        priv: "sgt.*:ALL"

And ended up with following error:

TASK: [geerlingguy.mysql | Get list of hosts for the anonymous user.] *********
failed: [default] => {"changed": false, "cmd": ["mysql", "-NBe", "SELECT Host FROM mysql.user WHERE User = \"\""], "delta": "0:00:00.006077", "end": "2015-04-27 05:46:49.456704", "rc": 1, "start": "2015-04-27 05:46:49.450627", "stdout_lines": []}
stderr: ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO)

I've spent a LOT of time trying to figure out why this happening and it appears I have to run role as root. I think it should be clear from documentation. Or may be I've done something wrong?

InnoDB log size is 5MB even though 64MB is specified

For some reason, my mysql db is created with 5MB InnoDB log file size, even though 64MB is specified. This makes mysql unable to start. Any idea? I saw you had set a 5MB log size in the test folder.

vagrant@vagrant-ubuntu-trusty-64:~$ sudo mysqld --verbose
150112 15:46:19 [Warning] 'THREAD_CONCURRENCY' is deprecated and will be removed in a future release.
150112 15:46:19 [Note] Plugin 'FEDERATED' is disabled.
150112 15:46:19 InnoDB: The InnoDB memory heap is disabled
150112 15:46:19 InnoDB: Mutexes and rw_locks use GCC atomic builtins
150112 15:46:19 InnoDB: Compressed tables use zlib 1.2.8
150112 15:46:19 InnoDB: Using Linux native AIO
150112 15:46:19 InnoDB: Initializing buffer pool, size = 256.0M
150112 15:46:19 InnoDB: Completed initialization of buffer pool
InnoDB: Error: log file ./ib_logfile0 is of different size 0 5242880 bytes
InnoDB: than specified in the .cnf file 0 67108864 bytes!
150112 15:46:19 [ERROR] Plugin 'InnoDB' init function returned error.
150112 15:46:19 [ERROR] Plugin 'InnoDB' registration as a STORAGE ENGINE failed.
150112 15:46:19 [ERROR] Unknown/unsupported storage engine: InnoDB
150112 15:46:19 [ERROR] Aborting

150112 15:46:19 [Note] mysqld: Shutdown complete

Grateful for any ideas.

RHEL/CentOS root password not being set

The fix for #60 introduced a regression where the root password will never, with the default settings, be changed on RHEL/CentOS during the secure installation tasks - causing the subsequent setup tasks requiring the mysql client to fail. The mysql_install_packages registered variable changed flag becomes false by the Debian setup task (even though it is skipped).

Remove Python MySQL from package list

If I am correct, it MUST be installed anyway to be able to create databases, etc. Overriding the mysql_packages requires to manually include this package is well, which is a possibility to mistake. How about installing it manually in the OS-specific setup?

"Get list of hosts for the root user" fails to run

command -NBe 'SELECT Host FROM mysql.user WHERE User = "root" ORDER BY (Host="localhost") ASC' fails to run at my vagrant machine. Haven't tried it in production yet.

my overrides:

mysql_root_password: P4UD6d1Vw8N%##FAI9ch5aY8!

mysql_databases:
  - { name: production, collation: utf8_general_ci, encoding: utf8, replicate: 0 }
  - { name: dev, collation: utf8_general_ci, encoding: utf8, replicate: 0 }

mysql_users:
  - { name: prod_usr, host: 127.0.0.1, password: FsEhhydhiWqPHT1icdzhSiG, priv: "production.*:ALL" }
  - { name: dev_usr, host: 127.0.0.1, password: v3tmz1AgfbFgxsN5Xm6wmwN, priv: "dev.*:ALL" }

MySQL 5.5 using remi repo failed start

by using epel or base repo no problem but when enabling remi repo I have the following error:

TASK: [geerlingguy.mysql | Ensure MySQL is started and enabled on boot.] ******
failed: [localhost] => {"failed": true}
[Warning] 'THREAD_CONCURRENCY' is deprecated and will be removed in a future release.
[Note] /usr/libexec/mysqld (mysqld 5.5.45) starting as process 9010 ...
[Warning] 'THREAD_CONCURRENCY' is deprecated and will be removed in a future release.
[Note] /usr/libexec/mysqld (mysqld 5.5.45) starting as process 9017 ...

Error while installing mysql

What could that be?

TASK: [geerlingguy.mysql | Ensure MySQL is started and enabled on boot.] ****** 
<127.0.0.1> ESTABLISH CONNECTION FOR USER: root
<127.0.0.1> REMOTE_MODULE service name=mysql state=started enabled=True
<127.0.0.1> EXEC sshpass -d9 ssh -C -tt -v -o ControlMaster=auto -o ControlPersist=60s -o ControlPath="/home/hristo/.ansible/cp/ansible-ssh-%h-%p-%r" -o Port=2200 -o GSSAPIAuthentication=no -o PubkeyAuthentication=no -o User=root -o ConnectTimeout=10 127.0.0.1 /bin/sh -c 'mkdir -p $HOME/.ansible/tmp/ansible-tmp-1446655254.11-253875681659318 && chmod a+rx $HOME/.ansible/tmp/ansible-tmp-1446655254.11-253875681659318 && echo $HOME/.ansible/tmp/ansible-tmp-1446655254.11-253875681659318'
<127.0.0.1> PUT /tmp/tmpy5YQeN TO /root/.ansible/tmp/ansible-tmp-1446655254.11-253875681659318/service
<127.0.0.1> EXEC sshpass -d9 ssh -C -tt -v -o ControlMaster=auto -o ControlPersist=60s -o ControlPath="/home/hristo/.ansible/cp/ansible-ssh-%h-%p-%r" -o Port=2200 -o GSSAPIAuthentication=no -o PubkeyAuthentication=no -o User=root -o ConnectTimeout=10 127.0.0.1 /bin/sh -c 'LANG=C LC_CTYPE=C /usr/bin/python /root/.ansible/tmp/ansible-tmp-1446655254.11-253875681659318/service; rm -rf /root/.ansible/tmp/ansible-tmp-1446655254.11-253875681659318/ >/dev/null 2>&1'
changed: [devbox] => {"changed": true, "enabled": true, "name": "mysql", "state": "started"}

TASK: [geerlingguy.mysql | Get list of hosts for the root user.] ************** 
<127.0.0.1> ESTABLISH CONNECTION FOR USER: root
<127.0.0.1> REMOTE_MODULE command mysql -NBe 'SELECT Host FROM mysql.user WHERE User = "root" ORDER BY (Host="localhost") ASC'
<127.0.0.1> EXEC sshpass -d12 ssh -C -tt -v -o ControlMaster=auto -o ControlPersist=60s -o ControlPath="/home/hristo/.ansible/cp/ansible-ssh-%h-%p-%r" -o Port=2200 -o GSSAPIAuthentication=no -o PubkeyAuthentication=no -o User=root -o ConnectTimeout=10 127.0.0.1 /bin/sh -c 'mkdir -p $HOME/.ansible/tmp/ansible-tmp-1446655255.37-111181030381962 && chmod a+rx $HOME/.ansible/tmp/ansible-tmp-1446655255.37-111181030381962 && echo $HOME/.ansible/tmp/ansible-tmp-1446655255.37-111181030381962'
<127.0.0.1> PUT /tmp/tmpO7ebgE TO /root/.ansible/tmp/ansible-tmp-1446655255.37-111181030381962/command
<127.0.0.1> EXEC sshpass -d12 ssh -C -tt -v -o ControlMaster=auto -o ControlPersist=60s -o ControlPath="/home/hristo/.ansible/cp/ansible-ssh-%h-%p-%r" -o Port=2200 -o GSSAPIAuthentication=no -o PubkeyAuthentication=no -o User=root -o ConnectTimeout=10 127.0.0.1 /bin/sh -c 'LANG=C LC_CTYPE=C /usr/bin/python /root/.ansible/tmp/ansible-tmp-1446655255.37-111181030381962/command; rm -rf /root/.ansible/tmp/ansible-tmp-1446655255.37-111181030381962/ >/dev/null 2>&1'
failed: [devbox] => {"changed": false, "cmd": ["mysql", "-NBe", "SELECT Host FROM mysql.user WHERE User = \"root\" ORDER BY (Host=\"localhost\") ASC"], "delta": "0:00:00.014310", "end": "2015-11-04 16:40:55.470858", "rc": 1, "start": "2015-11-04 16:40:55.456548", "stdout_lines": [], "warnings": []}
stderr: ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: YES)

FATAL: all hosts have already failed -- aborting

PLAY RECAP ******************************************************************** 
           to retry, use: --limit @/home/hristo/mysql.retry

devbox                     : ok=9    changed=1    unreachable=0    failed=1   

Can't connect to local MySQL server during root user operations, get "Access denied for user 'root'@'localhost'"

I randomly get this error message while running this role (os_family: Debian).

TASK: [geerlingguy.mysql | Get list of hosts for the root user.] ************** <192.168.76.130> REMOTE_MODULE command mysql -NBe 'SELECT Host FROM mysql.user WHERE User = "root" ORDER BY (Host="localhost") ASC' failed: [checkpoint] => {"changed": false, "cmd": ["mysql", "-NBe", "SELECT Host FROM mysql.user WHERE User = \"root\" ORDER BY (Host=\"localhost\") ASC"], "delta": "0:00:00.005448", "end": "2015-08-30 17:52:43.330309", "rc": 1, "start": "2015-08-30 17:52:43.324861", "stdout_lines": [], "warnings": []} stderr: ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2)

Right before this task is started, the server is reset. Based on the type of error, I believe it's caused because the server has not fully started before this task is executed.

Maybe we need to add a wait_for to ensure that server is online before trying to connect?

- wait_for: port=3306 delay=10

I wanted to mention that I'm using the VMWare provider, not Virtualbox. This VMWare provider has its own demons, which may be the cause. I have not tested with Virtualbox yet.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.