I need to find out the user,group of directory and change owner by using varibales

I am new writing recipe. I want to find user and group of existing directory/file store it in variable . I need to change the owner and group using that variable. After doing some research, I wrote below code in default.rb. But it is not assigning "#{user_name}:#{group_name}" at chown command. Can someone help be with below code? thanks in Advance .

=================================================================

ruby_block "get user" do
block do
Chef::Resource::RubyBlock.send(:include, Chef::Mixin::ShellOut)
user1 = "ls -ltr /opt/AppD | grep -w AppServerAgent | awk '{print $3}'"
group1 = "ls -ltr /opt/AppD | grep -w AppServerAgent | awk '{print $4}'"
user_out = shell_out(user1)
group_out = shell_out(group1)
node.run_state['user_name'] = user_out.stdout
node.run_state['group_name'] = group_out.stdout
end
action :create
end

template "/tmp/script.sh" do
source "script.sh.erb"
variables(
:user_name => lazy { node.run_state['user_name'] },
:group_name => lazy { node.run_state['group_name'] }
)
end

user_name=node.run_state['user_name']
group_name=node.run_state['group_name']

execute "unzip_agent_file" do
command <<-EOH
cd #{install_dir}
old_file=( $(ls -ltr | grep ^l | awk '{print $11}') )
cp -r $old_file "old_file"-(date +"%m-%d-%y")
unlink AppServerAgent
rm -rf $old_file
mkdir -p #{install_dir}/AppServerAgent#{node['appdynamics']['agent']['version']}
cd #{install_dir}/AppServerAgent#{node['appdynamics']['agent']['version']}
unzip -qq #{install_dir}/#{local_zip_file} -d #{install_dir}/AppServerAgent#{node['appdynamics']['agent']['version']}
cd #{install_dir}
ln -sf AppServerAgent#{node['appdynamics']['agent']['version']} AppServerAgent
chown -R #{user_name}:#{group_name} /opt/AppD/
EOH

end

============================================================================

Can someone help me on this ? "#{user_name}:#{group_name}" is throwing as null value. Not sure where I am doing mistake in the above code.