Need help to find the ip address of other host

I am using this peice of code to get the ip of other server in my code:-
publish_vm = node['aem_dispatcher_cookbook']['publish'].to_s
nodes = search(:node, 'hostname:publish_vm')
node.default['aem_dispatcher_cookbook']['ip_address'] = 'nodes.first['ipaddress']'

But i am getting error can you please help me to get the ip address of desired host ip address (I want to get the ip address of other host). Pasting error as well

================================================================================
Recipe Compile Error in /root/.chef/local-mode-cache/cache/cookbooks/aem_dispatcher_cookbook/recipes/default.rb
================================================================================

SyntaxError
-----------
/root/.chef/local-mode-cache/cache/cookbooks/aem_dispatcher_cookbook/recipes/default.rb:333: syntax error, unexpected tIDENTIFIER, expecting keyword_end
...ess'] = 'nodes.first['ipaddress']'
...                      ^~~~~~~~~

If i am putting this ('nodes.first['ipaddress']') in double quotes it wont bring ip for me

Make this change and it should run fine:

node.default['aem_dispatcher_cookbook']['ip_address'] = nodes.first['ipaddress']

-Tim

Hello,

I have tried it as well getting below mentioned error

--- END RESPONSE ---

  ================================================================================
  Recipe Compile Error in /root/.chef/local-mode-cache/cache/cookbooks/aem_dispatcher_cookbook/recipes/default.rb
  ================================================================================

  NoMethodError
  -------------
  undefined method `[]' for nil:NilClass

  Cookbook Trace:
  ---------------
    /root/.chef/local-mode-cache/cache/cookbooks/aem_dispatcher_cookbook/recipes/default.rb:335:in `from_file'

  Relevant File Content:
  ----------------------
  /root/.chef/local-mode-cache/cache/cookbooks/aem_dispatcher_cookbook/recipes/default.rb:

  328:    #  EOH
  329:    #end
  330:
  331:
  332:  publish_vm = node['aem_dispatcher_cookbook']['publish'].to_s
  333:    nodes = search(:node, 'hostname:publish_vm')
  334:  puts nodes
  335>>  node.default['aem_dispatcher_cookbook']['ip_address'] = nodes.first['ipaddress']