From 1071c3622469b7b02dd3b772070db540b6842dfb Mon Sep 17 00:00:00 2001 From: Christoph Kluenter Date: Mon, 29 Sep 2014 13:53:39 +0200 Subject: new fact to check if dhcp is used; from https://github.com/gds-operations/puppet-resolvconf/blob/master/lib/facter/dhcp_enabled.rb --- .../modules/site_config/lib/facter/dhcp_enabled.rb | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 puppet/modules/site_config/lib/facter/dhcp_enabled.rb (limited to 'puppet/modules/site_config/lib') diff --git a/puppet/modules/site_config/lib/facter/dhcp_enabled.rb b/puppet/modules/site_config/lib/facter/dhcp_enabled.rb new file mode 100644 index 00000000..33220da3 --- /dev/null +++ b/puppet/modules/site_config/lib/facter/dhcp_enabled.rb @@ -0,0 +1,22 @@ +require 'facter' +def dhcp_enabled?(ifs, recurse=true) + dhcp = false + included_ifs = [] + if FileTest.exists?(ifs) + File.open(ifs) do |file| + dhcp = file.enum_for(:each_line).any? do |line| + if recurse && line =~ /^\s*source\s+([^\s]+)/ + included_ifs += Dir.glob($1) + end + line =~ /inet\s+dhcp/ + end + end + end + dhcp || included_ifs.any? { |ifs| dhcp_enabled?(ifs, false) } +end +Facter.add(:dhcp_enabled) do + confine :osfamily => 'Debian' + setcode do + dhcp_enabled?('/etc/network/interfaces') + end +end -- cgit v1.2.3