Вопрос

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?

Это было полезно?

Решение

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

Другие советы

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

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"
   }
Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top