Thanks R.I.

So iteration works with 3.8x with future parser. I am going to avoid 4 
until Debian builds it into their repositories.

So iteration works but not with file_line.. 

Here is the code.

hiera array
mod1::testdefs:
  - 'hello'
  - 'there'
  - 'friends'
##mod1  init.pp
each($testdefs) |$hline| {
   file_line { 'Append a line to /etc/testfile':
      ensure => present,
      line      => $hline,
       path    => '/etc/testfile',
    }
}


##error is this
Error: Could not retrieve catalog from remote server: Error 400 on SERVER: 
Evaluation Error: Error while evaluating a Resource Statement, Duplicate 
declaration: File_line[Append a line to /etc/testfile] is already declared 
in file /etc/puppet/environments/test/modules/mod1/manifests/init.pp:48; 
cannot redeclare at 
/etc/puppet/environments/test/modules/mod1/manifests/init.pp:48

I tried putting the loop in the file_line type but that throws another 
error since it is not acceptable to file_line.

Is there any way around this that you guys are aware of?

Thanks

On Saturday, December 31, 2016 at 10:05:49 PM UTC-7, Joe wrote:
>
> Hi All
>
> Puppet v3.8.7 community on Ubuntu 14 LTS
>
> I have been attempting to write a class to use the "file_line" type 
> reference from the stdlib library to add multiple lines to a file if these 
> lines are not present. 
> I was attempting to do this with iteration using the each function and 
> tried with static and Hiera arrays. After a few hours of failure I came 
> across the docs for Puppet Enterprise that say this iteration capability 
> was introduced in Puppet 4.
>
> It looks like this, testdefs is an array in Hiera defined in the nodes 
> yaml config
>
>  each($testdefs) |$hline| {
>    file_line { 'Append a line to /etc/testfile':
>       ensure => present,
>       line      => "$hline",
>        path    => '/etc/testfile',
>     }
> }
>
> To be clear I am trying to.. 
> iterate through a Hiera array 
> pass each array member to the file_line type 
> append this member to a file if it does not exist.  
>
> Is there a way to do this with Puppet 3.x or should I just make a static 
> class with multiple file_line types?
>
> Thanks
>
>
>

-- 
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 puppet-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/puppet-users/4912ca68-64e4-48d7-906e-923b70aabaa3%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to