Ask Your Question
0

Get key and value of a hash passed to a module from the site.pp class when declaring the class

asked 2014-09-25 07:19:24 -0500

gideonmaina gravatar image

I have classes that I would like them to receive hashes as declaration arguments for the node they are in but need to get the key and the value of the hash separately and then manipulate them to do what I want. Let me elaborate on this

     node 'node' {
           hash => {
                    "hash key "  => "value" or
                    "hash key" => ["value1","value2"]
                }
          }

Then in the target class I can have the following

           resource_type { "hash key":
                        attribute => "value" or
                       attribute => ["value1","value2"]
         }

Is it possible If so guidance is welcome and if not any workarounds are welcome ...This would be greatly appreciated

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
1

answered 2014-09-28 03:43:06 -0500

jonn gravatar image

I'm not sure if I've understood exactly what you want to do here, but maybe this would be a good use case for hiera? If you use hiera to store your hash, it is easy to refer to it in modules - if you use the right naming convention, the lookup in hiera will even be done automatically by Puppet.

The great thing about hiera is that you can specify the hash contents based on any fact - this could be something very general (e.g. the operating system) or, as in your example above, something very specific to the node (e.g. the hostname).

edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower

Stats

Asked: 2014-09-25 03:15:50 -0500

Seen: 254 times

Last updated: Sep 28 '14