summaryrefslogtreecommitdiff
path: root/puppet/modules/site_config/lib
diff options
context:
space:
mode:
authorMicah Anderson <micah@leap.se>2015-01-06 12:30:00 -0500
committerMicah Anderson <micah@leap.se>2015-01-06 12:30:00 -0500
commit3d2c6f315e99ad4fb9ceac9f392b7eab27f924aa (patch)
treed725470402edfa0eca3ae5e5094dbc6b26d14b0a /puppet/modules/site_config/lib
parentbd098f1691307685958d4a07caba9812c025e163 (diff)
parentd063e35d3e29b3cedc810b8e5ca1855c841d8f9e (diff)
Merge remote-tracking branch 'cz8s/check_dhcp' into develop (#6610)
Diffstat (limited to 'puppet/modules/site_config/lib')
-rw-r--r--puppet/modules/site_config/lib/facter/dhcp_enabled.rb22
1 files changed, 22 insertions, 0 deletions
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