Brackets in hiera yaml

66 views
Skip to first unread message

MartinW

unread,
Apr 18, 2018, 4:23:31 AM4/18/18
to Puppet Users
Hi

I have some hiera yaml that looks like this:

   vars:
      psuName:  xxxxx
      liveCustomers: 100
      notes: some notes here (more info in backets)
      uplink: uplink01

The yaml is autogenerated by a script and it is basically used to help build icinga2 config. The problem I have is that the output looks like this in the config file:

  vars.psuName = "xxxxx"
  vars.liveCustomers = 100
  vars.notes = some notes here ("more info in backets")
  vars.uplink = "uplink01"

So puppet has put quotes around most fields which is what I want, but on the notes field it has put quotes only around the text inside the bracket, I want it to look like this:

  vars.notes = "some notes here (more info in backets)"

I have tried changing the hiera yaml to look like this:

      notes: "some notes here (more info in backets)"

but it makes no difference.

Any ideas?

jcbollinger

unread,
Apr 18, 2018, 8:55:42 AM4/18/18
to Puppet Users
Puppet itself is not responsible for adding the quotes to the target file.  That's being done by whatever template or other mechanism you specified and provided for it to use to generate the content of that file.  Puppet just supplies your input data to that function or template (as a Hash, it appears, but not raw text in any case), and receives the result, which it records literally in the target file.

I do recommend that you take care with how you generate the Hiera data.  Use a YAML-specific tool, and twiddle its dials to get the most conservative output style it is willing to produce.  For instance, I'm surprised that your notes data is not already being presented quoted.  But that's to protect you from future issues, not to fix your present one.


John

MartinW

unread,
Apr 18, 2018, 10:37:50 AM4/18/18
to Puppet Users

Hi John

Thanks for the reply

The hiera is generated by a custom Ruby script. I have tried tweaking it to output both with quotes and without but it didn't help

The end config file on the server is being created with an Ensure_resources statement like this:

ensure_resources('icinga2::object::host', lookup('profile::icinga2_master::monitoring::objects::servers'), {'ensure' => 'present'})

so maybe the issue is with the puppet - icinga2 plugin... after some more playing around I have made it work in a slightly less than satisfactory way:
I added a line into the ruby script to strip out any brackets in the notes string  and use a - to separate the string out a bit like this

notes: some notes here - more info no longer in brackets

but It still gave me output where everything after the - was in quotes.

what finally worked was to have the ruby output the string like this (basically without the spaces around the -):

notes: some notes here-more info no longer in brackets



jcbollinger

unread,
Apr 19, 2018, 9:11:09 AM4/19/18
to Puppet Users


On Wednesday, April 18, 2018 at 9:37:50 AM UTC-5, MartinW wrote:

Hi John

Thanks for the reply

The hiera is generated by a custom Ruby script. I have tried tweaking it to output both with quotes and without but it didn't help


And you should stick with the version that quotes the whole string, but as I said before, that's for better protection against potential other issues, not for solving this one.
 

The end config file on the server is being created with an Ensure_resources statement like this:
 
ensure_resources('icinga2::object::host', lookup('profile::icinga2_master::monitoring::objects::servers'), {'ensure' => 'present'})


Attributing the config file creation to the ensure_resources() call is like attributing your tax preparer's work to his landlord.  Ensure_resources() is one way to tell Puppet to engage specific resources to do the job -- in this case, resources of type icinga2::object::host.  But that resource type belongs to a third-party module, and the problem is in that module and specific to it.

We might be able to help you solve the problem or find a better workaround, but that starts with you telling us which version of which icinga2 module you are using, and where to find it (on the Forge, ideally).


John

Reply all
Reply to author
Forward
0 new messages