Hello,


They are duplicate resources because Puppet (on the server) parses the 
manifests and adds all resources found to a catalog that is sent to the client, 
which uses this catalog to update the configuration.

The catalog cannot have duplicate resources.



I know of 3 basic methods to alter the contents of a file with Puppet: augeas, 
file_line and concat. Augeas is quite powerful, and maybe not best suited for 
this specific task. file_line is part of the puppetlabs-stdlibs module you most 
likely already have installed and concat is in a separate puppetlabs-concat 
module.



Untested, but with file_line I would do something like this:



joesfriends = jack, sam, sally

$joesfriends.each | String $joesfriend | {

  file_line { $joesfriend:

    ensure => present,

    path   => '/etc/list_of_joes_friends',

    line    => 'whatever you want',

  }

}



This assumes the file /etc/list_of_joes_friends is already present.



-----Original message-----
From: buoyant_puppy <[email protected]>
Sent: Thursday 6th July 2017 23:45
To: Puppet Users <[email protected]>
Subject: [Puppet Users] Avoiding duplicate declaration in a loop?

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 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] 
<mailto:[email protected]> .
 To view this discussion on the web visit 
https://groups.google.com/d/msgid/puppet-users/220aaba3-2cc4-4338-b575-349b8397f694%40googlegroups.com.
 For more options, visit https://groups.google.com/d/optout.
 

-- 
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/zarafa.595f4f95.0ca2.541e22d26cae771f%40anjie.dontpanic.nl.
For more options, visit https://groups.google.com/d/optout.

Reply via email to