I''m sure this is so simple I''m just not seeing it. I have an array of hashes of filenames & modes defined in hiera (the actual problem is a tad more complex, but for simplicity, if I can solve this, I can solve the bigger problem): files: - name: /etc/skel/.bashrc mode: 600 - name: /etc/sysctl.conf mode: 600 and so on. I then have a class which loads this hash and wants to execute a defined type for it, basically enforcing the mode for each file: define compliance::file { file { "$title": mode => ??? } } And that''s where I''m stuck -- how on earth do I get at the "mode" value of the array of hashes? Is there an easier way to do this that allows me to add additional hash keys for various files later? Thanks! -- 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+unsubscribe@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/puppet-users/b011caaf-98da-4a32-b370-0373f92ac5f8%40googlegroups.com. For more options, visit https://groups.google.com/groups/opt_out.
Gavin Williams
2013-Nov-13 14:47 UTC
[Puppet Users] Re: Accessing hash values in defined type
Bret Sounds like ''create_resources'' might be a good fit here... Take a look at http://four-eyes.net/2013/09/puppet-passing-a-hash-of-variables-to-a-defined-type/ Alternatively, if you can''t use ''create_resources'' you probably want to add a parameter to the defined type, and then use the indexing syntax as defined here: http://docs.puppetlabs.com/puppet/3/reference/lang_datatypes.html#hashes to call out specific keys from said parameter. HTH Gav On Wednesday, 13 November 2013 12:57:35 UTC, Bret Wortman wrote:> > I''m sure this is so simple I''m just not seeing it. I have an array of > hashes of filenames & modes defined in hiera (the actual problem is a tad > more complex, but for simplicity, if I can solve this, I can solve the > bigger problem): > > files: > - name: /etc/skel/.bashrc > mode: 600 > - name: /etc/sysctl.conf > mode: 600 > > and so on. > > I then have a class which loads this hash and wants to execute a defined > type for it, basically enforcing the mode for each file: > > define compliance::file { > file { "$title": > mode => ??? > } > } > > And that''s where I''m stuck -- how on earth do I get at the "mode" value of > the array of hashes? Is there an easier way to do this that allows me to > add additional hash keys for various files later? > > Thanks! > >-- 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+unsubscribe@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/puppet-users/2744222f-5ec9-4005-b116-cc8808f1782a%40googlegroups.com. For more options, visit https://groups.google.com/groups/opt_out.
Bret Wortman
2013-Nov-13 15:04 UTC
[Puppet Users] Re: Accessing hash values in defined type
Thanks. I''ll give that a look. I got it working like this: define compliance::file { $fmode=$title[''mode''] $fname=$title[''name''] file { $fname: path => $fname, mode => $fmode, } } And then I can reference it like this: compliance::file { $files: } But I''d like to find something cleaner. Thanks for the tip, Gavin. On Wednesday, November 13, 2013 9:47:15 AM UTC-5, Gavin Williams wrote:> > Bret > > Sounds like ''create_resources'' might be a good fit here... Take a look at > http://four-eyes.net/2013/09/puppet-passing-a-hash-of-variables-to-a-defined-type/ > > Alternatively, if you can''t use ''create_resources'' you probably want to > add a parameter to the defined type, and then use the indexing syntax as > defined here: > http://docs.puppetlabs.com/puppet/3/reference/lang_datatypes.html#hashesto call out specific keys from said parameter. > > HTH > Gav > > On Wednesday, 13 November 2013 12:57:35 UTC, Bret Wortman wrote: >> >> I''m sure this is so simple I''m just not seeing it. I have an array of >> hashes of filenames & modes defined in hiera (the actual problem is a tad >> more complex, but for simplicity, if I can solve this, I can solve the >> bigger problem): >> >> files: >> - name: /etc/skel/.bashrc >> mode: 600 >> - name: /etc/sysctl.conf >> mode: 600 >> >> and so on. >> >> I then have a class which loads this hash and wants to execute a defined >> type for it, basically enforcing the mode for each file: >> >> define compliance::file { >> file { "$title": >> mode => ??? >> } >> } >> >> And that''s where I''m stuck -- how on earth do I get at the "mode" value >> of the array of hashes? Is there an easier way to do this that allows me to >> add additional hash keys for various files later? >> >> Thanks! >> >>-- 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+unsubscribe@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/puppet-users/a725ae3a-bf95-4a07-af67-c849e3970075%40googlegroups.com. For more options, visit https://groups.google.com/groups/opt_out.