BeastMode
2012-Aug-09 19:10 UTC
[Puppet Users] Class using if/else w/ multiple if conditions
I created a custom fact that determines what class of server it is based off the first 3 letters of the hostname: tst, qa, stg, prd, dev.... The fact tested fine and shows in the list when running "facter -p". I wanted to use the fact in a class to determine if zabbix-agent should be removed or installed. I want to remove from servers that currently have zabbix installed in groups tst, dev and qa. For some reason this doesn''t work at all. It doesn''t error out but doesn''t do anything. Every time I run puppet or even debug it just finishes like nothing has changed. Can you please tell me what I''m doing wrong? My test machine is in the ''tst'' server class so in theory puppet should more the zabbix-agent package. Thanks - Chris class zabbix { class client { $module_name = "zabbix" if $datacenter == ''boston'' { $zabbix_server = ''yoda.enernoc.net''} else { $zabbix_server = ''vader.enernoc.net''} # Determine server class. Remove agent from qa, tst and dev server classes if (( $server_class == ''qa[a-z0-9]'' ) or ( $server_class == ''tst'' ) or ( $server_class == ''dev'' )) { package { "zabbix-agent": ensure => absent, }} else { package { "zabbix-agent": ensure => installed, } etmpl { "/etc/zabbix/zabbix_agentd.conf": group => "zabbix", mode => 0640, require => Package["zabbix-agent"]}} # The following files are empty and are only used for the Zabbix # vfs.fs.writable check. $zabbix_files = [ "/.zabbix_writable", "/var/.zabbix_writable", "/opt/.zabbix_writable", "/home/.zabbix_writable",] efile { $zabbix_files: owner => "zabbix", require => Package["zabbix-agent"], } service { "zabbix-agent": enable => true, hasstatus => true, ensure => running, require => [ Etmpl["/etc/zabbix/zabbix_agentd.conf"] ], } } # zabbix::client } # zabbix -- You received this message because you are subscribed to the Google Groups "Puppet Users" group. To view this discussion on the web visit https://groups.google.com/d/msg/puppet-users/-/yqqWjFVZg78J. To post to this group, send email to puppet-users@googlegroups.com. To unsubscribe from this group, send email to puppet-users+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/puppet-users?hl=en.
jcbollinger
2012-Aug-09 21:56 UTC
[Puppet Users] Re: Class using if/else w/ multiple if conditions
On Thursday, August 9, 2012 2:10:46 PM UTC-5, BeastMode wrote:> > I created a custom fact that determines what class of server it is based > off the first 3 letters of the hostname: tst, qa, stg, prd, dev.... The > fact tested fine and shows in the list when running "facter -p". I wanted > to use the fact in a class to determine if zabbix-agent should be removed > or installed. I want to remove from servers that currently have zabbix > installed in groups tst, dev and qa. For some reason this doesn''t work at > all. It doesn''t error out but doesn''t do anything. Every time I run puppet > or even debug it just finishes like nothing has changed. Can you please > tell me what I''m doing wrong? My test machine is in the ''tst'' server class > so in theory puppet should more the zabbix-agent package. Thanks - Chris > > > class zabbix { > > class client { > $module_name = "zabbix" > > if $datacenter == ''boston'' { > $zabbix_server = ''yoda.enernoc.net''} > else { > $zabbix_server = ''vader.enernoc.net''} > > # Determine server class. Remove agent from qa, tst and dev server classes > if (( $server_class == ''qa[a-z0-9]'' ) or ( $server_class == ''tst'' ) or ( > $server_class == ''dev'' )) { >Well, the ''qa[a-z0-9]'' bit probably isn''t going to do what you want. At least, it looks like you wanted to test a regex match, but you wrote an equality test instead. Also, it is best to use fully-qualified names. Custom facts are in the top namespace, so their fully-qualified names look like "$::server_class". You could also drop this in to make sure that your fact values are actually what you expect: notify { ''server_class'': message => "my class is ''$::server_class''" } John -- You received this message because you are subscribed to the Google Groups "Puppet Users" group. To view this discussion on the web visit https://groups.google.com/d/msg/puppet-users/-/wzI8igwkkucJ. To post to this group, send email to puppet-users@googlegroups.com. To unsubscribe from this group, send email to puppet-users+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/puppet-users?hl=en.