Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to set root password using salt states

Tags:

salt-stack

I want to set strong password for mysql root user. But there is a egg-hen problem. I have empty server. I salt it. The root password is empty (by default after install).

If I use

root: 
  mysql_user.present:
  - name: root
  - password: $ecur3h4x0r
  - host: %

Then I would not be able to call any other mysql states because they would need the password. But the next time I do highstate this call would not work, because the state tries to connect with empty password.

like image 994
Tomáš Fejfar Avatar asked Jun 12 '13 13:06

Tomáš Fejfar


2 Answers

Yeah, we're going to add a 'default_user' and 'default_pass' setting so you can handle this situation. It should be in 0.17.0

like image 156
Utah_Dave Avatar answered Oct 24 '22 00:10

Utah_Dave


Just in case someone stumbles upon this question while starting to manage mysql with saltstack.

Here is how it works in the current salt version (salt 2015.5.0 (Lithium)). Notice that the mysql_user.present-state is smart enough to try it without a password at first. In subsequent runs the state will use the root password to connect and realize that the password for root is in the right state.

root:
  mysql_user.present:
    - host: localhost
    - password: s3cure_root_password

another_user:
  mysql_user.present:
    - host: localhost
    - password: anoth3r_user_password
    - connection_user: root
    - connection_pass: s3cure_root_password
like image 21
Christian Seitzer Avatar answered Oct 23 '22 23:10

Christian Seitzer