0

I'm trying to do a loop in puppet, I put this code in manifests/site.pp

class ubuntu_fw {
        ufw::allow { "allow-ssh-from-all":
          port => 22,
        }

        $trustips = ["1.1.1.1", "2.2.2.2"]

        $trustips.each |$trustip| {
                ufw::allow { "allow-all-from-trusted-$trustip":
                        from => $trustip,
                }
        }
}

But i get this error

"Could not parse for environment production: Syntax error at '.'; expected '}' at /opt/puppet/manifests/site.pp:13"

Using puppet 3.4.3

Cœur
  • 37,241
  • 25
  • 195
  • 267
BigLeo
  • 6,906
  • 2
  • 13
  • 12
  • Seems like this version of puppet doesn't support loops (details [here](http://stackoverflow.com/questions/6399922/are-there-iterators-and-loops-in-puppet)). – Maxim Dec 02 '15 at 13:21
  • 1
    You'd want to be using the `future` parser (https://docs.puppetlabs.com/puppet/3.8/reference/experiments_future.html) in order to take advantage of loops and other more advanced DSL features. – Evgeny Chernyavskiy Dec 02 '15 at 14:47
  • Thanks Evgeny! Enabling future works. – BigLeo Dec 02 '15 at 15:31

1 Answers1

0

As Evgeny said, loops, iteration and the like are available in Puppet 4. (New features documented here: https://docs.puppetlabs.com/references/4.0.0/function.html)

You can either make the major bump to 4.0 or enable the Future parser in Puppet > 3.7.3 to get a simulation of the newer syntax.

You can do this with the following:

  • Add --parser future to the cli when running puppet apply or puppet agent -t
  • Add parser = future to the main config section of puppet.conf

You can make the puppet.conf change with the following Puppet code

augeas { 'puppet.conf':
  context => '/files/etc/puppet/puppet.conf',
  changes => [
    'set main/parser future',
  ],
}
Peter Souter
  • 5,110
  • 1
  • 33
  • 62