From f7c2f160b46cc94f68e144d922230176870a074d Mon Sep 17 00:00:00 2001 From: Martin Millnert Date: Fri, 29 Jan 2016 12:17:44 +0100 Subject: [PATCH] network::if::static: Add VLAN capability Adds missing VLAN capability to network::if::static. The existing documentation for using VLAN:s on static interfaces says to instantiate network::global with the parameter vlan set to yes, such as: class{'network::global': vlan => 'yes' } This isn't sufficient. ifcfg-$ifname requires also the parameter 'VLAN=yes' defined, for a VLAN interface. With this approach, that parameter is explicitly defined to network::static::if, such as: 'network::static::if' { 'eth0.330': ensure => 'up', vlan => true, ipaddress => '10.2.3.248', netmask => '255.255.255.0', } This makes it abundandly clear what's going on. --- README.md | 1 + manifests/if/static.pp | 3 +++ manifests/init.pp | 6 ++++++ templates/ifcfg-eth.erb | 2 ++ 4 files changed, 12 insertions(+) diff --git a/README.md b/README.md index 72c0b769..0fb59c90 100644 --- a/README.md +++ b/README.md @@ -218,6 +218,7 @@ Normal interface - VLAN - static (minimal): network::if::static { 'eth0.330': ensure => 'up', + vlan => true, ipaddress => '10.2.3.248', netmask => '255.255.255.0', } diff --git a/manifests/if/static.pp b/manifests/if/static.pp index 09f1ca4a..5d039655 100644 --- a/manifests/if/static.pp +++ b/manifests/if/static.pp @@ -53,6 +53,7 @@ $ipaddress, $netmask, $gateway = undef, + $vlan = false, $ipv6address = undef, $ipv6init = false, $ipv6gateway = undef, @@ -83,6 +84,7 @@ $macaddy = $macaddress } # Validate booleans + validate_bool($vlan) validate_bool($userctl) validate_bool($ipv6init) validate_bool($ipv6autoconf) @@ -96,6 +98,7 @@ ipv6address => $ipv6address, netmask => $netmask, gateway => $gateway, + vlan => $vlan, ipv6gateway => $ipv6gateway, ipv6autoconf => $ipv6autoconf, macaddress => $macaddy, diff --git a/manifests/init.pp b/manifests/init.pp index ff3cbbcf..0088fdc8 100644 --- a/manifests/init.pp +++ b/manifests/init.pp @@ -100,6 +100,7 @@ $netmask, $macaddress, $gateway = undef, + $vlan = false, $ipv6address = undef, $ipv6gateway = undef, $ipv6init = false, @@ -123,6 +124,7 @@ $check_link_down = false ) { # Validate our booleans + validate_bool($vlan) validate_bool($userctl) validate_bool($isalias) validate_bool($peerdns) @@ -165,6 +167,10 @@ 'down' => 'no', default => undef, } + $vlanyes = $vlan ? { + true => 'yes', + default => undef, + } $iftemplate = template('network/ifcfg-eth.erb') } diff --git a/templates/ifcfg-eth.erb b/templates/ifcfg-eth.erb index 3f17d2d1..1590a484 100644 --- a/templates/ifcfg-eth.erb +++ b/templates/ifcfg-eth.erb @@ -8,6 +8,8 @@ BOOTPROTO=<%= @bootproto %> ONBOOT=<%= @onboot %> HOTPLUG=<%= @onboot %> TYPE=Ethernet +<% if @vlanyes %>VLAN=<%= @vlanyes %> +<% end -%> <% if @ipaddress and @ipaddress != '' %>IPADDR=<%= @ipaddress %> <% end -%> <% if @netmask and @netmask != '' %>NETMASK=<%= @netmask %>