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) -- Yo

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 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 >>       args[0].keys

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: /Stage[mai

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/fun

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 wrote: > Thanks guys > > I ended up breaking up what Felix&Ohad suggested into two lines to make it > work: > $keycsv= inline_template("<%= netifcfg.keys.join(',') %>") > $keys = split ($keycsv,',') > Yep, it's a 'hack' (sorry, Ohad, w

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 Felix&Ohad 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 Nigel Kersten
On Tue, Apr 19, 2011 at 8:08 PM, Nigel Kersten wrote: > On Tue, Apr 19, 2011 at 6:28 PM, Miki Shapiro 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 r

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 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. http://docs.puppetlabs.com/guides/custom_

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 n

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 n

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

2011-04-19 Thread Felix Frank
On 04/19/2011 09:09 AM, Ohad Levy wrote: > > > On Tue, Apr 19, 2011 at 8:42 AM, Miki Shapiro > 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 > tha

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 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 > "manually" defining $a

[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 => { ip