summaryrefslogtreecommitdiffstats
path: root/plugins/puppet/provider/mysql_user/mysql.rb
blob: a1c2896a07a71266b34ce3f8ec7b77c59f061704 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
Puppet::Type.type(:mysql_user).provide(:mysql) do
	desc "Use mysql as database."
	commands :mysql => '/usr/bin/mysql'

	def create
		mysql "mysql", "-e", "create user '%s@%s' identified by '%s'" % [ @resource[:name], @resource[:host], @resource[:password] ]
	end
	def destroy
		mysql "mysql", "-e", "drop user '%s@%s'" % [ @resource[:name], @resource[:host] ]
	end
	def exists?
		if /^#{@resource[:name]}@#{@resource[:host]}$/.match( mysql( "mysql", "-Be", 'SELECT CONCAT(user, "@", host) FROM user' ) )
			true
		else
			false
		end
	end
end