On Thursday, July 6, 2017 at 4:45:53 PM UTC-5, buoyant_puppy wrote:
>
> Excuse my newbieness, but I'm having a basic misunderstanding regarding
> loops.
>
> Say I have: joesfriends = jack, sam, sally
>
> I need to add each entry into a file - one per line.
>
> $joesfriends.each | String $joesfriends| { # loop
>
> file { "/etc/list_of_joes_friends":
>
> line => "${joesfriends}"
>
> }
>
> }
>
>
>
> This fails on a duplicate declaration error....but how can there not be a
> duplicate, it's a loop? The examples in the docs avoid this particular
> situation by using the var in the filename, but that's not usually going to
> be an option.
>
You have it backwards. If you're trying to declare a single resource then
it's the (Puppet) loop that's not an option.
No resource can be declared more than once. You can, however, declare
*distinct* resources in various iterations of a loop -- for example,
resources representing different parts of the same file -- or you can
construct resource properties via an iterative process in a template or
custom function.
It's not clear exactly what you mean to do because the File resource type
does not have a "line" property. If you mean to describe the complete
contents of a single file then you are looking for a way to construct a
value for the 'content' property of one File resource. I'd recommend a
template <https://docs.puppet.com/puppet/4.10/lang_template.html> for that
purpose. Puppet 4 has two flavors to choose from, ERB and EPP, either one
of which would support building the file content by iterating over the
elements of an array.
John
--
You received this message because you are subscribed to the Google Groups
"Puppet Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/puppet-users/16b621db-af5e-47fb-aaba-b19e7d7a4f60%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.