Hi Henrik,
On 26 Aug 2015, at 17:49, Henrik Lindberg <[email protected]>
wrote:
> On 2015-24-08 14:38, Martin Alfke wrote:
>> Hi,
>>
>> I am playing around with the Puppet 4 Type system and nested hashes.
>> Is it possible to use the Type system on a hash and check sub hashes as
>> Struct?
>>
> Yes, certainly.
>
>> # nested hashes
>> $hash = {
>> ‘ben’ => {
>> uid => 2204,
>> home => ‘/home/ben’,
>> },
>> ‘jones’ => {
>> uid => 2205,
>> home => ‘home/jones’,
>> }
>> }
>>
>> # class definition
>> class users (
>> Hash[String, Struct[{ uid => Integer, home => Pattern[/^\/.*/]}]] $hash,
>> ){
>> …
>> }
> …
> That is because you cannot match integer values (such as 2204) with a Pattern
> (it only matches strings).
??
Hash[String, Struct[{ uid => Integer, home => Pattern[/^\/.*/]}]] $hash
Am I missing something?
Within the Struct I provide the key name (uid) and Type (Integer) and the
second key (home) with Type (Pattern).
>
>> Within class users I could use the keys function and a define and check for
>> the data types within the define.
>> But I thought that the mentioned approach is valid (at least I haven’t found
>> a hint that my approach is not valid).
>>
>
> Your approach is valid, you just got tripped up by Integer values not
> matching with a Pattern.
Good to know…
Many thanks,
Martin
--
You received this message because you are subscribed to the Google Groups
"Puppet Developers" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/puppet-dev/A2EA5C24-EA56-4B60-BFD7-EAF440B2FC6A%40gmail.com.
For more options, visit https://groups.google.com/d/optout.