Install MySQL with ansible on ubuntu


I have a problem installing MySQL with ansible on a vagrant ubuntu,

This is my MySQL part

And I have this error

my .my.cnf is

and when copied on the server

I don’t understand why, ~/.my.cnf is created

Project Github



When mysql-server is installed headlessly, there’s no password. Therefore to make .my.cnf work, it should have a blank password line. Here’s what I tested with for a .my.cnf:

It’s also slightly strange to put .my.cnf in your vagrant user directory as owned by root and only readable as root.

After ensuring the password was blank in .my.cnf, I was able to properly set the password for root in those four contexts. Note that it fails to run after that, since .my.cnf would need to be updated, so it fails the idempotency test.

There’s a note on the ansible mysql_user module page that suggests writing the password and then writing the .my.cnf file. If you do that, you need a where clause to the mysql_user action (probably with a file stat before that).

Even more elegant is to use check_implicit_admin along with login_user and login_password. That’s beautifully idempotent.

As a third way, perhaps check_implicit_admin makes it even easier.

Here’s my successful playbook showing the above, tested with a few fresh servers. Kinda proud of this. Note .my.cnf is unnecessary for all of this.

Leave a Reply