Search code examples
arrayspuppetfacter

puppet merge two variable in define


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?


Solution

  • 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"
       }