【问题标题】:Access to the first element of a Foreman's yaml访问工头 yaml 的第一个元素
【发布时间】:2015-02-26 10:26:23
【问题描述】:

我试图从来自 Foreman 的 yaml 结构中获取一个元素,yaml 是这样的:

nodes:
   host1:
      ip: xxx.xxx.xxx
      cdir: bbb.bbb.bbb
      interface: aaa
   host2:
      ip: yyy.yyy.yyy
      cdir: bbb.bbb.bbb
      interface: aaa

这个 yaml 是在 Foreman 上声明的,它在模板中使用:

<%= @nodes[0][name] %> IPaddr2::<%= @nodes[0]['ip'] %>/<%= @nodes[0]['cidr'] %>/<%= @nodes[0]['interface'] -%>

它在清单上定义:

class heartbeat {
   template_resources => 'site/heartbeat/resources.erb'
}

在这种情况下,我只需要应用第一个元素。感谢您的快速答复。

干杯

【问题讨论】:

  • 你有什么问题?

标签: ruby templates puppet theforeman


【解决方案1】:

我找到了答案,

<% key = @nodes.keys[0] -%>
<%= key %> IPaddr2::<%= @nodes[key]['ip'] %>/<%= @nodes[key]['cidr'] %>/<%= @nodes[key]['interface'] %>

干杯

【讨论】:

    猜你喜欢
    • 2013-06-16
    • 1970-01-01
    • 2023-04-07
    • 1970-01-01
    • 2020-12-24
    • 2020-02-28
    • 1970-01-01
    • 2020-09-06
    • 1970-01-01
    相关资源
    最近更新 更多