hiera_hash string key variable

44 views
Skip to first unread message

João Matos

unread,
Jun 26, 2017, 12:58:51 PM6/26/17
to Puppet Users
Hi 

i wanted to had the value to hiera_hash string key from a variable

something like:

$variable= specific
$newvariable = hiera_hash('data::hiera::$variable')

is this possible what's the correct syntax?


Thanks

Henrik Lindberg

unread,
Jun 26, 2017, 1:44:38 PM6/26/17
to puppet...@googlegroups.com
I think you want to interpolate a value into the string that is the key
you are looking up. If so, you would do this:

$variable = 'specific'
$newvariable = hiera_hash("data::hiera::${variable}")


Note that if you are on a recent release you want to use the lookup()
function instead of hiera_hash function (and friends hiera, hiera_array,
etc).

Best,
- henrik

>
> Thanks
>
> --
> 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/b07f61bd-c023-4627-959c-b0ef0bc704c8%40googlegroups.com
> <https://groups.google.com/d/msgid/puppet-users/b07f61bd-c023-4627-959c-b0ef0bc704c8%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/

João Matos

unread,
Jun 27, 2017, 11:26:10 AM6/27/17
to Puppet Users
Doesnt work. ${variable} is being set literally

 



On Monday, 26 June 2017 18:44:38 UTC+1, Henrik Lindberg wrote:
On 26/06/17 18:33, João Matos wrote:
> Hi
>
> i wanted to had the value to hiera_hash string key from a variable
>
> something like:
>
> $variable= specific
> $newvariable = hiera_hash('data::hiera::$variable')
>
> is this possible what's the correct syntax?
>

I think you want to interpolate a value into the string that is the key
you are looking up. If so, you would do this:

     $variable = 'specific'
     $newvariable = hiera_hash("data::hiera::${variable}")


Note that if you are on a recent release you want to use the lookup()
function instead of hiera_hash function (and friends hiera, hiera_array,
etc).

Best,
- henrik

>
> Thanks
>
> --
> 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

Andrew Grimberg

unread,
Jun 27, 2017, 12:01:20 PM6/27/17
to puppet...@googlegroups.com, João Matos
Greetings João,

Do you have it inside double or single quotes? If it's in single quotes,
like your example, then it's only going to be literal. To get
interpolation you've got to use double quotes like Henrik had.

-Andy-
> > an email to puppet-users...@googlegroups.com <javascript:>
> > <mailto:puppet-users...@googlegroups.com <javascript:>>.
> <https://groups.google.com/d/msgid/puppet-users/b07f61bd-c023-4627-959c-b0ef0bc704c8%40googlegroups.com?utm_medium=email&utm_source=footer
> <https://groups.google.com/d/optout>.
>
>
> --
>
> 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 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/899dfdab-5772-4930-80e7-b8af75073e48%40googlegroups.com
> <https://groups.google.com/d/msgid/puppet-users/899dfdab-5772-4930-80e7-b8af75073e48%40googlegroups.com?utm_medium=email&utm_source=footer>.
signature.asc

João Matos

unread,
Jun 28, 2017, 7:58:41 AM6/28/17
to Puppet Users
tks.
tried both ways. didnt work

Henrik Lindberg

unread,
Jun 28, 2017, 12:39:59 PM6/28/17
to puppet...@googlegroups.com
On 28/06/17 13:58, João Matos wrote:
> tks.
> tried both ways. didnt work
>
>

Then something else is wrong, impossible to say what
since "didnt work" does not say much.

I am absolutely positive the example I showed does what you wanted
"interpolates a value into the key you are looking up" - clearly I do
not know if the variable has the value you expect it to have, nor if
there is anything at all to look up at that key, and that it is a hash.


- henrik
> --
> 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/f7871adc-b746-417f-8a6d-9797243362a2%40googlegroups.com
> <https://groups.google.com/d/msgid/puppet-users/f7871adc-b746-417f-8a6d-9797243362a2%40googlegroups.com?utm_medium=email&utm_source=footer>.
> For more options, visit https://groups.google.com/d/optout.


Reply all
Reply to author
Forward
0 new messages