Changing default password for root user mysql

Hi.

I’m trying to change the password of the root user for a fresh mysql install with :

  • name: Changing default pass for user root for mysql
    action: mysql_user name=root password=root

but ir doesn’t work.

am I missing something here ?

Thanks.

I believe that's only there for database users. Those using MySQL
may know. I don't use it.

Users in MySQL are also attached to specific hosts. I’m not sure what the behavior is when you don’t specify a host in the MySQL Ansible module. You can see how these guys do it in their LAMP setup here:
https://github.com/fourkitchens/server-playbooks/blob/master/common-tasks/mysql-secure.yml

Regards

if you do not specify the host is supposed to connect to localhost and that if what I want.

my playbook is running in pull mode.

What errors do you get? What is the result?

MySQL users are identified through a combination of user and host. In a fresh MySQL install, there will be several entries for the root user.

This Ansible playbook secures the MySQL server:

https://github.com/fourkitchens/server-playbooks/blob/master/common-tasks/mysql-secure.yml

No, the host param in mysql_user command is the host to associate w/ that user login, not the host where you are connecting to.

http://ansible.cc/docs/modules.html#mysql-user

ohh I seem so is the part ‘user’@‘THISISTHEHOST’ part.

I solved the problem using mysqladmin now I know that is not possible with the mysql_user module.

It should be possible - there are two host parameters, the one associated with the user, and one that should be connected to:

http://ansible.cc/docs/modules.html#mysql-user

Hi,

This will solve your problem.

  • name: Update mysql root password
    mysql_user: name=root host={{ item }} login_user=root login_password={{ mysql_default_pass }} password={{ mysql_new_root_password }}
    with_items:
  • 127.0.0.1
  • localhost

You can fine mysql default password in my.cnf or mysql log file.