puppet - ruby template - ip address from a generated interface name

273 views Asked by At

I have a following ruby template

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. the interface name is dynamic. So if I get eth0 in @interface the @ipadress_interface should be the ip of eth0 (@ipaddress_eth0). IF I predefine the name of the NIC like nic01. The @ipadress_nic01 works like a charm. But unfortunately I know the if name only when the puppet runs

1

There are 1 answers

0
John Bollinger On BEST ANSWER

You can access dynamically-determined variables by using the scope object exposed to ERB scriptlets. 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. Example:

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