Hi
Is there a way to pass the output of a custom resource or access output variable inside chef recipe and another custom resource ?
Here is my custom resource:
resource_name :shellexec
property :command_name, String, name_property: true
property :command_value, String
property :ip, String
property :outvariable, String, identity:true
property :errvariable, String
action :execute do
ruby_block “getresult” do
block do
Chef::Resource::RubyBlock.send(:include, Chef::Mixin::ShellOut)
command1 = “ssh -T root@#{new_resource.ip} -i #{node[“shellrun”][“keyfile”]} << ENDSSH
#{new_resource.command_value}
ENDSSH”
commandresult = shell_out(command1)
new_resource.outvariable = commandresult.stdout
new_resource.errvariable = commandresult.stderr
#puts “output is #{new_resource.outvariable} and error is #{new_resource.errvariable}”
if not new_resource.outvariable.to_s.empty?
node.default[‘shellrun’][‘commandout’] = commandresult.stdout
end
if not new_resource.errvariable.to_s.empty?
node.default[‘shellrun’][‘commanderr’] = commandresult.stderr
end
end
action :create
end
end
I am accessing node.default[‘shellrun’][‘commanderr’] and node.default[‘shellrun’][‘commandout’] in my recipe as below
runcommands = node[‘shellrun’][‘commands’]
runcommands.each do |commandname, commandval|
command_name = commandname
command_value = commandval
server = ‘10.1.1.6’
shellexec “#{command_name}” do
ip lazy{"#{server}"}
command_value lazy{"#{command_value}"}
end
log “final_output” do
message node[‘shellrun’][‘commanderr’]
message node[‘shellrun’][‘commandout’]
end
end
How ever I am am not able to print message node[‘shellrun’][‘commanderr’] and node[‘shellrun’][‘commandout’] for each command. Is there a way to pass the output to recipe and also to some other custom resource like in functions ?