Ask Your Question
1

passing parameters to templates

asked 2013-09-22 08:27:57 -0500

shyp gravatar image

updated 2013-09-22 10:30:38 -0500

golja gravatar image

Hello , Considering I want to create 5 files which are the same besides few parameters in each one , I tried to use template to support it , but it looks like I need class for each file , corrent me if I am wrong or if there is a way for passing file to template :

for example , ( this is what I want and its not working ) ... what is the right way todo it ?

class api {

  file {'/etc/init/resque_worker.conf':
    $name = 'api',
    $resque_task = 'resque:work',
    $queues = 'mailer,sms',
    content => template("resque/resque.conf.erb"),
    mode => "0775",
  }

  file {'/etc/init/resque_worker2.conf':
    $name ...
(more)
edit retag flag offensive close merge delete

Comments

Probably you are missing an '}' in the code. Use `puppet parser validate` to find the error.

golja gravatar imagegolja ( 2013-09-22 10:45:15 -0500 )edit

2 Answers

Sort by ยป oldest newest most voted
3

answered 2013-09-22 10:56:40 -0500

LindaLoo gravatar image

updated 2013-09-22 12:49:19 -0500

It appears you're trying to treat the File resource like a Define. The File resource will not use $name, $resque_task, $queue because those are not parameters it supports. You should write a define that takes those parameters and then creates a File resource in the local scope where the template has access to those variables.

modules/api/manifests/init.pp

class api {

  resque::worker { 'api':
    resque_task => 'resque:work',
    queues         => 'mailer,sms',
  }

  resque::worker { 'api2':
    resque_task => 'resque:work',
    queues         => 'mailer,sms',
  }
}

modules/resque/manifests/worker.pp

define resque::worker(
  $resque_task,
  $queues,
) {

  file { "/etc/init/resque_worker_${name}.conf":
    content => template('resque ...
(more)
edit flag offensive delete link more
2

answered 2013-09-22 10:43:32 -0500

golja gravatar image

Create a defined type something like

define resque_worker($resque_name, $resque_task, $queues) {

  file {"/etc/init/${name}":
    content => template("resque/resque.conf.erb"),
    mode => 0775,
    ensure => present,
  }    
}

And then to initilize those files add this to the node definition:

resque_worker { 'resque_worker.conf':
   resque_name => 'api',
   resque_task => 'resque:work',
   queues  => 'mailer,sms',
}

resque_worker { 'resque_worker2.conf:
   resque_name => 'api2',
   resque_task => 'resque2:work',
   queues => 'mailer,sms',
}

Be carefull in defined type $title and $name has a special meaning. Also you are mixing variables with parameters in file resource type. For more information about defined type check here http://docs.puppetlabs.com/learning/definedtypes.html.

edit flag offensive delete link more

Comments

1

thanks for the help , it solved my problem !

shyp gravatar imageshyp ( 2013-09-23 08:19:44 -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-09-22 08:27:57 -0500

Seen: 3,672 times

Last updated: Sep 22 '13