example42/puppet-network

Syntax Error on Ubuntu 16.04 for rule and route if-up scripts

AndrewLipscomb opened this issue · 1 comments

Expected Behavior

Repeatable scripts that can be generated using the network::route and network::rule elements. This may be resolvable with formatting options from ip but AFAIK there are no such options.

Actual Behavior

Scripts are not repeatable due to bash/grep formatting

Two examples

  network::route { 'local_net_routes':
    interface => 'br0',
    ipaddress => [ '0.0.0.0', "192.168.50.0" ],
    netmask   => [ '0.0.0.0', '255.255.255.0' ],
    gateway   => [ '192.168.50.1', false ],
    source    => [ false, '192.168.50.39', ],
    table     => [ 'wifi', 'wifi', ],
  }

makes

if [ "$IFACE" = "br0" ] || [ "$IFACE" = "--all" ]; then
  if ! ip route show  table wifi | grep -qF "0.0.0.0/0 "
  then
    ip route add 0.0.0.0/0.0.0.0 via 192.168.50.1 dev br0 table wifi
  fi
  if ! ip route show  table wifi | grep -qF "192.168.50.0/24 "
  then
    ip route add 192.168.50.0/255.255.255.0 dev br0 src 192.168.50.39 table wifi
  fi
fi

then ip route show table wifi shows

default via 192.168.50.1 dev br0 
192.168.50.0/24 dev br0  scope link  src 192.168.50.39

Note the default and not 0.0.0.0/0.0.0.0. Admittedly I could format this better in the Puppet declaration

For network::rule

  network::rule { 'local_net_rules':
    interface => 'br0',
    iprule    => [
      "from 192.168.50.39 priority 30000 table wifi",
      "to 192.168.50.39 priority 30001 table wifi"
    ],
  }
if [ "$IFACE" = "br0" ] || [ "$IFACE" = "--all" ]; then
  if ! ip rule show | grep -qF "from 192.168.50.39 priority 30000 table wifi"
  then
    ip  rule add from 192.168.50.39 priority 30000 table wifi
  fi
  if ! ip rule show | grep -qF "to 192.168.50.39 priority 30001 table wifi"
  then
    ip  rule add to 192.168.50.39 priority 30001 table wifi
  fi
fi

then ip rule show gives

0:	from all lookup local 
30000:	from 192.168.50.39 lookup wifi 
30001:	from all to 192.168.50.39 lookup wifi 
32766:	from all lookup main 
32767:	from all lookup default 

Note the grep string can never be found.

Specifications

os => {
  architecture => "amd64",
  distro => {
    codename => "xenial",
    description => "Ubuntu 16.04.5 LTS",
    id => "Ubuntu",
    release => {
      full => "16.04",
      major => "16.04"
    }
  },
  family => "Debian",
  hardware => "x86_64",
  name => "Ubuntu",
  release => {
    full => "16.04",
    major => "16.04"
  },
  selinux => {
    enabled => false
  }
}

Published v3.5.2 to the Forge with the fix, sorry for latency