Skip to content

Instantly share code, notes, and snippets.

@pbrit
Created May 22, 2015 11:51
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 pbrit/69a96bdb079a50b01216 to your computer and use it in GitHub Desktop.
Save pbrit/69a96bdb079a50b01216 to your computer and use it in GitHub Desktop.
hash_join_dnsmasq
# Put in $module/lib/puppet/parser/functions/hash_join_dnsmasq.rb
module Puppet::Parser::Functions
newfunction(:hash_join_dnsmasq, :type => :rvalue, :arity => 2, :doc => <<-EOS
Take hash and string, join them for dnsmasq.
EOS
) do |arguments|
hash = arguments[0]
ip = arguments[1]
array = hash.map { |key, value| "#{key}/#{value}" }
array.zip(array.count.times.map { ip }).map { |el| el.join(',')}.join(',')
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment