Pergunta

I have the following simple recipe:

bash "start mongos" do
  code <<-EOH
    mongos --configdb cfg0.example.net:27019,cfg1.example.net:27019,cfg2.example.net:27019 --fork --logpath /var/log/mongodb.log
  EOH
end

the cfg0/1/2.example.net needs to be taken dynamically from my chef server. These should be replaced with the IPs of the nodes named cfg1, cfg2 and cfg3 accordingly.

How can I do this?

Foi útil?

Solução

You will need to use Chef Search for this. I don't know what your exact query will be, but here's an example:

mongos = search(:node, 'role:mongo')
mongo_addresses = mongos.map { |mongo| "#{mongo['fqdn']}:#{mongo['mongo']['port']}" } 

bash "start mongos" do
  code "mongos --configdb #{mongo_addresses.join(',')} --fork --logpath /var/log/mongodb.log"
end

Note: this is for demonstration purposes. Without more information about the structure of your mongo cookbook and Chef Server setup, I can't give you "copy-paste" code.

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top