In order to understand what is going on you can put some Puppet.debug
statements in there to see what the code is getting to. I think there
is also a problem with the name of your sublcass of
Puppet::Rails::Host. Activerecord takes the name of the class and
converts it into the name of the table. So I think you need to name
your subclass Host (singular). However, I don't know why you would
need to subclass anyway.
If the master is running store configs, I also don't see any reason
that you need to call `establish_connection`. The master should have
done that already, unless you are trying to connect to a different
database, in which case I think this will cause problems for the
master's connection to its database.
On Tue, Oct 16, 2012 at 7:01 AM, Leonard Smith <
lrs...@gmail.com> wrote:
> I am writing a puppet function that will query the stored configs to get a
> list of hosts that subscribe to a resource. I have a standalone ruby script
> that works and I've "converted" it to a puppet function but it doesn't seem
> to be working. I don't see any errors, I just don't get the list of hosts.
> Also I am just learning ruby. Does anyone have any suggestions or ideas or
> is there another way to already do this?
>
> Thanks
> Len
>
> ## manifest
>
> class cluster {
>
> $nodes = clustermembership('testcluster')
> }
>
>
> ## Function Code
>
> require "puppet"
> require "puppet/rails"
>
> module Puppet::Parser::Functions
>
> newfunction(:clustermembership, :type => :rvalue ) do |args|
>
> ActiveRecord::Base.establish_connection(
> :adapter => 'mysql',
> :database => 'puppet',
> :host => 'localhost',
> :password => 'default',
> :username => 'puppet'
> )
>
> theCluster = args[0]
>
> class Hosts < Puppet::Rails::Host; end
>
> printtype = "name"
>
> query = "( resources.restype = \'File\' AND resources.title =
> \'/var/lib/pacemaker/cib/" + theCluster + "-cib.xml\')"
>
> Hosts.find(:all,
> :include => [ :resources ],
> :conditions => query
> ).map { |host| host.send(printtype) }
>
>
> end # newfunction
>
> end # module
>
> --
> You received this message because you are subscribed to the Google Groups
> "Puppet Developers" group.
> To view this discussion on the web visit
>
https://groups.google.com/d/msg/puppet-dev/-/50vNUYCrc9gJ.
> To post to this group, send email to
puppe...@googlegroups.com.
> To unsubscribe from this group, send email to
>
puppet-dev+...@googlegroups.com.
> For more options, visit this group at
>
http://groups.google.com/group/puppet-dev?hl=en.