Author: | Mark Theunissen |
---|
parameter | required | default | choices | comments |
---|---|---|---|---|
append_privs | no | no |
|
Append the privileges defined by priv to the existing ones for this user instead of overwriting existing ones. (added in Ansible 1.4) |
check_implicit_admin | no | Check if mysql allows login as root/nopassword before trying supplied credentials. (added in Ansible 1.3) | ||
host | no | localhost | the 'host' part of the MySQL username | |
login_host | no | localhost | Host running the database | |
login_password | no | The password used to authenticate with | ||
login_port | no | 3306 | Port of the MySQL server (added in Ansible 1.4) | |
login_unix_socket | no | The path to a Unix domain socket for local connections | ||
login_user | no | The username used to authenticate with | ||
name | yes | name of the user (role) to add or remove | ||
password | no | set the user's password | ||
priv | no | MySQL privileges string in the format: db.table:priv1,priv2 |
||
state | no | present |
|
Whether the user should exist. When absent , removes the user. |
Note
Requires ConfigParser
Note
Requires MySQLdb
# Create database user with name 'bob' and password '12345' with all database privileges
- mysql_user: name=bob password=12345 priv=*.*:ALL state=present
# Creates database user 'bob' and password '12345' with all database privileges and 'WITH GRANT OPTION'
- mysql_user: name=bob password=12345 priv=*.*:ALL,GRANT state=present
# Ensure no user named 'sally' exists, also passing in the auth credentials.
- mysql_user: login_user=root login_password=123456 name=sally state=absent
# Example privileges string format
mydb.*:INSERT,UPDATE/anotherdb.*:SELECT/yetanotherdb.*:ALL
# Example using login_unix_socket to connect to server
- mysql_user: name=root password=abc123 login_unix_socket=/var/run/mysqld/mysqld.sock
# Example .my.cnf file for setting the root password
# Note: don't use quotes around the password, because the mysql_user module
# will include them in the password but the mysql client will not
[client]
user=root
password=n<_665{vS43y
Note
Requires the MySQLdb Python package on the remote host. For Ubuntu, this is as easy as apt-get install python-mysqldb.
Note
Both login_password and login_username are required when you are passing credentials. If none are present, the module will attempt to read the credentials from ~/.my.cnf, and finally fall back to using the MySQL default login of ‘root’ with no password.
Note
MySQL server installs with default login_user of ‘root’ and no password. To secure this user as part of an idempotent playbook, you must create at least two tasks: the first must change the root user’s password, without providing any login_user/login_password details. The second must drop a ~/.my.cnf file containing the new root credentials. Subsequent runs of the playbook will then succeed by reading the new credentials from the file.