Ask Your Question
0

pass variable in hiera value calling [closed]

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

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

Comments

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

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

1 Answer

Sort by ยป oldest newest most voted
2

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

DarylW gravatar image

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

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

try applying the following test manifest

$value = 1
notice('ipaddress${value}')
notice("ipaddress${value}")

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 => "172.17.0.1",
          netmask => "255.255.0.0",
          network => "172.17.0.0"
        }
      ],
...

and in a little test.pp example..

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

And the (non-warning) output given is

ubuntu:~$ puppet apply test.pp
Notice: Scope(Class[main]): 172.17.0.1
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

Stats

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

Seen: 67 times

Last updated: Jul 03 '16