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?
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