Changing default password for root user mysql

1,850 views
Skip to first unread message

PePe Amengual

unread,
Oct 16, 2012, 7:19:39 PM10/16/12
to ansible...@googlegroups.com
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.

Michael DeHaan

unread,
Oct 16, 2012, 7:23:30 PM10/16/12
to ansible...@googlegroups.com
I believe that's only there for database users. Those using MySQL
may know. I don't use it.
> --
>
>

giulianob

unread,
Oct 17, 2012, 10:32:54 AM10/17/12
to ansible...@googlegroups.com
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:

Regards

PePe Amengual

unread,
Oct 17, 2012, 1:30:39 PM10/17/12
to ansible...@googlegroups.com
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.

Mark Theunissen

unread,
Oct 18, 2012, 4:48:56 PM10/18/12
to ansible...@googlegroups.com
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:

--
 
 

giulianob

unread,
Oct 19, 2012, 1:26:42 PM10/19/12
to ansible...@googlegroups.com
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. 

PePe Amengual

unread,
Oct 19, 2012, 4:08:57 PM10/19/12
to ansible...@googlegroups.com
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.

Mark Theunissen

unread,
Oct 25, 2012, 3:26:37 PM10/25/12
to ansible...@googlegroups.com
It should be possible - there are two host parameters, the one associated with the user, and one that should be connected to:

--
 
 

Ravikumar Wagh

unread,
Jun 4, 2018, 3:54:57 AM6/4/18
to Ansible Project
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.
Reply all
Reply to author
Forward
0 new messages