Skip to content

Instantly share code, notes, and snippets.

@joaquin386
Last active April 11, 2017 15:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save joaquin386/6c4355631668285867979bef94c45d54 to your computer and use it in GitHub Desktop.
Save joaquin386/6c4355631668285867979bef94c45d54 to your computer and use it in GitHub Desktop.
require 'netaddr' ##Version Puppet 3.8.7
module Puppet::Parser::Functions
newfunction(:ip_2_network, :type => :rvalue) do |args|
## receive the 192.168.10.100/24 ip adderss
definition = args[1]
cidr = NetAddr::CIDR.create(args[0])
if definition == 'ip'
result = cidr.ip
elsif definition == 'network'
result = cidr.network
elsif definition == 'cidr'
result = cidr.to_s
end
result
end
end
Using in manisfest as:
$var = ip_2_network("192.168.10.100/24", "ip")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment