Dude, I struggled with that for more than 6 months, and the position of the 
Puppet people was, "you're doing it wrong".  Since that didn't help my problem 
I ended up doing it this way:
1) Create a new fact (see attached) that reports back to the master server on 
what classes are defined on the client (during the last run!).
2) Create a new function (see attached) that will compute the correct set of 
hostgroups from the class list
3) Create a new fact (see attached) that will determine if the client is a zone 
server (e.g. global zone) or if it's a zone running on a server.
4) Use those to drive my Nagios configs.

Here's the relevant class fragment:

  @@nagios_host {
    $fqdn:
      alias => $hostname,
      address => $service_ipaddress,
      max_check_attempts => 3,
      contact_groups => "unix",
      hostgroups => $nagios_hostgroup_list,
      icon_image_alt => $operatingsystem,
      icon_image => "$operatingsystem.png",
      notifications_enabled => 1,
      statusmap_image => "$operatingsystem.gd2",
      tag => inline_template("<%=my_nagios_home.sub(' ','_')%>"), # Puppet 
doesn't like tags with spaces?!?
      notes_url => $cprt_globalzone ? {
        global => "https://${hostname}-a.${my_domain}/";,
        default => undef,
      },
      parents => $cprt_globalzone ? {
        "" => undef,
        nil => undef,
        global => undef,
        default => "${cprt_globalzone}.${my_domain}",
      },
      use => [ $productname ? {
               "Sun Fire X4140" => "host-x4140-template",
               default => "host-generic-template" },
               "host-pnp-template"
               ],
             
             
  }



On Mar 2, 2011, at 6:55 AM, Martijn Grendelman wrote:

> On 02-03-11 14:49, Brian Gallew wrote:
>> Sadly, signs point to "no".
> 
> Too bad. But since I run a patched Puppetmaster anyway, I can do what I
> want :-)
> 
> Unfortunately, it doesn't solve my problem.
> 
> I am trying to do the same thing as Gabriel Filion in this post:
> http://groups.google.com/group/puppet-users/browse_thread/thread/276e6e694520224d
> 
> So, I have a nagios-target class, that defines a virtual resource:
> 
>    @@nagios_host { "$hostname":
>        use => "generic-host",
>        address => $fqdn,
>        alias => $hostname,
>        ensure => present,
>        hostgroups => [],
>    }
> 
> and I would like to do something along the lines of this: in a different
> class (not a subclass of nagios-target), for example in the class that
> configures the MTA:
> 
>    Nagios_host [$hostname] {
>        hostgroups +> "mail-satellite-servers",
>    }
> 
> which results in this error:
> 
> "Only subclasses can override parameters at ..."
> 
> which sounds logical, but...
> 
> Is there any way to do what I want? I can't really think of anything,
> since (variable) scoping will always be in my way, as far as I can see...
> 
> Best regards,
> Martijn.
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 
>> 
>> On Wed, Mar 2, 2011 at 5:15 AM, Martijn Grendelman <mart...@iphion.nl
>> <mailto:mart...@iphion.nl>> wrote:
>> 
>>    Hi,
>> 
>>    A question for the devs. Will this:
>> 
>>    http://projects.puppetlabs.com/issues/4020
>> 
>>    make it into a release any time soon?
>> 
>>    Best regards,
>>    Martijn.
>> 
>>    --
>>    You received this message because you are subscribed to the Google
>>    Groups "Puppet Users" group.
>>    To post to this group, send email to puppet-users@googlegroups.com
>>    <mailto:puppet-users@googlegroups.com>.
>>    To unsubscribe from this group, send email to
>>    puppet-users+unsubscr...@googlegroups.com
>>    <mailto:puppet-users%2bunsubscr...@googlegroups.com>.
>>    For more options, visit this group at
>>    http://groups.google.com/group/puppet-users?hl=en.
>> 
>> 
>> -- 
>> You received this message because you are subscribed to the Google Groups
>> "Puppet Users" group.
>> To post to this group, send email to puppet-users@googlegroups.com.
>> To unsubscribe from this group, send email to
>> puppet-users+unsubscr...@googlegroups.com.
>> For more options, visit this group at
>> http://groups.google.com/group/puppet-users?hl=en.
> 
> -- 
> You received this message because you are subscribed to the Google Groups 
> "Puppet Users" group.
> To post to this group, send email to puppet-users@googlegroups.com.
> To unsubscribe from this group, send email to 
> puppet-users+unsubscr...@googlegroups.com.
> For more options, visit this group at 
> http://groups.google.com/group/puppet-users?hl=en.
> 

Facter.add(:cprt_classes) do
    setcode do
	open('/var/lib/puppet/state/classes.txt').read().split().join(',') rescue ""
    end
end
module Puppet::Parser::Functions
  newfunction(:cprt_calculatehostgroups, :type => :rvalue) do |args|
    classlist = lookupvar('cprt_classes').split(',') rescue []
    pairs = [['role::service', 'service'],
             ['role::production', 'production'],
             ['role::development', 'development'],
             ['role::auction_server', 'auction'],
             ['role::scheduler_server', 'scheduler'],
             ['role::bind_server', 'bind'],
             ['role::build_server', 'build'],
             ['role::jump_start', 'jumpstart'],
             ['role::ldap_server', 'ldap'],
             ['role::network_registration', 'web_static'],
             ['role::mta', 'mta'],
             ['role::nagios', 'nagios'],
             ['role::oracle_server', 'oracle'],
             ['role::puppetmaster', 'puppet'],
             ['role::syslog_aggregator', 'syslog'],
             ['role::web_application_server', 'web_application'],
             ['role::web_services', 'web_static'],
             ['role::zone_server', 'zone_server'],
             ['role::load_gen', 'load_generation_and_testing'],
            ]
    hostgroups = {'default_hostgroup' => nil}
    hostgroups[lookupvar('hardwareisa')] = nil
    hostgroups[lookupvar('productname')] = nil
    os = lookupvar('operatingsystem') rescue nil
    if os != nil
      hostgroups[os] = nil
      hostgroups["#{os}-#{lookupvar('operatingsystemrelease') rescue ''}"] = nil
      hostgroups["#{os}-#{lookupvar('productname') rescue ''}"] = nil
      hostgroups["#{os}-#{lookupvar('virtual') rescue ''}"] = nil
      if hostgroups.has_key?("#{os}-")
        hostgroups.delete("#{os}-")
      end
    end
    hostgroups[lookupvar('virtual')] = nil
    hostgroups[lookupvar('my_nagios_home')] = nil
    pairs.each do |key, value|
      if classlist.index(key)
        hostgroups[value] = nil
      end
    end
    if hostgroups.has_key?("")
      hostgroups.delete("")
    end
    if hostgroups.has_key?(nil)
      hostgroups.delete(nil)
    end
    hostgroups.keys.sort.join(',')
  end
end
Facter.add(:cprt_globalzone) do
  confine :kernel => :SunOS
  setcode do
    zone=`/sbin/zonename`.strip()
    if zone != "global"
      zone = open('/etc/globalzone').read().strip().split('.')[0] rescue "unknown"
    end
    zone
  end
end
-- 
You received this message because you are subscribed to the Google Groups 
"Puppet Users" group.
To post to this group, send email to puppet-users@googlegroups.com.
To unsubscribe from this group, send email to 
puppet-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/puppet-users?hl=en.

Reply via email to