1

So I have a custom module that just sets up a simple nginx server, to learn how to properly make puppet modules.

But it seems that my values when I declare the class aren't getting passed in. It just uses the default values instead.

Below is my bits of class code that matter, and the base.pp I'm using in my control repo.

Base class init.pp:

class ufprovisioning (

    $webserver_manage   = $ufprovisioning::params::webserver_manage,
    $site_name          = $ufprovisioning::params::site_name,


) inherits ufprovisioning::params {

    contain ufprovisioning::install
    contain ufprovisioning::config
    contain ufprovisioning::service

    Class['::ufprovisioning::install'] -> Class['::ufprovisioning::config'] ~> Class['::ufprovisioning::service']
    Class['::ufprovisioning::install'] ~> Class['::ufprovisioning::service']
}

Parameter Class params.pp:

class ufprovisioning::params {

    $site_name = "webserver.test"
    $webserver_manage = true

}

Config Class config.pp:

class ufprovisioning::config {

    assert_private()

    $webserver_manage   = $::ufprovisioning::params::webserver_manage
    $site_name          = $::ufprovisioning::params::site_name


    nginx::resource::server { 'cclloyd.com':
        ensure          =>  present,
        server_name     =>  [$site_name],
        www_root        =>  "/var/www/${site_name}",
        listen_port     =>  80,
        ssl             =>  false,
    }
}

Control class base.pp:

class profile::base {
    class { '::ntp': }
    class { 'ufprovisioning':
        site_name => "examplesite.test",
        webserver_manage => true,
    }
}
0

Your ufprovisioning::config class is setting variable values directly from ufprovisioning::params, but you are setting values with the ufprovisioning top-scope class when you declare it in profile::base.

Let me phrase it a slightly different way in case that doesn't make sense. You are setting parameter values for init.pp via base.pp which gets default values from params.pp. However, that logic is broken because config.pp gets values directly from params.pp. To solve this, config.pp should inherit values from init.pp.

You could fix it by moving the variables into ufprovisioning::config class parameters which inherit from the top-scope class like this;

class ufprovisioning::config (
    $webserver_manage   = $::ufprovisioning::webserver_manage
    $site_name          = $::ufprovisioning::site_name
) inherits ufprovisioning {

    assert_private()

    nginx::resource::server { 'cclloyd.com':
        ensure          =>  present,
        server_name     =>  [$site_name],
        www_root        =>  "/var/www/${site_name}",
        listen_port     =>  80,
        ssl             =>  false,
    }
}

But, be warned, even this is no longer the suggested pattern used with more recent Puppet versions and Hiera 5.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.