当资源被另一个资源

时间:2017-12-20 19:43:21

标签: chef chef-recipe

我正在编写一个厨师食谱,以便在ec2实例上安装Splunk。我只想在实例的初始设置上安装Splunk。食谱不需要第二次运行。

我使用通知只在满足条件时执行后续代码块:

#install splunk
dpkg_package 'splunkforwarder' do
    source '/tmp/splunkforwarder.deb'
    action :nothing
    notifies :run, 'execute[configure-splunk]', :immediately
end

这是通知的块

commands = ['command1', 'command2', 'etc']
commands.each do |i|
    execute "configure-splunk" do
        command i
        action :nothing
    end
end

问题在于,当配置splunk'如果调用它,它似乎只运行列表中的最后一个命令而不是循环遍历所有命令。我在这里缺少什么?

1 个答案:

答案 0 :(得分:0)

这是正确的,当您有多个具有相同名称+类型对的资源时,只有在查找该名称时才能使用最后一个资源。

你可能想要的是:

execute "configure-splunk" do
    command commands.join(' && ')
    action :nothing
end
相关问题