paragraphing hiera yaml

60 views
Skip to first unread message

Christopher Wood

unread,
Oct 28, 2016, 1:46:02 PM10/28/16
to puppet...@googlegroups.com
Here's a Friday sort of question.

All the yaml emitters don't add the extra space that I can add as a person editing a file to make things more readable. Or to be more accurate, I can't manage it myself and I can't find one that does.

Consider the readability of the two examples below when thinking about what keys go with which classes. Also keep in mind that while example one may be fine for many of us, lots more people will find it easier to work with yaml using example two.

So how would I auto-magically auto-paragraph hiera yaml to make it friendlier for more people, while still keeping it syntactically valid?


Example one:

---
one::services::enabled: true
one::two::abc: 8.45
one::two::three: this is the string
puppet4::ca_server: otherhostname
puppet4::server: hostname


Example two:

---
one::services::enabled: true

one::two::abc: 8.45
one::two::three: this is the string

puppet4::ca_server: otherhostname
puppet4::server: hostname

R.I.Pienaar

unread,
Oct 30, 2016, 4:57:57 AM10/30/16
to puppet-users
nothing really built in but you can hack this up yourself (emphasis on hack)

https://gist.github.com/ripienaar/097aa19b928ffffa57b4b7a4ec861fa4

Garrett Honeycutt

unread,
Oct 30, 2016, 3:38:40 PM10/30/16
to puppet...@googlegroups.com
Hi Christopher,

It sounds like you have two processes managing the same data - a program
that emits YAML and people who also edit that YAML. If so, you would be
better off by splitting that between two backends. Hiera can query the
program that emits YAML directly as well as reading the YAML you modify
manually.

Best regards,
-g

--
Garrett Honeycutt
@learnpuppet
Puppet Training with LearnPuppet.com
Mobile: +1.206.414.8658

Christopher Wood

unread,
Oct 31, 2016, 9:52:36 AM10/31/16
to puppet...@googlegroups.com
That's almost exactly it, I was trying to munge the text not the data so no wonder I couldn't get it working. Thank you!

> --
> 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...@googlegroups.com.
> To view this discussion on the web visit https://groups.google.com/d/msgid/puppet-users/2124299857.120.1477817859281.JavaMail.zimbra%40devco.net.
> For more options, visit https://groups.google.com/d/optout.

Christopher Wood

unread,
Oct 31, 2016, 9:53:43 AM10/31/16
to puppet...@googlegroups.com
On Sun, Oct 30, 2016 at 03:38:31PM -0400, Garrett Honeycutt wrote:
> On 10/28/16 1:45 PM, Christopher Wood wrote:
> > Here's a Friday sort of question.
> >
> > All the yaml emitters don't add the extra space that I can add as a person editing a file to make things more readable. Or to be more accurate, I can't manage it myself and I can't find one that does.
> >
> > Consider the readability of the two examples below when thinking about what keys go with which classes. Also keep in mind that while example one may be fine for many of us, lots more people will find it easier to work with yaml using example two.
> >
> > So how would I auto-magically auto-paragraph hiera yaml to make it friendlier for more people, while still keeping it syntactically valid?
> >
> >
> > Example one:
> >
> > ---
> > one::services::enabled: true
> > one::two::abc: 8.45
> > one::two::three: this is the string
> > puppet4::ca_server: otherhostname
> > puppet4::server: hostname
> >
> >
> > Example two:
> >
> > ---
> > one::services::enabled: true
> >
> > one::two::abc: 8.45
> > one::two::three: this is the string
> >
> > puppet4::ca_server: otherhostname
> > puppet4::server: hostname
> >
>
> Hi Christopher,
>
> It sounds like you have two processes managing the same data - a program

Just people editing the yaml, but with all skill levels editing in sometimes hurried circumstance it can be a job to intermittently clean out the metaphorical stables. Tidying everything up first really helps.

