0

I am having node['server']['ipaddress'] attribute that includes 3 ip addresses as below:

node['server']['ipaddress']=["10.211.241.21", "10.211.241.20", "10.211.241.22"]

I am now trying to use the above values in a chef bash resource

bash 'configure_engine_discovery' do
  code <<-EOH
  echo `docker run --server ipaddress1 --server ipaddress2 --server ipaddress3 --update`
  EOH
end

There might be more than 3 ipaddresses and I want to make the above bash command more dynamic so that the I don't require to change the bash every time and it can accommodate any number of server ips

1 Answer 1

2

Try this:

server_specs = node['server']['ipaddress'].map { |s| "--server #{s}" }.join(' ')
command = "docker run #{server_specs} --update"
echo command

By the way, why isn't the key named in the plural, ipaddresses instead of ipaddress? That's confusing to readers.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.