Re: [Puppet Users] use current array element when declaring multiple resources using an array

2010-11-18 Thread Felix Frank
On 11/10/2010 05:16 PM, Gabriel Filion wrote:
> On 11/10/2010 10:18 AM, luke.bigum wrote:
>> Hi list,
>>
>> When declaring multiple resources at once with an array like this:
>>
>> file { [ "foo", "bar" ]: ... }
>>
>> Is there a way to access the current array element so as to pass this
>> value as a parameter? So the "foo" resource has a parameter value
>> "foo" and "bar" with a parameter value "bar"?
> 
> 
> I think what you want is to use $name. it corresponds to the resource
> name that is currently being worked on.
> 
> file { [ "foo", "bar" ]: path => "/blah/${name}.txt", ... }
> 

Close, but no cigar.

You need to wrap the file in a define like:

define my_file() {
  file { "$name":
owner => $name,
mode  => 640,
  }
}

Then you can just use

$array = [ ... ]
my_file { $array: }

Regards,
Felix

-- 
You received this message because you are subscribed to the Google Groups 
"Puppet Users" group.
To post to this group, send email to puppet-us...@googlegroups.com.
To unsubscribe from this group, send email to 
puppet-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/puppet-users?hl=en.



Re: [Puppet Users] use current array element when declaring multiple resources using an array

2010-11-10 Thread Gabriel Filion
On 11/10/2010 10:18 AM, luke.bigum wrote:
> Hi list,
> 
> When declaring multiple resources at once with an array like this:
> 
> file { [ "foo", "bar" ]: ... }
> 
> Is there a way to access the current array element so as to pass this
> value as a parameter? So the "foo" resource has a parameter value
> "foo" and "bar" with a parameter value "bar"?


I think what you want is to use $name. it corresponds to the resource
name that is currently being worked on.

file { [ "foo", "bar" ]: path => "/blah/${name}.txt", ... }

-- 
Gabriel Filion

-- 
You received this message because you are subscribed to the Google Groups 
"Puppet Users" group.
To post to this group, send email to puppet-us...@googlegroups.com.
To unsubscribe from this group, send email to 
puppet-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/puppet-users?hl=en.



RE: [Puppet Users] use current array element when declaring multiple resources using an array

2010-11-10 Thread Matthew Black
What you are looking for is a loop which does not exist in puppet, except
for templates. 

I've never tried it but I've speculated it could be possible to create a
manifest template and then use puppet to generate that manifest file in a
similar fashion you are looking to do.

-Original Message-
From: puppet-users@googlegroups.com [mailto:puppet-us...@googlegroups.com]
On Behalf Of luke.bigum
Sent: Wednesday, November 10, 2010 10:19 AM
To: Puppet Users
Subject: [Puppet Users] use current array element when declaring multiple
resources using an array

Hi list,

When declaring multiple resources at once with an array like this:

file { [ "foo", "bar" ]: ... }

Is there a way to access the current array element so as to pass this
value as a parameter? So the "foo" resource has a parameter value
"foo" and "bar" with a parameter value "bar"?

This is a broken example showing that Puppet looks to be evaluating
"owner => $array1" in it's entirety (and perhaps only taking the first
element for a File resource?):

  $array1 = [ "/tmp/one", "/tmp/two", "/tmp/three" ]
  file { $array1:
ensure => present,
owner => $array1,
  }

err: /Stage[main]/Test/File[/tmp/three]: Could not evaluate: Could not
find user /tmp/one
err: /Stage[main]/Test/File[/tmp/two]: Could not evaluate: Could not
find user /tmp/one
err: /Stage[main]/Test/File[/tmp/one]: Could not evaluate: Could not
find user /tmp/one

What I want to see is:

err: /Stage[main]/Test/File[/tmp/three]: Could not evaluate: Could not
find user /tmp/three
err: /Stage[main]/Test/File[/tmp/two]: Could not evaluate: Could not
find user /tmp/two
err: /Stage[main]/Test/File[/tmp/one]: Could not evaluate: Could not
find user /tmp/one

Is there an equivalent of Perl's $_ variable? Perhaps with some
inline_template Ruby magic? This would make some config I'm trying to
write a great deal more concise.

-- 
You received this message because you are subscribed to the Google Groups
"Puppet Users" group.
To post to this group, send email to puppet-us...@googlegroups.com.
To unsubscribe from this group, send email to
puppet-users+unsubscr...@googlegroups.com.
For more options, visit this group at
http://groups.google.com/group/puppet-users?hl=en.


-- 
You received this message because you are subscribed to the Google Groups 
"Puppet Users" group.
To post to this group, send email to puppet-us...@googlegroups.com.
To unsubscribe from this group, send email to 
puppet-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/puppet-users?hl=en.



[Puppet Users] use current array element when declaring multiple resources using an array

2010-11-10 Thread luke.bigum
Hi list,

When declaring multiple resources at once with an array like this:

file { [ "foo", "bar" ]: ... }

Is there a way to access the current array element so as to pass this
value as a parameter? So the "foo" resource has a parameter value
"foo" and "bar" with a parameter value "bar"?

This is a broken example showing that Puppet looks to be evaluating
"owner => $array1" in it's entirety (and perhaps only taking the first
element for a File resource?):

  $array1 = [ "/tmp/one", "/tmp/two", "/tmp/three" ]
  file { $array1:
ensure => present,
owner => $array1,
  }

err: /Stage[main]/Test/File[/tmp/three]: Could not evaluate: Could not
find user /tmp/one
err: /Stage[main]/Test/File[/tmp/two]: Could not evaluate: Could not
find user /tmp/one
err: /Stage[main]/Test/File[/tmp/one]: Could not evaluate: Could not
find user /tmp/one

What I want to see is:

err: /Stage[main]/Test/File[/tmp/three]: Could not evaluate: Could not
find user /tmp/three
err: /Stage[main]/Test/File[/tmp/two]: Could not evaluate: Could not
find user /tmp/two
err: /Stage[main]/Test/File[/tmp/one]: Could not evaluate: Could not
find user /tmp/one

Is there an equivalent of Perl's $_ variable? Perhaps with some
inline_template Ruby magic? This would make some config I'm trying to
write a great deal more concise.

-- 
You received this message because you are subscribed to the Google Groups 
"Puppet Users" group.
To post to this group, send email to puppet-us...@googlegroups.com.
To unsubscribe from this group, send email to 
puppet-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/puppet-users?hl=en.