Re: [Puppet Users] Listing the keys in a hash as an array

2012-06-26 Thread Jon Jackson
I'm going to add to this thread because this function (keys - Returns the keys of a hash as an array ) and other similar utility functions are now just a download away in the puppet stdlib http://forge.puppetlabs.com/puppetlabs/stdlib (this page currently lists a few of the functions) --

Re: [Puppet Users] Listing the keys in a hash as an array

2011-04-20 Thread Felix Frank
module Puppet::Parser::Functions newfunction(:hash_keys, :type = :rvalue) do |args| unless args[0].is_a?(Hash) Puppet.warning hash_keys takes one argument, the input hash nil else args[0].keys end end end save to lib/puppet/parser/functions/ in a

Re: [Puppet Users] Listing the keys in a hash as an array

2011-04-20 Thread Thomas Bellman
On 2011-04-20 03:28, Miki Shapiro wrote: As suggested by Felix: Manifest says: $keys = split(,, inline_template(%= netifcfg.keys.join(',') %)) exec { /bin/echo keys are $keys and netifcfg is $netifcfg: logoutput = true } Output says: notice:

Re: [Puppet Users] Listing the keys in a hash as an array

2011-04-20 Thread Nigel Kersten
On Wed, Apr 20, 2011 at 12:17 AM, Felix Frank felix.fr...@alumni.tu-berlin.de wrote: module Puppet::Parser::Functions   newfunction(:hash_keys, :type = :rvalue) do |args|     unless args[0].is_a?(Hash)       Puppet.warning hash_keys takes one argument, the input hash       nil     else      

Re: [Puppet Users] Listing the keys in a hash as an array

2011-04-19 Thread Ohad Levy
On Tue, Apr 19, 2011 at 8:42 AM, Miki Shapiro mikishap...@gmail.com wrote: clunky and could probably be written better. My 2 questions are: 1. Can I somehow get a list of keys from the hash itself (a list that will behave like an array that I can feed into a defined type) instead of

Re: [Puppet Users] Listing the keys in a hash as an array

2011-04-19 Thread Miki Shapiro
I must be doing something wrong... As suggested by Ohad: Manifest says: $keys = inline_template(%= netifcfg.keys %) exec { /bin/echo keys are $keys and netifcfg is $netifcfg: logoutput = true } Output says: notice: /Stage[main]/Base::Network-common/Exec[/bin/echo keys are bond0bond1 and

Re: [Puppet Users] Listing the keys in a hash as an array

2011-04-19 Thread Miki Shapiro
I must be doing something wrong... As suggested by Ohad: Manifest says: $keys = inline_template(%= netifcfg.keys %) exec { /bin/echo keys are $keys and netifcfg is $netifcfg: logoutput = true } Output says: notice: /Stage[main]/Base::Network-common/Exec[/bin/echo keys are bond0bond1 and

Re: [Puppet Users] Listing the keys in a hash as an array

2011-04-19 Thread Nigel Kersten
On Tue, Apr 19, 2011 at 6:28 PM, Miki Shapiro mikishap...@gmail.com wrote: $keys = split(,, inline_template(%= netifcfg.keys.join(',') %)) Honestly, I'd put this together as a Puppet function at this point, as that's just resulting in something rather unmaintainable.

Re: [Puppet Users] Listing the keys in a hash as an array

2011-04-19 Thread Nigel Kersten
On Tue, Apr 19, 2011 at 8:08 PM, Nigel Kersten ni...@puppetlabs.com wrote: On Tue, Apr 19, 2011 at 6:28 PM, Miki Shapiro mikishap...@gmail.com wrote: $keys = split(,, inline_template(%= netifcfg.keys.join(',') %)) Honestly, I'd put this together as a Puppet function at this point, as that's

Re: [Puppet Users] Listing the keys in a hash as an array

2011-04-19 Thread Miki Shapiro
Thanks guys I ended up breaking up what FelixOhad suggested into two lines to make it work: $keycsv= inline_template(%= netifcfg.keys.join(',') %) $keys = split ($keycsv,',') Yep, it's a 'hack' (sorry, Ohad, workaround ;)), but it saves me having to add puppet functions into

Re: [Puppet Users] Listing the keys in a hash as an array

2011-04-19 Thread Ohad Levy
On Wed, Apr 20, 2011 at 7:46 AM, Miki Shapiro mikishap...@gmail.com wrote: Thanks guys I ended up breaking up what FelixOhad suggested into two lines to make it work: $keycsv= inline_template(%= netifcfg.keys.join(',') %) $keys = split ($keycsv,',') Yep, it's a 'hack'

[Puppet Users] Listing the keys in a hash as an array

2011-04-18 Thread Miki Shapiro
Hi all I've got node definition on the site with server interface, bonding and TCP/IP configurations inscribed in a per-node [ hash + accompanying array-of-interface-names ] (e.g. $array = [ 'eth0', 'eth1' ] $hash = { eth0 = { ipaddress = 1.2.3.4, ... } eth1 = {