negate conditional to simplify indentation

This commit is contained in:
Adam Spiers
2014-01-09 12:12:59 +00:00
parent a19cca3b68
commit 1b5e9ca6a8

View File

@@ -26,49 +26,49 @@ action :create do
name = new_resource.name name = new_resource.name
agent = new_resource.agent agent = new_resource.agent
unless resource_exists?(name) return if resource_exists?(name)
cmd = "crm configure primitive #{name} #{agent}"
if new_resource.params and !(new_resource.params.empty?) cmd = "crm configure primitive #{name} #{agent}"
cmd << " params"
new_resource.params.each do |key, value| if new_resource.params and !(new_resource.params.empty?)
cmd << " params"
new_resource.params.each do |key, value|
cmd << " #{key}=\"#{value}\""
end
end
if new_resource.meta and !(new_resource.meta.empty?)
cmd << " meta"
new_resource.meta.each do |key, value|
cmd << " #{key}=\"#{value}\""
end
end
if new_resource.op and !(new_resource.op.empty?)
cmd << " op"
new_resource.op.each do |op, attrs|
cmd << " #{op}"
attrs.each do |key, value|
cmd << " #{key}=\"#{value}\"" cmd << " #{key}=\"#{value}\""
end end
end end
end
if new_resource.meta and !(new_resource.meta.empty?) # 'Execute' resource doesn't throw exception even when command fails..
cmd << " meta" # So, Mixlib::ShellOut was used instead.
new_resource.meta.each do |key, value| cmd_ = Mixlib::ShellOut.new(cmd)
cmd << " #{key}=\"#{value}\"" cmd_.environment['HOME'] = ENV.fetch('HOME', '/root')
end cmd_.run_command
end begin
cmd_.error!
if new_resource.op and !(new_resource.op.empty?) if resource_exists?(name)
cmd << " op" new_resource.updated_by_last_action(true)
new_resource.op.each do |op, attrs| Chef::Log.info "Successfully configured primitive '#{name}'."
cmd << " #{op}" else
attrs.each do |key, value|
cmd << " #{key}=\"#{value}\""
end
end
end
# 'Execute' resource doesn't throw exception even when command fails..
# So, Mixlib::ShellOut was used instead.
cmd_ = Mixlib::ShellOut.new(cmd)
cmd_.environment['HOME'] = ENV.fetch('HOME', '/root')
cmd_.run_command
begin
cmd_.error!
if resource_exists?(name)
new_resource.updated_by_last_action(true)
Chef::Log.info "Successfully configured primitive '#{name}'."
else
Chef::Log.error "Failed to configure primitive #{name}."
end
rescue
Chef::Log.error "Failed to configure primitive #{name}." Chef::Log.error "Failed to configure primitive #{name}."
end end
rescue
Chef::Log.error "Failed to configure primitive #{name}."
end end
end end