【问题标题】:puppet - ruby template - ip address from a generated interface namepuppet - ruby​​ 模板 - 来自生成的接口名称的 IP 地址
【发布时间】:2019-10-25 12:58:44
【问题描述】:

我有一个以下 ruby​​ 模板

interface <%= @interface %>
  state <%= @state %>
  priority <%= @priority %>

  virtual_router_id 1
  unicast_src_ip <%= @ipaddress_interface %>

在 unicast_src_ip 我会添加@interface-s ip 地址。 接口名称是动态的。 因此,如果我在@interface 中获得 eth0,@ipadress_interface 应该是 eth0 (@ipaddress_eth0) 的 ip。 如果我预定义了 NIC 的名称,例如 nic01。 @ipadress_nic01 就像一个魅力。但不幸的是,我只有在木偶运行时才知道 if 名称

【问题讨论】:

    标签: templates puppet embedded-ruby


    【解决方案1】:

    您可以使用暴露给 ERB 脚本的the scope object 访问动态确定的变量。它将您要访问的变量的名称作为字符串获取,可以在运行时以 Ruby 提供的任何方式计算。示例:

      unicast_src_ip <%= scope["ipaddress_#{@interface}"] %>
    

    【讨论】:

      猜你喜欢
      • 2020-05-20
      • 2010-09-20
      • 1970-01-01
      • 2012-08-02
      • 2019-08-19
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多