Ask Your Question

I am getting a array value from extlookup and need to loop through it to add multiple lines to a file. But getting syntax error.

asked 2016-07-19 11:13:49 -0500

Arpitha gravatar image

updated 2016-07-25 00:20:44 -0500

ramindk gravatar image

define zoocfgloop ($zoocfg){ foreach $zoocfg { file {"/etc/zookeeper/zoo.cfg": content => "$zoo_cfg"; } } }

I need to add multiple lines to the file zoo.cfg and getting that value from csv, so I tried the above syntax, because I am using puppet 3.8.6. But its throwing the below error at foreach line.:

Syntax error at '{'; expected '}' at /etc/puppet/environments/Caf_Identity_Management/modules/mesos/manifests/master.pp:103

Update: I added parser = future in puppet.conf, still getting the same error.

file_line { 'Append a line to /etc/puppet/puppet.conf':
  path => '/etc/puppet/puppet.conf',
  line => "parser = future",

define zoo_cfg_loop(

  foreach $zoo_cfg {
    file_line { 'Append a line to /etc/zookeeper/zoo.cfg':
      path => '/etc/zookeeper/zoo.cfg',
      line => "$zoo_cfg",
      require => File_line['Append a line to /etc/puppet/puppet.conf'],

Even the below syntax is not working:

# function call with lambda:
  $zoo_cfg.each |String $zoo_cfg| {
  file_line { 'Append a line to /etc/zookeeper/zoo.cfg':
    path => '/etc/zookeeper/zoo.cfg',
    line => "$zoo_cfg",

Any help will be highly appreciated.

edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted

answered 2016-07-19 21:15:21 -0500

DarylW gravatar image

foreach is not valid puppet 3.x syntax. you could only use it if you have the future parser enabled.

edit flag offensive delete link more


So if I set parser=future in environment.conf, I could use this syntax for looping as well? $binaries.each |String $binary| as given ?

Arpitha gravatar imageArpitha ( 2016-07-20 09:42:25 -0500 )edit

While I was editing your post so the code was more readable, I noticed something.. I don't think having a semicolin at the end of your content parameter is valid syntax, it should be a comma.

DarylW gravatar imageDarylW ( 2016-07-20 19:07:04 -0500 )edit

There is no semicolon now, the one I updated yesterday is a valid syntax right? Still I cant understand why I am getting syntax error. Could you kindly help me with this?

Arpitha gravatar imageArpitha ( 2016-07-21 09:56:15 -0500 )edit

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower


Asked: 2016-07-19 11:13:49 -0500

Seen: 75 times

Last updated: Jul 25 '16