Ask Your Question

How to use templates for variable substitution/planting

asked 2014-02-26 10:29:52 -0600

dre7425 gravatar image

updated 2014-02-26 13:02:57 -0600

Stefan gravatar image

Noob here. I created my first module that deploys a text file (/tmp/testmodule.txt) to a managed node, that contains a variable defined at the node.pp level. Ultimately I plan to package custom SW and use variable substitution with & without facter.

Question is: why do I need to invoke the file resource in the node.pp file? Why can't I use the module's init.pp file to do this? I want to be able to do fancier things and create dependencies to that file, but it seems odd that I have to do this in the ... (more)

edit retag flag offensive close merge delete

2 Answers

Sort by ยป oldest newest most voted

answered 2014-02-26 12:19:08 -0600

updated 2014-02-26 12:20:23 -0600

Try changing the class in order to accept parameters, and pass that variable from the node. e.g.:

class testmodule($fakevar) {
  file { '/tmp/testmodule.txt':
    content => template('testmodule/template-test.erb'),


node '' {
  $fakevar = 'thisisavar'
  class { 'testmodule':
    fakevar => $fakevar,
edit flag offensive delete link more


Stefan gravatar imageStefan ( 2014-02-26 13:20:14 -0600 )edit

Thanks - for some reason the link is broken - this should be usable: .

giavac gravatar imagegiavac ( 2014-02-27 03:51:23 -0600 )edit

answered 2014-02-27 07:08:15 -0600

dre7425 gravatar image

updated 2014-02-27 11:30:19 -0600

Stefan gravatar image

Folks, this worked like a champ! I hadn't gotten far enough into reading about scope to have seen how vars can be passed to classes. Next time I'll read more before asking these types of questions.

Here's my new testbox.pp. I changed the vars around to be a bit more transparent.

node '' {
  $local_fake_var = 'this_is_a_value'
  class {  'testmodule':
        fake_var => $local_fake_var,

Thanks again!

edit flag offensive delete link more


Glad to help - do you want to set my answer as accepted? ;-)

giavac gravatar imagegiavac ( 2014-02-27 07:16:04 -0600 )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


Asked: 2014-02-26 10:29:52 -0600

Seen: 133 times

Last updated: Feb 27 '14