On 10/08/16 18:28,
pokemon.mas...@gmail.com wrote:
> I'm relatively new to puppet but I used hiera_hash to lookup what I
> would consider a "hash" in yaml.
>
> The data I tested with is rather complex in nature but it basically
> boils down to a hash of hashes with sub hashes / arrays.
>
> Ex: (my hieradata yaml file, pardon the lack of creativity in the names)
> |
> stuff:
> FirstNamedStuff:
> foo:bar
> foo2:
> -bara
> -barb
> foo3:
> anotherthing:hi
> yetanotherthing:hi2
> |
>
> Puppet (v4.3.2) is returning it as a struct (ex:
> Struct[{FirstNamedStuff => Struct[] }] ) when I was expecting it to be
> returned as a hash. I'm using functions written in puppet (not be
> confused with puppet functions written in ruby which if you google is
> what you'll get mostly) with type information for my parameter. I pass
> in this value gotten from hiera_hash("stuff") to my custom function but
> it fails because it expected a hash and instead received a struct.
>
A Struct data type is a Hash, only with more details about the keys and
the type of the value per key.
> Ex:
>
> |
> functionmodule::get_foo(Hash[String,Struct[{
> foo =>String,
> foo2 =>Array[String]
> foo3 =>Hash[String,String]
> }]$myvar)
> {
> }
> |
>
>
> I think what's happening is hiera is /always/ being treated as a struct
> for any hash. I assumed they were interchangeable but it doesn't look
> like they are.
>
They are.
> There are some cases where I want to enforce a hash, there are other
> cases where I want to enforce a struct. Ex:
>
> FirstNameStuff for instance might be user defined, it could be
> anything. But foo, foo2, foo3 are all properties that I expect and so a
> struct makes sense. foo3's properties might be userdefined so a hash
> makes sense.
>
You can use Hash or Struct - a Hash[String, Any] would allow any data
that has string keys.
The Hash type applies the same key and value data type rule for all
entries, the Struct allows you to define the value types specifically
per key, as well as the optionality of the keys (missing entries).
>
> So the question is, can I somehow get this functionality from hieradata
> and a custom function? Maybe this is just a bug with 4.3.2? Or is my
> only hope to strip off the type information?
>
There have been some bugs in the type system that have been fixed. It
may be that you are bitten by one of those. Some examples are needed of
actual input and error messages to be able to tell.
Hope that helps.
- henrik
> --
> You received this message because you are subscribed to the Google
> Groups "Puppet Users" group.
> To unsubscribe from this group and stop receiving emails from it, send
> an email to
puppet-users...@googlegroups.com
> <mailto:
puppet-users...@googlegroups.com>.
> To view this discussion on the web visit
>
https://groups.google.com/d/msgid/puppet-users/21d19acd-b054-41eb-9c56-da1d6c6bfd44%40googlegroups.com
> <
https://groups.google.com/d/msgid/puppet-users/21d19acd-b054-41eb-9c56-da1d6c6bfd44%40googlegroups.com?utm_medium=email&utm_source=footer>.
> For more options, visit
https://groups.google.com/d/optout.
--
Visit my Blog "Puppet on the Edge"
http://puppet-on-the-edge.blogspot.se/