[英]puppet - ruby template - ip address from a generated interface name
I have a following ruby template我有以下 ruby 模板
interface <%= @interface %>
state <%= @state %>
priority <%= @priority %>
virtual_router_id 1
unicast_src_ip <%= @ipaddress_interface %>
at unicast_src_ip I would add the @interface-s ip address.在 unicast_src_ip 我会添加@interface-s ip 地址。 the interface name is dynamic.
接口名称是动态的。 So if I get eth0 in @interface the @ipadress_interface should be the ip of eth0 (@ipaddress_eth0).
因此,如果我在@interface 中获得 eth0,@ipadress_interface 应该是 eth0 (@ipaddress_eth0) 的 ip。 IF I predefine the name of the NIC like nic01.
如果我预定义了 NIC 的名称,例如 nic01。 The @ipadress_nic01 works like a charm.
@ipadress_nic01 就像一个魅力。 But unfortunately I know the if name only when the puppet runs
但不幸的是,我只有在木偶运行时才知道 if 名称
You can access dynamically-determined variables by using the scope
object exposed to ERB scriptlets.您可以使用暴露给 ERB 脚本的
scope
object访问动态确定的变量。 It takes the name of the variable you want to access as a string, which can be computed at runtime in any of the ways that Ruby affords.它将您要访问的变量的名称作为字符串,可以在运行时以 Ruby 提供的任何方式计算。 Example:
例子:
unicast_src_ip <%= scope["ipaddress_#{@interface}"] %>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.