Matthew Pounsett
2011-Feb-10 17:32 UTC
[Puppet Users] Complex data structures: working around a parser bug
A few days ago another user posted an issue with complex hashes[1]; it looks
like a parser bug, and a bug report was opened[2]. I seem to be having a
similar problem, but I haven''t been able to make the same workaround
function.
This is the data structure I''d like to be using, but puppet
doesn''t like the array nested inside a hash:
$dev_numbers = {
''null'' => {
''freebsd'' = [ 0, 6 ],
''ubuntu'' = [ 1, 3 ],
},
''random'' => {
''freebsd'' = [ 0, 12 ],
''ubuntu'' = [ 1, 8 ],
},
''zero'' => {
''freebsd'' = [ 0, 7 ],
''ubuntu'' = [ 1, 5 ],
},
}
--parseonly produces an error when checking this one
err: Could not parse for environment production: Syntax error at
''=''; expected ''}''
The alternative is to replace the array with a hash, like this:
$dev_numbers = {
''null'' => {
''freebsd'' => { ''major''
=> 0, ''minor'' => 6 },
''ubuntu'' => { ''major''
=> 1, ''minor'' => 3 },
},
''random'' => {
''freebsd'' => { ''major''
=> 0, ''minor'' => 12 },
''ubuntu'' => { ''major''
=> 1, ''minor'' => 8 },
},
''zero'' => {
''freebsd'' => { ''major''
=> 0, ''minor'' => 7 },
''ubuntu'' => { ''major''
=> 1, ''minor'' => 5 },
},
}
Puppet lets me define this data structure, but I can''t find a way to
access it.
If I use this:
$major = $dev_numbers[$type][$operatingsystem][''major'']
$minor = $dev_numbers[$type][$operatingsystem][''minor'']
then --parseonly gives me a syntax error:
err: Could not parse for environment production: Syntax error at
''[''; expected '']''
If I use the alternative proposed to the OP, which looks like this:
$device = $dev_numbers[$type][$operatingsystem]
$major = $device[''major'']
$minor = $device[''minor'']
then --parseonly passes everything, but when puppet actually tries to build the
catalog for the client it fails and logs this error:
device is not an hash or array when accessing it with major at...
Does anyone have any other suggestions for how to work around this problem with
the parser?
Thanks in advance!
Matt
[1]
<http://groups.google.com/group/puppet-users/browse_thread/thread/8840c275ca677cd9/58d7adea821fc49f>
[2] <http://projects.puppetlabs.com/issues/6269>
--
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.
Daniel Pittman
2011-Feb-13 20:31 UTC
Re: [Puppet Users] Complex data structures: working around a parser bug
On Thu, Feb 10, 2011 at 09:32, Matthew Pounsett <matt@conundrum.com>
wrote:
This works for me on 2.6.5rc2, which is before any of the recent
patching of the parser in the area:
$dev_numbers = {
''null'' => {
''freebsd'' => [ 0, 6 ],
''ubuntu'' => [ 1, 3 ],
},
''random'' => {
''freebsd'' => [ 0, 12 ],
''ubuntu'' => [ 1, 8 ],
},
''zero'' => {
''freebsd'' => [ 0, 7 ],
''ubuntu'' => [ 1, 5 ],
},
}
notice(inline_template("<%= dev_numbers.inspect %>"))
⚡ puppet apply ~/tmp/test.pp
notice: Scope(Class[main]):
{"random"=>{"freebsd"=>["0",
"12"],
"ubuntu"=>["1", "8"]},
"null"=>{"ubuntu"=>["1", "3"],
"freebsd"=>["0",
"6"]}, "zero"=>{"freebsd"=>["0",
"7"], "ubuntu"=>["1", "5"]}}
notice: Finished catalog run in 0.01 seconds
I think the mental trick is that you need to use ''=>'' to
separate the
key and value in a hash; it depends on the surrounding context, not
the type on the right hand side of the entry in the hash.
Regards,
Daniel
--
⎋ Puppet Labs Developer – http://puppetlabs.com
✉ Daniel Pittman <daniel@puppetlabs.com>
✆ Contact me via gtalk, email, or phone: +1 (877) 575-9775
♲ Made with 100 percent post-consumer electrons
--
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.