summaryrefslogtreecommitdiff
path: root/puppet/modules/site_config
diff options
context:
space:
mode:
authorChristoph Kluenter <ckluente@thoughtworks.com>2014-09-29 13:53:39 +0200
committerChristoph Kluenter <ckluente@thoughtworks.com>2014-09-29 13:53:39 +0200
commit1071c3622469b7b02dd3b772070db540b6842dfb (patch)
tree5b9c262be0007c741f5a4cac343c84ff6bca70e0 /puppet/modules/site_config
parentd04bc91a176ea4a88e8291f8a374df55b77fdc23 (diff)
new fact to check if dhcp is used;
from https://github.com/gds-operations/puppet-resolvconf/blob/master/lib/facter/dhcp_enabled.rb
Diffstat (limited to 'puppet/modules/site_config')
-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