0

We have multiple sub-interface and multiple app running on own sub-interface IP so I am trying to use facter variables to iterate my loop using $name

here are my interface in facter command output

ipaddress_eth0_0 => 10.3.68.98
ipaddress_eth0_1 => 10.3.68.99
ipaddress_eth0_2 => 10.3.68.100
ipaddress_eth0_3 => 10.3.68.101

my manifests file

define myapp {
     exec {"$name":
        command => /bin/sed -i 's/IP_ADDRESS=\"127.0.0.1\"/IP_ADDRESS=\"$ipaddress_eth0_$name\"/' /opt/app.$name/bin/setenv.sh
}

myapp { [ "0", "1" , "2", "3" ]: }

some how $ipaddress_eth0_$name doesn't working :( its not parsing this variable, how do I join two variables?

Brian Tompsett - 汤莱恩
  • 5,753
  • 72
  • 57
  • 129
Satish
  • 16,544
  • 29
  • 93
  • 149

3 Answers3

1

Take a look to the inline template feature

   define myapp {
      $myip  =  inline_template("<%= ipaddress_eth0_${name} %>")
      exec {"$name":
        command => "/bin/sed -i 's/IP_ADDRESS=\"127.0.0.1\"/IP_ADDRESS=\"$myip\"/' /opt/app.${name}/bin/setenv.sh"
   }
Raul Andres
  • 3,766
  • 15
  • 24
1

The stdlib library has a getvar (https://github.com/puppetlabs/puppetlabs-stdlib#getvar) function that should solve your problem.

bartavelle
  • 897
  • 8
  • 16
0

Could you try to wrap the variables with curly braces

E.g.

   define myapp {
      exec {"$name":
        command => /bin/sed -i 's/IP_ADDRESS=\"127.0.0.1\"/IP_ADDRESS=\"${ipaddress_eth0}_${name}\"/' /opt/app.${name}/bin/setenv.sh
   }

UPDATE

Could you wrap the command in double quotes e.g.

   define myapp {
      exec {"$name":
        command => "/bin/sed -i 's/IP_ADDRESS=\"127.0.0.1\"/IP_ADDRESS=\"${ipaddress_eth0}_${name}\"/' /opt/app.${name}/bin/setenv.sh"
   }
cocheese
  • 512
  • 2
  • 9