0
votes

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

1
Seems like this version of puppet doesn't support loops (details here). - Maxim
You'd want to be using the future parser (docs.puppetlabs.com/puppet/3.8/reference/…) in order to take advantage of loops and other more advanced DSL features. - Evgeny Chernyavskiy
Thanks Evgeny! Enabling future works. - Leonardo Cuquejo

1 Answers

0
votes

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',
  ],
}