]> git.openstreetmap.org Git - chef.git/blobdiff - cookbooks/networking/libraries/ipaddresses.rb
Add a load more cookbooks
[chef.git] / cookbooks / networking / libraries / ipaddresses.rb
diff --git a/cookbooks/networking/libraries/ipaddresses.rb b/cookbooks/networking/libraries/ipaddresses.rb
new file mode 100644 (file)
index 0000000..811c818
--- /dev/null
@@ -0,0 +1,25 @@
+class Chef
+  class Node
+    def ipaddresses(options = {}, &block)
+      addresses = []
+
+      interfaces(options).each do |interface|
+        if block.nil?
+          addresses << interface[:address]
+        else
+          block.call(interface[:address])
+        end
+      end
+
+      addresses
+    end
+
+    def internal_ipaddress
+      return ipaddresses(:role => :internal).first
+    end
+
+    def external_ipaddress
+      return ipaddresses(:role => :external).first
+    end
+  end
+end