diff --git a/chef/cookbooks/network/recipes/default.rb b/chef/cookbooks/network/recipes/default.rb index 43583ce57a..ccfa0531bd 100644 --- a/chef/cookbooks/network/recipes/default.rb +++ b/chef/cookbooks/network/recipes/default.rb @@ -119,24 +119,28 @@ def kill_nic(nic) # Ignore loopback interfaces for now. return if nic.loopback? - Chef::Log.info("Interface #{nic.name} is no longer being used, deconfiguring it.") - nic.destroy - + nicfiles = [] case node[:platform_family] when "rhel" # Redhat and Centos have lots of small files definining interfaces. # Delete the ones we no longer care about here. - if ::File.exists?("/etc/sysconfig/network-scripts/ifcfg-#{nic.name}") - ::File.delete("/etc/sysconfig/network-scripts/ifcfg-#{nic.name}") - end + nicfiles.push("/etc/sysconfig/network-scripts/ifcfg-#{nic.name}") when "suse" # SuSE also has lots of small files, but in slightly different locations. - if ::File.exists?("/etc/sysconfig/network/ifcfg-#{nic.name}") - ::File.delete("/etc/sysconfig/network/ifcfg-#{nic.name}") - end - if ::File.exists?("/etc/sysconfig/network/ifroute-#{nic.name}") - ::File.delete("/etc/sysconfig/network/ifroute-#{nic.name}") - end + nicfiles.push("/etc/sysconfig/network/ifcfg-#{nic.name}", + "/etc/sysconfig/network/ifroute-#{nic.name}") + end + + # Ignore unmanaged interfaces + nicfiles.each do |file| + next unless ::File.exist?(file) + return nil if system("fgrep", "-q", "#unmanaged", file) + end + Chef::Log.info("Interface #{nic.name} is no longer being used, deconfiguring it.") + nic.destroy + + nicfiles.each do |file| + ::File.delete(file) if ::File.exist?(file) end end