Puppet Function: strip_ports
- Defined in:
- lib/puppet/parser/functions/strip_ports.rb
- Function type:
- Ruby 3.x API
Overview
Take an Array
of items that may contain port numbers and
appropriately return the non-port portion. Works with hostnames, IPv4, and
IPv6.
2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/puppet/parser/functions/strip_ports.rb', line 2 newfunction(:strip_ports, :type => :rvalue, :doc => <<-EOM) do |args| raise Puppet::ParseError, "You must pass a list of hosts." if args.empty? Take an `Array` of items that may contain port numbers and appropriately return the non-port portion. Works with hostnames, IPv4, and IPv6. @example $foo = ['https://mysite.net:8443', 'http://yoursite.net:8081', 'https://theirsite.com'] $bar = strip_ports($foo) $bar contains: ['https://mysite.net','http://yoursite.net','theirsite.com'] @param hosts [Array[String]] `Array` of hostnames which may contain port numbers. @return [Array[String]] EOM Puppet::Parser::Functions.autoloader.loadall hosts = Array(args).flatten stripped_hosts = function_parse_hosts([hosts]).keys.uniq stripped_hosts.uniq end |