Skip to content

Instantly share code, notes, and snippets.

@opennetadmin
Created April 12, 2012 15:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save opennetadmin/2368581 to your computer and use it in GitHub Desktop.
Save opennetadmin/2368581 to your computer and use it in GitHub Desktop.
Puppet template to calculate the base subnet IP from an IP/MASK input
<%
# This portion simply calculates the baseip from the ip/mask
baseip=""
addr_parts = scope.lookupvar("ipaddress").split('.')
mask_parts = scope.lookupvar("netmask").split('.')
addr_parts.zip((0..addr_parts.size).to_a).map do |n,i|
baseip += (n.to_i & mask_parts[i].to_i).to_s + "."
end
baseip = baseip[0..-2]
-%>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment