我正在使用以下厨师资源:
execute 'run_command' do
command "chkconfig service on"
only_if node['platform_version'].to_i == 6, 5
end
请让我知道是否正确地使用了only_if防护
发布于 2019-02-01 23:41:56
保护块中的ruby命令应该包含在{}中。还要注意的是,保护块中的任何ruby代码都将在收敛阶段执行,即运行时。我有一个类似的场景,基于tensibai上面的评论,我只是使用了一个带有预先包含的值的数组来检查ubuntu版本。
execute "apt-get-update" do
command "apt-get update"
ignore_failure true
notifies :install, 'package[ntp]', :immediately
not_if {[16.04, 18.04].include?(node['platform_version'].to_f) && (node['packages'].keys.include? "ntp")}
#not_if {(node['packages'].keys.include? "ntp")}
end
因此,对于您的场景,我认为保护块应该是这样的
execute 'run_command' do
command "chkconfig service on"
only_if {[5, 6].include?(node['platform_version'].to_i)}
end
https://stackoverflow.com/questions/40133670
复制相似问题