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?

4

3 回答 3

1

看看内联模板功能

   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"
   }
于 2014-01-29T11:57:53.567 回答
1

stdlib 库有一个getvar( https://github.com/puppetlabs/puppetlabs-stdlib#getvar ) 函数可以解决您的问题。

于 2014-01-31T11:08:36.663 回答
0

你能试着用花括号把变量包起来吗

例如

   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
   }

更新

您能否将命令用双引号括起来,例如

   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"
   }
于 2014-01-28T22:22:54.800 回答