Re: Class using if/else w/ multiple if conditions

4,988 views
Skip to first unread message

jcbollinger

unread,
Aug 9, 2012, 5:56:09 PM8/9/12
to puppet...@googlegroups.com


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

Reply all
Reply to author
Forward
0 new messages