How to pass variable in powershell script recipe

I have recipe which is of powershell commands

powershell_script “run-isci” do
code <<-EOH
Set-Service -Name msiscsi -StartupType Automatic
Start-Service msiscsi
New-IscsiTargetPortal -TargetPortalAddress 165.xx.xx.xx
Connect-IscsiTarget -NodeAddress iqn.2015.xxxx.xx -TargetPortalAddress 165.xx.xx.xx -IsPersistent $True

EOH
end

I am getting values 165.xx.xx.xx and iqn.2015.xxxx.xx from another recipe and i wanted to pass it to this recipe.
How i can achieve this?

This was answered here: https://github.com/chef-cookbooks/aws/issues/329#issuecomment-350767238. I’ll answer the remaining questions here but please don’t use a cookbooks issue tracker to ask general Chef questions.

In the issue I initially showed this using Node Attributes but the later example seemed like you had a helper library doing this so combining them we’d get:

bkp_id = List_volume_attached_acd.list_volume_acd('ocid1.instance.oc1.iad.abuw')
target_address = bkp_id.map(&:ipv4)
node_address = bkp_id.map(&:iqn)

powershell_script "run-isci" do
code <<-EOH
Set-Service -Name msiscsi -StartupType Automatic
Start-Service msiscsi
New-IscsiTargetPortal -TargetPortalAddress #{target_address}
Connect-IscsiTarget -NodeAddress #{node_address} -TargetPortalAddress #{target_addres} -IsPersistent $True

EOH
end

I’d give our Ruby Basics doc a look as that will be helpful when working with Chef.

If you’d like more real-time help, I encourage you to join us in the Community Slack.

This is not single recipe, i have two different recipes,
First part of code is recipe which will find values for node and target address.
I have to use these values in another recipe which is powershell script.