Reputation: 15581
I am using the following chef resource:
execute 'run_command' do
command "chkconfig service on"
only_if node['platform_version'].to_i == 6, 5
end
Please let me know if only_if guard is used in correct fashion
Upvotes: 1
Views: 6457
Reputation: 170
The ruby commands in the guard block should be enclosed in {}. Also note that any ruby code inside the guard block will be executed at the converging phase i.e. run-time. I had a similar scenario and based on tensibai's comment above, I just used a array with pre-included values to be checked for the ubuntu version.
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
So for your scenario, I believe that the guard-block would be something like
execute 'run_command' do
command "chkconfig service on"
only_if {[5, 6].include?(node['platform_version'].to_i)}
end
Upvotes: -1