Ask Your Question
1

Reference variable from template

asked 2013-05-24 11:13:47 -0500

mcvicch gravatar image

I want to create a params.pp class that'll house all my common variables used across various modules but when I reference them in a template, they just show up as "undefined."

Here's my common variables file located in: /etc/puppetlabs/puppet/modules/project/manifests/params.pp:

class project::params {
   $app_cluster = 'app'
}

Here's my manifest file located in: /etc/puppetlabs/puppet/modules/system/manifests/scripts.pp:

class system::scripts {
  file { '/h/scripts':
    ensure    => directory,
    source    => 'puppet:///modules/system/scripts',
    mode      => '750',
    recurse   => true,
  }

  file { '/h/scripts/system.properties':
    ensure    => present,
    content   => template('system/scripts/constructSystemProperties.erb'),
    mode ...
(more)
edit retag flag offensive close merge delete

3 Answers

Sort by ยป oldest newest most voted
1

answered 2013-05-28 15:26:02 -0500

Stefan gravatar image

Personally I'd try to avoid using lookupvar and not cross reference variables from other modules in templates. Instead I'd make the variable local first and use that one in a template. Because when someone else is reading your class he'll normally expect that every information the class depends on is found inside the class (and no dependency is hidden away in templates)

class system::scripts(
  $app_cluster = $project::params::app_cluster
) {
  file { '/h/scripts/system.properties':
    ensure    => present,
    content   => template('system/scripts/constructSystemProperties.erb'),
    mode      => '750',
  }
}

So if the app_cluster parameter is not overwritten, it will use the value ... (more)

edit flag offensive delete link more
1

answered 2013-05-24 17:58:05 -0500

Try to make sure project::params is loaded before system::scripts with require

ie :

class system::scripts {

  require project::params 

  file { '/h/scripts':
    ensure    => directory,
    source    => 'puppet:///modules/system/scripts',
    mode      => '750',
    recurse   => true,
  }
  [...]
edit flag offensive delete link more
0

answered 2013-05-28 06:43:13 -0500

mcvicch gravatar image

That was it, thanks a lot! I knew it had to be something simple.

edit flag offensive delete link more

Comments

I'd suggest to use the "post a comment" button to respond to a specific answer as your text may float up and down depending on the number of upvotes.

Stefan gravatar imageStefan ( 2013-05-28 15:28:18 -0500 )edit

Your Answer

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

Add Answer

Question Tools

1 follower

Stats

Asked: 2013-05-24 11:13:47 -0500

Seen: 3,838 times

Last updated: May 28 '13