On 11/30/2010 09:05 PM, Jay Almers wrote:> Hello all,
>
> I am a new user to Puppet (system and language) and have a question
> regarding hashes and iterating through them in a definition. What I
> am trying to do is specify a multi-dimensional hash on a particular
> node, pass this hash to a define, and recursively do "stuff"
using the
> key/value pairs. Any help would be appreciated.
>
> Here is an example of what I am trying to do:
>
> /* IN SITE.PP */
> $myHash = {
> frank => { hairColor => "brown", eyeColor =>
"hazel" },
> bob => { hairColor => "blonde", eyeColor =>
"blue" }.
> john => { hairColor => "red", eyeColor =>
"green" }
> }
>
> do_stuff {"Doing Stuffs": people => $myHash }
>
> /* IN CLASS FILE */
> define do_stuff (people="") {
> # FOR EACH people, "..." represents what I am wanting to
dynamically
> loop through
> notify { people[...][eyeColor]: }
> }
>
This is not what hashes are intended for. Instead, you want to use plain
old define:
define do_stuff($hairColor, $eyeColor) {
notify { "Person $name has $hairColor hair and $eyeColor eyes.": }
}
do_stuff {
frank: { hairColor => "brown", eyeColor => "hazel"
};
bob: { hairColor => "blonde", eyeColor => "blue"
};
john: { hairColor => "red", eyeColor => "green" };
}
If you MUST use a hash, you will need another array with the keys only.
$keys = [ frank, bob, john ]
define do_stuff() {
notify { "Person $name has $people[$name][hairColor] ...
}
do_stuff { $keys: }
HTH,
Felix
--
You received this message because you are subscribed to the Google Groups
"Puppet Users" group.
To post to this group, send email to puppet-users@googlegroups.com.
To unsubscribe from this group, send email to
puppet-users+unsubscribe@googlegroups.com.
For more options, visit this group at
http://groups.google.com/group/puppet-users?hl=en.