Hi all, I am trying to understand how does hiera puppet backend work, so I created the following example: hiera.yaml has only: --- :backends: - puppet --- And the node: node ''testnode'' { $variable = ''kk'' $thing = hiera ("variable") notify { "note: $thing": } } I don''t want to use the yaml backend for now, just want to grab variables from within puppet. But then I run the agent, and it "Could not find data item variable in any Hiera data file". This probably means I am completely lost. I did not put any hierarchy, because I don''t want to use the yaml backend, and I don''t know why else would I need it. Could anyone shed some light on me, please? Thanks, Pablo -- 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.
Hi Pablo, The Puppet backend accepts a ''datasource'' parameter whose value will be the class name for where it will look for Puppet variables. Take my hiera.yaml for example: --- :backends: - puppet :puppet: :datasource: data I''m telling it to look for a <modulename>::data class, and to check within that class for Puppet variables. Given that setup, I can do the following: # <modulepath>/puppetbackend/manifests/init.pp class puppetbackend { $stuff = hiera(''variable'') notify { "Stuff is: ${stuff}": } } # <modulepath>/puppetbackend/manifests/data.pp class puppetbackend::data { $variable = ''foo'' } Then if I run: " puppet apply -v -e ''include puppetbackend'' " I will get: notice: Stuff is: foo notice: /Stage[main]/Puppetbackend/Notify[Stuff is: foo]/message: defined ''message'' as ''Stuff is: foo'' notice: Finished catalog run in 0.06 seconds Does that help you out? On Sat, Mar 17, 2012 at 2:29 AM, Pablo Fernandez <pablo.fernandez@cscs.ch>wrote:> ** > > Hi all, > > > > I am trying to understand how does hiera puppet backend work, so I created > the following example: > > > > hiera.yaml has only: > > --- > > :backends: > > - puppet > > > > --- > > > > And the node: > > node ''testnode'' { > > $variable = ''kk'' > > $thing = hiera ("variable") > > notify { "note: $thing": } > > } > > > > I don''t want to use the yaml backend for now, just want to grab variables > from within puppet. But then I run the agent, and it "Could not find data > item variable in any Hiera data file". > > > > This probably means I am completely lost. I did not put any hierarchy, > because I don''t want to use the yaml backend, and I don''t know why else > would I need it. > > > > Could anyone shed some light on me, please? > > > > Thanks, > Pablo > > -- > 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. >-- Gary Larizza Professional Services Engineer Puppet Labs -- 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.
Thanks for the hint! Let me ask you a couple of questions: - Does the "puppetbackend::data" have to be imported by the node? - Is the name static, or can I name it "myclass::mydata", and use ":datasource: mydata"? - When you call hiera() inside the module, does it go to other modules to search for the "data" subclass? Or is it local (meaning, each module needs to have its own "data" subclass, and hiera will only search there)? - Can I specify a different :datasource:, so that I import a custom-made tree of data, that is independent from the modules? The last question is about my need to define "node groups" and each group have a hiera tree with different values, that the modules don''t need to be aware of, but whe they invoke hiera() they get the right data. For example: common.yaml ssh_keys: -keyA groupA.yaml ssh_keys: -keyB groupB.yaml ssk_keys: -keyC and have the ssh::site_admins class do: $keys = hiera_array("ssh_keys"). Then, depending on which groups does the node belong to (don''t know yet how to define the groups a machine belongs to), it should add the group''s key to the array. Also, is there any kind of documentation on how to use the hiera_puppet datasource? Thanks! Pablo On Saturday 17 March 2012 09:21:12 Gary Larizza wrote:> Hi Pablo, > > The Puppet backend accepts a ''datasource'' parameter whose value will be the > class name for where it will look for Puppet variables. Take my hiera.yaml > for example: > > --- > > :backends: - puppet > : > :puppet: > :datasource: data > > I''m telling it to look for a <modulename>::data class, and to check within > that class for Puppet variables. Given that setup, I can do the following: > > # <modulepath>/puppetbackend/manifests/init.pp > class puppetbackend { > $stuff = hiera(''variable'') > > notify { "Stuff is: ${stuff}": } > } > > # <modulepath>/puppetbackend/manifests/data.pp > class puppetbackend::data { > $variable = ''foo'' > } > > Then if I run: " puppet apply -v -e ''include puppetbackend'' " I will get: > > notice: Stuff is: foo > notice: /Stage[main]/Puppetbackend/Notify[Stuff is: foo]/message: defined > ''message'' as ''Stuff is: foo'' > notice: Finished catalog run in 0.06 seconds > > Does that help you out? > > On Sat, Mar 17, 2012 at 2:29 AM, Pablo Fernandez<pablo.fernandez@cscs.ch>wrote:> > ** > > > > Hi all, > > > > > > > > I am trying to understand how does hiera puppet backend work, so I > > created the following example: > > > > > > > > hiera.yaml has only: > > > > --- > > > > :backends: > > - puppet > > > > > > > > --- > > > > > > > > And the node: > > > > node ''testnode'' { > > > > $variable = ''kk'' > > > > $thing = hiera ("variable") > > > > notify { "note: $thing": } > > > > } > > > > > > > > I don''t want to use the yaml backend for now, just want to grab > > variables > > from within puppet. But then I run the agent, and it "Could not find > > data > > item variable in any Hiera data file". > > > > > > > > This probably means I am completely lost. I did not put any hierarchy, > > because I don''t want to use the yaml backend, and I don''t know why else > > would I need it. > > > > > > > > Could anyone shed some light on me, please? > > > > > > > > Thanks, > > Pablo > > > > -- > > 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.-- 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.
On Tue, Mar 20, 2012 at 9:32 PM, Pablo Fernandez <pablo.fernandez@cscs.ch>wrote:> ** > > Thanks for the hint! > > > > Let me ask you a couple of questions: > > - Does the "puppetbackend::data" have to be imported by the node? >No, not if you''re using Hiera. It just needs to be named appropriately and placed in the correct location inside your module (in the manifests directory).> - Is the name static, or can I name it "myclass::mydata", and use > ":datasource: mydata"? >Whatever you provide in hiera.yaml as the name of the puppet datasource can be used as the data subclass for your module. In your example, every module must have a ''mydata'' subclass, and that''s where Hiera will look for data.> - When you call hiera() inside the module, does it go to other modules to > search for the "data" subclass? Or is it local (meaning, each module needs > to have its own "data" subclass, and hiera will only search there)? >The backend file that does the lookups is here --> https://github.com/puppetlabs/hiera-puppet/blob/master/lib/hiera/backend/puppet_backend.rb I BELIEVE the hiera() function will traverse through the current module''s data class FIRST and then proceed to look through every class in the catalog''s data classes if it fails to find the data in the current module''s data class, but I could be wrong (on-site right now and don''t have time to read through it - maybe someone who''s used it more than I have can comment on this) - Can I specify a different :datasource:, so that I import a custom-made> tree of data, that is independent from the modules? > > >This functionality would be better served by using the YAML backend (as you describe). If you had a level of the hierarchy that utilized a fact whose value returned was ''groupA'' or ''groupB'', then this functionality would work as you describe. I believe we use Operatingsystem as an example in the blog post.> The last question is about my need to define "node groups" and each group > have a hiera tree with different values, that the modules don''t need to be > aware of, but whe they invoke hiera() they get the right data. For example: > > common.yaml > > ssh_keys: -keyA > > > > groupA.yaml > > ssh_keys: -keyB > > > > groupB.yaml > > ssk_keys: -keyC > > > > and have the ssh::site_admins class do: $keys = hiera_array("ssh_keys"). > > Then, depending on which groups does the node belong to (don''t know yet > how to define the groups a machine belongs to), it should add the group''s > key to the array. > > > > Also, is there any kind of documentation on how to use the hiera_puppet > datasource? > > > > Thanks! > > Pablo > > > > On Saturday 17 March 2012 09:21:12 Gary Larizza wrote: > > > Hi Pablo, > > > > > > The Puppet backend accepts a ''datasource'' parameter whose value will be > the > > > class name for where it will look for Puppet variables. Take my > hiera.yaml > > > for example: > > > > > > --- > > > > > > :backends: - puppet > > > : > > > :puppet: > > > :datasource: data > > > > > > I''m telling it to look for a <modulename>::data class, and to check > within > > > that class for Puppet variables. Given that setup, I can do the > following: > > > > > > # <modulepath>/puppetbackend/manifests/init.pp > > > class puppetbackend { > > > $stuff = hiera(''variable'') > > > > > > notify { "Stuff is: ${stuff}": } > > > } > > > > > > # <modulepath>/puppetbackend/manifests/data.pp > > > class puppetbackend::data { > > > $variable = ''foo'' > > > } > > > > > > Then if I run: " puppet apply -v -e ''include puppetbackend'' " I will get: > > > > > > notice: Stuff is: foo > > > notice: /Stage[main]/Puppetbackend/Notify[Stuff is: foo]/message: defined > > > ''message'' as ''Stuff is: foo'' > > > notice: Finished catalog run in 0.06 seconds > > > > > > Does that help you out? > > > > > > On Sat, Mar 17, 2012 at 2:29 AM, Pablo Fernandez < > pablo.fernandez@cscs.ch>wrote: > > > > ** > > > > > > > > Hi all, > > > > > > > > > > > > > > > > I am trying to understand how does hiera puppet backend work, so I > > > > created the following example: > > > > > > > > > > > > > > > > hiera.yaml has only: > > > > > > > > --- > > > > > > > > :backends: > > > > - puppet > > > > > > > > > > > > > > > > --- > > > > > > > > > > > > > > > > And the node: > > > > > > > > node ''testnode'' { > > > > > > > > $variable = ''kk'' > > > > > > > > $thing = hiera ("variable") > > > > > > > > notify { "note: $thing": } > > > > > > > > } > > > > > > > > > > > > > > > > I don''t want to use the yaml backend for now, just want to grab > > > > variables > > > > from within puppet. But then I run the agent, and it "Could not find > > > > data > > > > item variable in any Hiera data file". > > > > > > > > > > > > > > > > This probably means I am completely lost. I did not put any hierarchy, > > > > because I don''t want to use the yaml backend, and I don''t know why else > > > > would I need it. > > > > > > > > > > > > > > > > Could anyone shed some light on me, please? > > > > > > > > > > > > > > > > Thanks, > > > > Pablo > > > > > > > > -- > > > > 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. >-- Gary Larizza Professional Services Engineer Puppet Labs -- 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.