Last active
April 11, 2017 15:33
-
-
Save joaquin386/6c4355631668285867979bef94c45d54 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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