Ask Your Question
2

issue with variable in class

asked 2014-06-09 09:56:17 -0500

Esity gravatar image

updated 2014-06-09 10:24:31 -0500

Red Cricket gravatar image

Any idea why this always calls the puppet services and never puppet master even if the certname is puppet.domain.com?

class puppet {
    if $certname == 'puppet.domain.com' {
        package { 'puppetmaster':
            ensure => latest,
            provider => 'apt',
            notify => Service['puppetmaster'],
        }
        service { 'puppetmaster':
            ensure => running,
            enable => true,
            require => Package['puppetmaster'],
        }
    } else {
        package { 'puppet':
            ensure => latest,
            provider => 'apt',
            notify => Service['puppet'],
        }
        service { 'puppet':
            ensure => running,
            enable => true,
            require => Package['puppet'],
        }
    }
}
edit retag flag offensive close merge delete

Comments

How do you know that $certname is actually equal to puppet.domain.com? Maybe if you throw a 'debug' Notify resource in your class you can see what $certname really is.

Red Cricket gravatar imageRed Cricket ( 2014-06-09 10:30:48 -0500 )edit

2 Answers

Sort by ยป oldest newest most voted
0

answered 2014-06-09 10:28:07 -0500

Esity gravatar image

the correct thing to do here as to do if $hostname == 'puppet' which solved my problems

edit flag offensive delete link more

Comments

1

The correct thing to do here is actually to start using hiera so you don't have unnecessary code like this ;)

walterheck gravatar imagewalterheck ( 2014-06-10 03:30:51 -0500 )edit

+1 to walterheck. I would have two different classes: `role::puppetmaster` and `role::puppetagent`. Then use hiera for node classification, but use of hiera is not technically required.

Red Cricket gravatar imageRed Cricket ( 2014-06-14 18:00:16 -0500 )edit
1

answered 2014-06-13 18:57:28 -0500

ramindk gravatar image

updated 2014-06-14 13:07:35 -0500

I agree with Walter Heck that this sort of code isn't a great idea. However to solve your actual problem, the certname config value is actually the fact $::clientcert. This is a pretty common mistake. The correct code should be

if $::clientcert == 'puppet.domain.com' {

http://docs.puppetlabs.com/guides/faq...

edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

3 followers

Stats

Asked: 2014-06-09 09:56:17 -0500

Seen: 133 times

Last updated: Jun 14 '14