Re: [Puppet Users] Extending Puppet Woes

51 views
Skip to first unread message

Stefan Schulte

unread,
Aug 11, 2012, 8:33:03 AM8/11/12
to puppet...@googlegroups.com
On Fri, Aug 10, 2012 at 08:51:33PM -0700, Mike Carr wrote:
> I am looking to extend one of the puppet modules -"mysql". I found that they are extending Puppet with types and providers. First off I am having a difficult time find any documentationo on this and I do not know Ruby that well. The problem that I am having is this, I have the following code:
>
> Puppet::Type.type(:database).provide(:mysql) do
> desc "Manages MySQL database."
>
> defaultfor :kernel => 'Linux'
>
> optional_commands :mysql => 'mysql'

This will automatically define a method called mysql you can use later.

>
> def create
> def create
> mysql("-u #{resource[:rootuser]} -p\'#{resource[:rootpassword]}\' -h #{resource[:host]} -NBev", "create database #{@resource[:name]} character set #{resource[:charset]}")
> end
>

The mysql method does not use a shell to execute your command, instead every
argument you pass to the mysql method is passed as an argument to the mysql
executable. So in your case mysql is only executed with one huge argument.
What you want is:

mysql(
'-u', resource[:rootuser],
'-p', resource[:rootpassword],
'-h', resource[:host],
'-NBev', "create database #{resource[:name]} character set #{resource[:charset]}"
)

-Stefan

Mike Carr

unread,
Aug 11, 2012, 12:13:05 PM8/11/12
to puppet...@googlegroups.com
Awesome, thanks! Is this a feature of Ruby or Puppet?
Reply all
Reply to author
Forward
0 new messages