Puppet: Add MySQL User

Want to add a user to MySQL that you can use for eg backups, monitoring,… or any other tasks this user needs to perform. (in this example a root user)

Create a small definition

define create_mysqlbckuser (
$mysqlrootpasswd = '',
        )       {
        exec { "create_mysql_bck°user":
        unless => "/usr/bin/mysqladmin -ubckuser -p'b4ckupP4ss' status",
        command => "/usr/bin/mysql -uroot -p'$mysqlrootpasswd' -e \"GRANT ALL ON *.* TO 'bckuser'@'%' IDENTIFIED BY 'B4ckupP4ss';flush privileges;\"", } }

This

From your nodes.pp you can call this by:

create_mysqlbckuser { 'root_user': 
        mysqlrootpasswd => 'B4ckupP4ss, }

 

You can always use the Puppetlabs-mysql module of course!
Check here: https://github.com/puppetlabs/puppetlabs-mysql

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top