Henrik,
Thanks for helping... I tried originally using the hiera-file backend but,
there's too much code to update since the repo hasn't been touched in
nearly 2+ years. So I went down the path of trying to modify the json_data
and/or yaml_data backends to suit my needs, since I noticed the biggest
delta between the two files was the loading of the respective JSON or YAML.
I am unsure as to what the exact expectations are when returning the data
within the *_data.rb backend.
If you can assist in starting with either the json_data or yaml_data ruby
files and modifying them to work with what I need, I would be forever
grateful.
Here are my requirements and expectations...
1. Using lookup() should return/query the same way as it currently does for
variables.
2. I want to be able to specify a "filepath" like "/etc/hosts" which would
then be appended at the end of the search path, so
"environments/%{environment}", for example.
3. The contents of "environment/%{environment}/etc/hosts" would then be
returned.
3. The backend should only return the contents of the first match, as I
won't want duplicative entries within the files.
4. Anything else that may make sense to modify would be good.
I appreciate any assistance you can provide. Thanks!
On Monday, August 21, 2017 at 3:34:41 PM UTC-5, Henrik Lindberg wrote:
>
> On 21/08/17 22:18, John Baird wrote:
> > I see the "yaml_data" and "json_data" backends, but unfortunately, I'm
> > not a Ruby developer and trying to mock those into a file_data backend
> > is proving frustratingly obnoxious. Honestly, I wish a "file_data"
> > backend was included by default as I feel there a TON of value in it's
> > existence, but that's another topic.
> >
> > Basically, from the documentation
> > at https://docs.puppet.com/puppet/5.0/hiera_custom_data_hash.html, I am
> > able to make a custom backend, but unable to get it to parse the
> > directory structure properly and retrieve the entire contents of the
> file.
> >
> > If you have something that would work, I would love to get it working on
> > my end.
> >
>
> You can write functions in the puppet language as well as in Ruby if
> that is more convenient for you. Then depending on what the format of
> the data file you want read is, you could either use an existing
> function that reads JSON/YAML etc. If there is no reader you would be
> best off to write a separate function that can read a particular format,
> and then use that to parse the file and serve data from it using a hiera
> 5 backend compliant function.
>
> The functions that just read a file and returns it a a hash are very
> simple
> (
> https://github.com/puppetlabs/puppet/blob/master/lib/puppet/functions/json_data.rb)
>
>
> which is basically JSON.parse and some error handling around that.
>
> I would expect a custom backend function that you write to be given an
> argument that is the absolute path to the file you want read. That is
> given in the hiera.yaml.
>
> Is it that you want a structure that defines the keys and that the files
> themselves are the resulting value? (Have not looked at hiera-file
> backend). If so, then it sounds like just translating the key to lookup
> to a path (splitting on '::' and and joining with '/') plus appending
> that to a base path where the files are to be found (given as an option
> when adding the function to the hiera.yaml hierarchy). Then reading that
> file or producing a "not found" if the file does not exists.
>
> If you have the start of this in Ruby somewhere I am happy to help you
> review and point out what to change.
>
> Best,
> - henrik
>
> > On Monday, August 21, 2017 at 3:14:42 PM UTC-5, Henrik Lindberg wrote:
> >
> > On 21/08/17 22:03, John Baird wrote:
> > > There was an old hiera 3.X hiera-file backend now owned on github
> by
> > > voxpupuli... does anyone have a working example of how to
> > reproduce this
> > > in Puppet 5 with the next data_hash contexts? Puppet's
> > documentation
> > > seems woefully lacking in this area.
> > >
> > > Basically, I would like to be able to serve up `/etc/hosts` file
> > from
> > > hiera backend, for example.
> > >
> > That should be incredibly simple to achieve with hiera 5.
> > What is it that you feel is lacking in terms of documentation?
> >
> > - henrik
> >
> >
> > --
> >
> > Visit my Blog "Puppet on the Edge"
> > http://puppet-on-the-edge.blogspot.se/
> > <http://puppet-on-the-edge.blogspot.se/>
> >
> > --
> > 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 [email protected] <javascript:>
> > <mailto:[email protected] <javascript:>>.
> > To view this discussion on the web visit
> >
> https://groups.google.com/d/msgid/puppet-users/9154ad28-5f52-40b9-87a6-62ba6ac89e85%40googlegroups.com
>
> > <
> https://groups.google.com/d/msgid/puppet-users/9154ad28-5f52-40b9-87a6-62ba6ac89e85%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/
>
>
--
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 [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/puppet-users/ab1eae43-75c8-4d5f-a616-73a25eedd268%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.