From 35b3a3aa873350908b2eba6799ca078992b77368 Mon Sep 17 00:00:00 2001
From: Steve Pye <spye@liquidcapital.com>
Date: Mon, 22 Feb 2021 14:52:14 +0000
Subject: [PATCH] macaddr for debian/suse

---
 manifests/interface.pp         | 22 +++++++++++++---------
 templates/interface/Debian.erb |  7 +++++--
 templates/interface/RedHat.erb |  4 ++--
 templates/interface/Suse.erb   |  7 +++++--
 4 files changed, 25 insertions(+), 15 deletions(-)

diff --git a/manifests/interface.pp b/manifests/interface.pp
index ef89d94..9bc1b96 100644
--- a/manifests/interface.pp
+++ b/manifests/interface.pp
@@ -14,10 +14,20 @@
 # [*ipaddress*]
 # [*netmask*]
 # [*broadcast*]
+#   String. Default: undef
+#   Standard network parameters
+#
 # [*hwaddr*]
+#   String. Default: undef
+#   - On RedHat: assigns this interface name to the device with this mac.
+#   - On Debian/Suse: spoofs mac address of the interface.
+#     (syntax may be broke on Debian. if so, try $macaddr).
+#   Do not use togehter with $macaddr.
+#
 # [*macaddr*]
 #   String. Default: undef
-#   Standard network parameters
+#   Spoofs mac address of the interface.
+#   Do not use together with $hwaddr.
 #
 # [*enable*]
 #   Boolean. Default: true
@@ -115,12 +125,6 @@
 #    configure the ipv4 address of the interface.
 #    If both are present ipaddr is used.
 #
-#  $hwaddr        = undef,
-#    hwaddr if set assigns this interface to the device with this mac.
-#
-#  $macaddr       = undef,
-#    macaddr if set spoofs the mac address of the interface.
-#
 #  $prefix        = undef,
 #    Network PREFIX aka CIDR notation of the network mask. The PREFIX
 #    takes precedence if both PREFIX and NETMASK are set.
@@ -575,8 +579,8 @@ define network::interface (
     fail('Use either netmask or prefix to define the netmask for the interface')
   }
 
-  $manage_hwaddr = $hwaddr ? {
-    default => $hwaddr,
+  if $hwaddr != undef and $macaddr != undef {
+    fail('HWADDR and MACADDR cannot be used together')
   }
 
   $manage_method = $method ? {
diff --git a/templates/interface/Debian.erb b/templates/interface/Debian.erb
index 6c2b3e3..b1489ec 100644
--- a/templates/interface/Debian.erb
+++ b/templates/interface/Debian.erb
@@ -12,8 +12,11 @@ allow-hotplug <%= @interface %>
 <% if @manage_address and ! @manage_address.empty? -%>
     address <%= @manage_address %>
 <% end -%>
-<% if @manage_hwaddr -%>
-    hwaddress <%= @manage_hwaddr %>
+<% if @hwaddr -%>
+    hwaddress <%= @hwaddr %>
+<% end -%>
+<% if @macaddr -%>
+    hwaddress ether <%= @macaddr %>
 <% end -%>
 <% if @netmask -%>
     netmask <%= @netmask %>
diff --git a/templates/interface/RedHat.erb b/templates/interface/RedHat.erb
index e9cb5df..4d52567 100644
--- a/templates/interface/RedHat.erb
+++ b/templates/interface/RedHat.erb
@@ -97,8 +97,8 @@ GATEWAY="<%= @gateway %>"
 <% if @manage_defroute -%>
 DEFROUTE="<%= @manage_defroute %>"
 <% end -%>
-<% if @manage_hwaddr -%>
-HWADDR="<%= @manage_hwaddr %>"
+<% if @hwaddr -%>
+HWADDR="<%= @hwaddr %>"
 <% end -%>
 <% if @macaddr -%>
 MACADDR="<%= @macaddr %>"
diff --git a/templates/interface/Suse.erb b/templates/interface/Suse.erb
index 7674fbe..1cee4f6 100644
--- a/templates/interface/Suse.erb
+++ b/templates/interface/Suse.erb
@@ -32,8 +32,11 @@ MTU="<%= @mtu %>"
 <% if @vlan -%>
 VLAN_ID="<%= @vlan %>"
 <% end -%>
-<% if @manage_hwaddr -%>
-LLADDR="<%= @manage_hwaddr %>"
+<% if @hwaddr -%>
+LLADDR="<%= @hwaddr %>"
+<% end -%>
+<% if @macaddr -%>
+LLADDR="<%= @macaddr %>"
 <% end -%>
 <% if @bridge -%>
 BRIDGE="<%= @bridge %>"
-- 
GitLab