【问题标题】:Chef template resource not_if solo厨师模板资源 not_if solo
【发布时间】:2016-01-25 02:55:37
【问题描述】:

我有以下厨师食谱,当它在厨师独奏下收敛时,我不想运行模板资源。在运行厨房收敛时,它似乎不遵守 not_if。它仍然尝试连接厨师服务器。请帮忙。

食谱,

template '/etc/hosts' do
  not_if Chef::Config[:solo]
  source 'hosts.erb'
  mode '0644'
  owner 'root'
  group 'root'
  variables({
      :nodes => search(:node, 'ipaddress:*')
            })
end

模板,

...
<% @nodes.each do |n| -%>
    <% if (n['fqdn'] && n['ipaddress']) -%>
        <%= n['ipaddress'] %> <%= n['fqdn']  %>
    <% end -%>
<% end -%>
...

.kitchen.yml

---
driver:
  name: vagrant

provisioner:
  name: chef_solo

platforms:
  - name: centos-6.7
...

【问题讨论】:

    标签: chef-infra chef-recipe chef-solo test-kitchen


    【解决方案1】:

    将正常值传递给not_if 意味着它被解释为要运行的命令。你想要的是块形式:

    not_if { Chef::Config[:solo] }
    

    也就是说,这不是问题。更深层次的问题是资源主体中的所有值都在编译时被评估。您想使用 lazy 帮助器来延迟评估,以便仅在资源实际运行时才使用它们:

    variables(lazy {
      {:nodes => search(:node, 'ipaddress:*')}
    })
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-10-02
      • 1970-01-01
      • 2019-04-20
      • 1970-01-01
      • 2014-03-06
      相关资源
      最近更新 更多