hiera style guide

126 views
Skip to first unread message

Georg Faerber

unread,
Sep 28, 2017, 12:44:05 PM9/28/17
to puppet...@googlegroups.com
Hi all,

Searching the Internets didn't reveal anything: Is there some style
guide or best practice regarding syntax used in hiera, writing .yaml
files? For example, should it be:

array:
- string
- string

or

array:
- 'string'
- 'string'

Thanks in advance,
all the best,
Georg
signature.asc

Michael Watters

unread,
Oct 6, 2017, 12:11:08 PM10/6/17
to Puppet Users
You do not *have* to quote strings however I have ran into issues with hiera turning strings that look like integers into an integer which causes problems when you attempt to do a key lookup using a string value or pass a value to a parameter that expects a string value.

For example, there is a difference between this:

signing_keys:
    epel
: '7':
        key_name
: foo

And this:
signing_keys:
    epel
: 7:
        key_name
: foo

The latter causes the value for signingkeys['epel'] to be converted into an integer instead of a string.  This can cause issues with puppet depending on how you reference the data.

Henrik Lindberg

unread,
Oct 6, 2017, 6:20:30 PM10/6/17
to puppet...@googlegroups.com
On 06/10/17 09:11, Michael Watters wrote:
> You do not *have* to quote strings however I have ran into issues with hiera turning strings that look like integers into an integer which causes problems when you attempt to do a key lookup using a string value or pass a value to a parameter that expects a string value.
>
> For example, there is a difference between this:
>
> |
> signing_keys:
>     epel:'7':
>         key_name:foo
> |
>
>
> And this:
>
> |
> signing_keys:
>     epel:7:
>         key_name:foo
> |
>
>
> The latter causes the value for signingkeys['epel'] to be converted into
> an integer instead of a string.  This can cause issues with puppet
> depending on how you reference the data.
>

Note that it is not "hiera"/"puppet" that does that, it is the parser
that reads json or yaml that lexes and interprets values as array, hash,
string, integer etc. according with the syntax and rules for the format.

- henrik

>
> On Thursday, September 28, 2017 at 12:44:05 PM UTC-4, Georg Faerber wrote:
>
> Hi all,
>
> Searching the Internets didn't reveal anything: Is there some style
> guide or best practice regarding syntax used in hiera, writing .yaml
> files? For example, should it be:
>
> array:
>   - string
>   - string
>
> or
>
> array:
>   - 'string'
>   - 'string'
>
> Thanks in advance,
> all the best,
> Georg
>
> --
> 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
> <mailto:puppet-users...@googlegroups.com>.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/puppet-users/300854eb-2727-4299-93ec-189fae953ddf%40googlegroups.com
> <https://groups.google.com/d/msgid/puppet-users/300854eb-2727-4299-93ec-189fae953ddf%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/

Reply all
Reply to author
Forward
0 new messages