0

I have two servers running the same application with a need to access a database on one specific database server running MySQL.

Both servers with the application should access the MySQL DB with the same user credentials. At the same time, the MySQL user should not be created with a host wildcard (e.g. %), but with the IPs of both servers.

Usually, this means that I create two MySQL-Users:

  • User: frank, Pass: topsecret, Host: 10.10.0.1
  • User: frank, Pass: topsecret, Host: 10.10.0.2

Now, how can I do this with the MySQL Salt state?

I guess I want something like this:

frank:
  mysql_user.present:
    - host: 10.0.0.1
    - host: 10.0.0.2
    - password: topsecret
  mysql_grants.present:
    - grant: select
    - database: secretdb
    - user: frank
    - host: 10.0.0.1
    - host: 10.0.0.2

This doesn't work since the host is declared multiple times. Also creating the user "frank" two times doesn't work since Salt will complain about a non-unique user name. I tried solving this through Pillars, but also here Salt complains about multiple definitions of the same user name.

Any ideas how to solve this?

PythonLearner
  • 1,022
  • 2
  • 12
  • 29

1 Answers1

1

This should work if you add them as separate users. You can use loops and pillars as usual, but the expanded version would look like this:

EDIT: mysql_user.present now has parameter - name: frank

frank_10.0.0.1:
  mysql_user.present:
    - name: frank
    - host: 10.0.0.1
    - password: topsecret
  mysql_grants.present:
    - grant: select
    - database: secretdb.*
    - user: frank
    - host: 10.0.0.1

frank_10.0.0.2:
  mysql_user.present:
    - name: frank
    - host: 10.0.0.2
    - password: topsecret
  mysql_grants.present:
    - grant: select
    - database: secretdb.*
    - user: frank
    - host: 10.0.0.2
ahus1
  • 557
  • 4
  • 12
  • But this would create two users with different user names, correct? – PythonLearner Jan 22 '16 at 12:40
  • you are right, I have missed the additional `name: frank` for `mysql_user.present`. I've now added it and verified that it works by looking at the user table. Please give it another try. – ahus1 Jan 22 '16 at 17:16
  • Wow, thanks a lot @ahus1 ! This works and I am very happy with it :-) I remember trying something similar but it didn't work for me. I remember that Salt didn't like that I defined "name: frank" , but well.. works now. So: Thanks again! – PythonLearner Feb 02 '16 at 12:55