Puppet Function: get_ports
- Defined in:
- lib/puppet/parser/functions/get_ports.rb
- Function type:
- Ruby 3.x API
Overview
Take an Array
of items that may contain port
numbers and appropriately return the 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 |
# File 'lib/puppet/parser/functions/get_ports.rb', line 2 newfunction(:get_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 `port` portion. Works with hostnames, IPv4, and IPv6. @example $foo = ['https://mysite.net:8443','http://yoursite.net:8081'] $bar = strip_ports($foo) $bar contains: ['8443','8081'] @return [Array[String]] EOM Puppet::Parser::Functions.autoloader.loadall hosts = Array(args).flatten parsed_hosts = function_parse_hosts([hosts]) ports = [] for key in parsed_hosts.keys ports << parsed_hosts[key][:ports] if not parsed_hosts[key][:ports].nil? end ports.flatten.uniq end |