On Tue, May 24, 2011 at 02:54:37PM +0200, Florent Paillot wrote:
> Hi Stefan,
>
> Le 21/05/2011 14:42, Stefan Schulte a écrit :
> > On Fri, May 20, 2011 at 07:00:38PM +0200, Florent Paillot wrote:
> >> Hi all,
> >>
> >>
> >> I try to code a Puppet type that act like this :
> >>
> >> class1 {
> >>
> >> mytype { "a name":
> >> command => "command = YY"
> >> }
> >> }
> >>
> >> class2 {
> >>
> >> mytype { "a name":
> >> command => "command = XX",
> >> }
> >> }
> >>
> > You specify two resources here with the same title. That is not allowed.
> > What does the title mean here? What does the command property/parameter
> > means here? Why dont you write
> >
>
> "a name" is an example, i would use a title like "check_load".
>
>
> > command => 'XX' instead off command => 'command = XX'?
> Yes, it's a good idea.
> But I think that i'ts better too keep 'command = XX' because puppet
> could search this pattern in the myfile.cfg (for the "exists?" method)
>
> >>
> >> On the client, it generate a file :
> >>
> >> myfile.cfg
> >> -------------
> >>
> >>
> >> command = YY
> >> command = XX
> > I guess one resource should match one »command = « line (like a host
> > resource describes one entry in /etc/hosts) right? How should puppet
> > know which line in myfile.cfg is the resource you're describing in your
> > manifest?
> >
> >> I want to purge "myfile.cfg" at each run ( I don't want to use someting
> >> like ensure => absent to remove old stuff)
> >> I don't know where to put the code to delete the file and maintain a state
> >> variable to avoid the deletion for each call of the type.
> >>
> >> Should I use prefetch and flush method ?
> >> If someone is able to code the provider, he will have my eternal gratitude
> >> :)
> >>
> > You can use the parsedfile provider. It supports prefetching an the
> > instances method. This way you can also purge lines with the resources
> > type:
> >
> > resources { 'mytype':
> > purge => true,
> > }
> >
> > But I guess you have to provide more info about your type to really be
> > able to help you here.
> >>
> >> Thanks for your help.
> >> Long live Puppet !
> >>
> >>
> >>
> >>
> >> --
> >> You received this message because you are subscribed to the Google Groups
> >> "Puppet Developers" group.
> >> To post to this group, send email to [email protected].
> >> To unsubscribe from this group, send email to
> >> [email protected].
> >> For more options, visit this group at
> >> http://groups.google.com/group/puppet-dev?hl=en.
> >>
> My goal is to manage a nrpe_command.cfg :
>
> npre_commands.cfg:
> ------------------------------
>
> command[check_load]=/usr/lib64/nagios/plugins/check_load -w 15,10,5 -c
> 30,25,20
> command[check_raid]=/usr/lib64/nagios/plugins/check_megaraid_sas
>
>
>
> In my manifest, I would like to use this kind of config :
>
> class nagios::client::base {
>
> @@nagios_service { "check_load":
> use => "generic-service",
> check_command => "check_nrpe_1arg!check_load",
> service_description => "Check Load",
> host_name => "$fqdn",
> }
>
> nrpecmd { "check_load_client":
> command =>
> "command[check_load]=/usr/lib64/nagios/plugins/check_load -w 15,10,5 -c
> 30,25,20"
> }
>
> }I'm still not sure if I got your idea of the type right, so I tried to provide you with a basic type/provider based on what I understood. So here's a (totally not tested) sketch: At first you need a type. The type declares all the parameters and properties that are valid for your nrpecmd resource. If I got your example right, you have at least a name and a command to describe an entry in nrpe_command.cfg. The name parameter should identify a single line. That's why name is the namevar of the type. Because we want to check whether the command is out of sync the command needs to be a property. You should also add some description and value validation to the different parameters and properties. If you dont know how, I can refer you to James' blogpost: http://www.kartar.net/2010/02/puppet-types-and-providers-are-easy/ Sketch of the type: require 'puppet/provider/parsedfile' Puppet::Type.newtype(:nrpecmd) do @doc = "Your doc here" newparam(:name) do desc "Name of the command" isnamevar end newproperty(:command) desc "What command to run" end newproperty(:target) desc "file where the commands are stored" defaultto do if @resource.class.defaultprovider.ancestors.include?(Puppet::Provider::ParsedFile) @resource.class.defaultprovider.default_target else nil end end end end Then you need a provider. The parsedfileprovider should work just fine. Because you dont have a single separator to split the fields name and command you have to provide a regular expression to parse each line of your configfile (and a to_line hook to do the reverse part) require 'puppet/provider/parsedfile' Puppet::Type.type(:nrpecmd).provide(:parsed,:parent => Puppet::Provider::ParsedFile, :default_target => '/path/to/file',:filetype => :flat) do confine :exists => '/path/to/file' text_line :comment, :match => /^#/ text_line :blank, :match => /^\s*$/ record_line :parsed, :fields => %w{name command}, :match => /^command\[([^\]]*)\]\s*=\s*(.*)$/ :to_line => proc { |hash| "command[#{hash[:name]}]=#{hash[:command]}" } end Is this helpful? -Stefan > > > Florent > > > -- > You received this message because you are subscribed to the Google Groups > "Puppet Developers" group. > To post to this group, send email to [email protected]. > To unsubscribe from this group, send email to > [email protected]. > For more options, visit this group at > http://groups.google.com/group/puppet-dev?hl=en. >
pgpSRug97lZI3.pgp
Description: PGP signature
