Search code examples
syntax-erroreachpuppet

Puppet: Syntax error with '$x.each...'


I have the code below:

define keepalived::vrrp_instance(
  $state,
  $interface,
  $virtual_addresses,
  $virtual_router_id,
  $priority      = $::keepalived::params::priority,
  $advert_int    = $::keepalived::params::advert_int,
  $password      = $::keepalived::params::password,
  $notify_master = $::keepalived::params::notify_master,
  $notify_backup = $::keepalived::params::notify_backup,
  $notify_fault  = $::keepalived::params::notify_fault,
  $notify_all    = $::keepalived::params::notify_all,
  $smtp_alert    = $::keepalived::params::smtp_alert,
) {
  ...
  $virtual_addresses.each |$address| {
    $splitted_address = split($address,' ')
    if  !is_ip_address($splitted_address[0]) {
      fail("Error virtual_address Value: \"${address}\" not an ip address!")
    }
  }
  ...
}

$virtual_addresses is something like ['127.0.0.1 dev eth0','fd00::1 dev eth0']

Running the code I get the following error:

Syntax error at '.'; expected '}' at /etc/puppet/environments/ip6_dev/modules_custom/keepalived/manifests/vrrp_instance.pp:136 on node

Line 136 is "$virtual_addresses.each |$address| {"

I can't find a mistake (https://docs.puppetlabs.com/references/3.stable/function.html#each)

I am using Puppet 3.3.2


Solution

  • "note requires parser = future"

    Ensure you are using future parser in puppet. Set parser = future in your puppet.conf file or add the command line switch --parser=future

    UPDATE: Wrap your verification function:

    define verify::wrapper ()
    {
        $ip_address = split($name,' ')
        if  !is_ip_address("${ip_address[0]}") {
            fail("Error virtual_address Value:  \"${ip_address[0]}\" not an ip address!")
        }
    }
    

    Next use it:

    define keepalived::vrrp_instance(...)
    {
        ...
        verify::wrapper{ $virtual_addresses : }
        ...
    }