Take the 2-minute tour ×
Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

I need a way to pass a given variable - lets say thearch - to several different files within a given class. I need to be able to state the contents of this variable for each file individually.

I have tried the following:

file { "xxx":
  thearch => "i386",
  path    => "/xxx/yyyy",
  owner   => root,
  group   => root,
  mode    => 644,
  content => template("module/test.erb"),
}

This doesn't pass this variable so I can use it with a <%=thearch%> statement within the erb file as I expect.

What am I doing wrong here?

share|improve this question
    
... and your erb file contains something like <%= @thearch %>? Just checking, your example lacks @ from <%=thearch%> ... –  Janne Pikkarainen Jun 5 '12 at 18:03
    
I tried a couple variants, I'll double check that specifically. –  Tim Brigham Jun 5 '12 at 18:08
    
Using the @ returns "Invalid parameter". –  Tim Brigham Jun 5 '12 at 18:19
    
Strange. Have you read this? docs.puppetlabs.com/guides/templating.html –  Janne Pikkarainen Jun 5 '12 at 18:20
    
Repeatedly, unfortunately it doesn't seem to cover my needs. –  Tim Brigham Jun 5 '12 at 18:31

3 Answers 3

up vote 3 down vote accepted

You'll need to wrap the file in a define that does take that parameter, so that it's available when the template is called, and then call that define. If a lot of the parameters are usually the same, set them as defaults while you're at it just to keep the code clean.

define thearch_file($thearch, $path, $owner = root, $group = root, $mode = 0644, $template = '/module/test.erb') {
  file { $name:
    path    => $path,
    owner   => $owner,
    group   => $group,
    mode    => $mode,
    content => template($template),
  }
}

thearch_file {
  "xxx":
    thearch => 'i386',
    path    => "/xxx/yyy";
  "yyy":
    thearch => 'x86_64',
    path    => "/xxx/zzz";
}
share|improve this answer
    
Perfect, thanks. –  Tim Brigham Jun 6 '12 at 12:54

You can't define arbitrary meta parameters for the File resource like "thearch". The only meta parameters available are the ones here. You could use the existing architecture fact from the nodes which might give you the functionality you want.

<%= architecture %>

or perhaps

<% if architecture == 'i386' then -%>
  do some stuff
<% end-%>
share|improve this answer
    
That is kind of what I figured, however the architecture facts don't work in this situation (the given host is providing resources for multiple architectures). –  Tim Brigham Jun 5 '12 at 18:49
    
You might want to create a new question explaining what you're trying to do. It isn't very clear from the above. I'd recommend a define in general, but it's not clear how you're deciding or why the current facts won't work. –  kashani Jun 5 '12 at 18:59
    
Point taken. Thanks for the input. –  Tim Brigham Jun 5 '12 at 20:06

You can't do that. Arguments to a resource are not arbitrary values. You could do this, though:

thearch = "i386"
file { "xxx":
  path    => "/xxx/yyyy",
  owner   => root,
  group   => root,
  mode    => 644,
  content => template("module/test.erb"),
}
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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