Ask Your Question

pass variable in hiera value calling [closed]

asked 2016-07-03 13:32:54 -0600

puppetamateur gravatar image

$use_ip = $proxies[1]['ipaddress']

we use the above syntax to assign. how do i add a variable in the above syntax? like:

$value = 1
$use_ip = $proxies[1]['ipaddress${value}']

this does not work

edit retag flag offensive reopen merge delete

Closed for the following reason the question is answered, right answer was accepted by puppetamateur
close date 2016-07-05 11:35:20.411318


use double tick quote " instead of single tick ', so the string is actually interpolated?

DarylW gravatar imageDarylW ( 2016-07-03 21:06:15 -0600 )edit

1 Answer

Sort by ยป oldest newest most voted

answered 2016-07-03 21:39:58 -0600

DarylW gravatar image

updated 2016-07-03 21:40:37 -0600

It looks like you are just using single ticks around your string, instead of double ticks..

try applying the following test manifest

$value = 1

you should see output like the following

ubuntu:~$ puppet apply test.pp
Notice: Scope(Class[main]): ipaddress${value}
Notice: Scope(Class[main]): ipaddress1
Notice: Compiled catalog for dawiest-vpcsc1afm in environment production in 0.07 seconds
Notice: Applied catalog in 0.02 seconds

You'll see that the first example turns into the string literal of ipaddress${value}, where the second one correctly interpolates into ipaddress1

For a concrete example, here is a section of my facter output

networking => {
  interfaces => {
    docker0 => {
      bindings => [
          address => "",
          netmask => "",
          network => ""

and in a little test.pp example..

$value = '0'
$docker_binding = $::networking['interfaces']["docker${value}"]['bindings'][0]['address']

And the (non-warning) output given is

ubuntu:~$ puppet apply test.pp
Notice: Scope(Class[main]):
Notice: Compiled catalog for ubuntu in environment production in 0.06 seconds
Notice: Applied catalog in 0.02 seconds
edit flag offensive delete link more

Question Tools

1 follower


Asked: 2016-07-03 13:32:54 -0600

Seen: 104 times

Last updated: Jul 03 '16