replace 'execute' with 'Mixlib::ShellOut' library.

This commit is contained in:
Robert
2013-04-21 22:51:55 +09:00
parent 2d5708d753
commit 2f4177068b
7 changed files with 69 additions and 52 deletions

View File

@@ -33,12 +33,16 @@ action :create do
end
end
e = execute "configure clone #{name}" do
command cmd
end
cmd_ = Mixlib::ShellOut.new(cmd)
cmd_.environment['HOME'] = ENV.fetch('HOME', '/root')
cmd_.run_command
begin
cmd.error!
new_resource.updated_by_last_action(true)
Chef::Log.info "configured clone '#{name}'."
Chef::Log.info "Successfully configured clone '#{name}'."
rescue
Chef::Log.error "Failed to configure clone #{name}."
end
end
end
@@ -53,5 +57,4 @@ action :delete do
new_resource.updated_by_last_action(true)
Chef::Log.info "Deleted clone '#{name}'."
end

View File

@@ -32,24 +32,22 @@ action :create do
multiple_rscs.each do |rsc|
cmd << " #{rsc}"
end
e = execute "configure colocation #{name}" do
command cmd
end
new_resource.updated_by_last_action(true)
Chef::Log.info "Configured colocation '#{name}'."
else
rsc = new_resource.rsc
with_rsc = new_resource.with_rsc
cmd = "crm configure colocation #{name} #{priority}: #{rsc} #{with_rsc}"
e = execute "configure colocation #{name}" do
command cmd
end
cmd_ = Mixlib::ShellOut.new(cmd)
cmd_.environment['HOME'] = ENV.fetch('HOME', '/root')
cmd_.run_command
begin
cmd.error!
new_resource.updated_by_last_action(true)
Chef::Log.info "Configured colocation '#{name}'."
Chef::Log.info "Successfully configured colocation '#{name}'."
rescue
Chef::Log.error "Failed to configure colocation #{name}."
end
end
end

View File

@@ -28,12 +28,16 @@ action :create do
unless resource_exists?(name)
cmd = "crm configure location #{name} #{rsc} #{priority}: #{loc}"
e = execute "configure location #{name}" do
command cmd
end
cmd_ = Mixlib::ShellOut.new(cmd)
cmd_.environment['HOME'] = ENV.fetch('HOME', '/root')
cmd_.run_command
begin
cmd.error!
new_resource.updated_by_last_action(true)
Chef::Log.info "Configured location '#{name}'."
Chef::Log.info "Successfully configured location '#{name}'."
rescue
Chef::Log.error "Failed to configure location #{name}."
end
end
end

View File

@@ -33,12 +33,16 @@ action :create do
end
end
e = execute "configure ms #{name}" do
command cmd
end
cmd_ = Mixlib::ShellOut.new(cmd)
cmd_.environment['HOME'] = ENV.fetch('HOME', '/root')
cmd_.run_command
begin
cmd.error!
new_resource.updated_by_last_action(true)
Chef::Log.info "configured ms '#{name}'."
Chef::Log.info "Successfully configured ms '#{name}'."
rescue
Chef::Log.error "Failed to configure ms #{name}."
end
end
end

View File

@@ -25,12 +25,16 @@ action :add do
unless resource_exists?(name)
cmd = "crm configure node #{name}"
e = execute "add node #{name}" do
command cmd
end
cmd_ = Mixlib::ShellOut.new(cmd)
cmd_.environment['HOME'] = ENV.fetch('HOME', '/root')
cmd_.run_command
begin
cmd.error!
new_resource.updated_by_last_action(true)
Chef::Log.info "Node '#{name}' has been added.."
Chef::Log.info "Successfully configured node '#{name}'."
rescue
Chef::Log.error "Failed to configure node #{name}."
end
end
end

View File

@@ -30,12 +30,16 @@ action :create do
cmd << " #{rsc}"
end
e = execute "configure order #{name}" do
command cmd
end
cmd_ = Mixlib::ShellOut.new(cmd)
cmd_.environment['HOME'] = ENV.fetch('HOME', '/root')
cmd_.run_command
begin
cmd.error!
new_resource.updated_by_last_action(true)
Chef::Log.info "Configured order '#{name}'."
Chef::Log.info "Successfully configured order '#{name}'."
rescue
Chef::Log.error "Failed to configure order #{name}."
end
end
end

View File

@@ -53,18 +53,18 @@ action :create do
end
end
e = execute "configure primitive #{name}" do
command cmd
end
# With the below commands, 'e.updated?' is always 'false' even though the execute command ran successfully.
# new_resource.updated_by_last_action(e.updated?)
# if e.updated?
# Chef::Log.info "Done creating primitive '#{name}'."
# 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!
new_resource.updated_by_last_action(true)
Chef::Log.info "Configured primitive '#{name}'."
Chef::Log.info "Successfully configured primitive '#{name}'."
rescue
Chef::Log.error "Failed to configure primitive #{name}."
end
end
end