> that emits YAML and people who also edit that YAML. If so, you would be
> better off by splitting that between two backends. Hiera can query the
> program that emits YAML directly as well as reading the YAML you modify
> manually.
>
> Best regards,
> -g
>
> --
> Garrett Honeycutt
> @learnpuppet
> Puppet Training with LearnPuppet.com
> Mobile: +1.206.414.8658
>
> --
> 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...@googlegroups.com.
> To view this discussion on the web visit https://groups.google.com/d/msgid/puppet-users/033cc1a3-3e17-993e-1a1e-bd4b87b815b1%40garretthoneycutt.com.

Craig Dunn

unread,
Nov 2, 2016, 10:10:41 AM11/2/16
to puppet...@googlegroups.com
On Fri, Oct 28, 2016 at 7:45 PM, Christopher Wood <christop...@pobox.com> wrote:


So how would I auto-magically auto-paragraph hiera yaml to make it friendlier for more people, while still keeping it syntactically valid?


Example two:

---
one::services::enabled: true

one::two::abc: 8.45
one::two::three: this is the string

puppet4::ca_server: otherhostname
puppet4::server: hostname

Another options not yet presented is to split the files out into the classes they represent.

This can be done with something like this in your hiera.yaml using the special variable %{calling_module}

---
:yaml:
  :hierarchy:
    - foo/%{calling_module}

Then, instead of having a foo.yaml with everything, you have a foo/one.yaml and a foo/puppet.yaml (based on your above example). I like this configuration in Hiera, and in fact Jerakia does something very similar by default - grouping everything in one file can get very messy very quickly.  Using calling_module in hiera has a few limitations if you're doing crazy things like hiera() calls across different modules, but if you are using straight forward data binding lookups it works well.  It's not quite an answer to your question but it might help you keep things tidier.

Regards
Craig

 

Thomas Müller

unread,
Nov 5, 2016, 8:29:13 AM11/5/16
to Puppet Users


Am Mittwoch, 2. November 2016 15:10:41 UTC+1 schrieb Craig Dunn:


On Fri, Oct 28, 2016 at 7:45 PM, Christopher Wood <christop...@pobox.com> wrote:


So how would I auto-magically auto-paragraph hiera yaml to make it friendlier for more people, while still keeping it syntactically valid?


Example two:

---
one::services::enabled: true

one::two::abc: 8.45
one::two::three: this is the string

puppet4::ca_server: otherhostname
puppet4::server: hostname

Another options not yet presented is to split the files out into the classes they represent.

This can be done with something like this in your hiera.yaml using the special variable %{calling_module}

---
:yaml:
  :hierarchy:
    - foo/%{calling_module}

or %{calling_module_path} which replaces :: by /

usefull if you checkout your hiera git repo on Windows where no : are allowed in filenames.

- Thomas

Thomas Müller

unread,
Nov 5, 2016, 8:31:10 AM11/5/16
to Puppet Users


Am Samstag, 5. November 2016 13:29:13 UTC+1 schrieb Thomas Müller:


Am Mittwoch, 2. November 2016 15:10:41 UTC+1 schrieb Craig Dunn:


On Fri, Oct 28, 2016 at 7:45 PM, Christopher Wood <christop...@pobox.com> wrote:


So how would I auto-magically auto-paragraph hiera yaml to make it friendlier for more people, while still keeping it syntactically valid?


Example two:

---
one::services::enabled: true

one::two::abc: 8.45
one::two::three: this is the string

puppet4::ca_server: otherhostname
puppet4::server: hostname

Another options not yet presented is to split the files out into the classes they represent.

This can be done with something like this in your hiera.yaml using the special variable %{calling_module}

---
:yaml:
  :hierarchy:
    - foo/%{calling_module}

or %{calling_module_path} which replaces :: by /

I meant
%{calling_class_path}


 not module. calling_module_path does not exist.

- Thomas
Reply all
Reply to author
Forward
0 new messages