Push_jobs and dynamic whitelist (using search)

Hello guys,

I’m trying to generate some dynamic whitelist commands in recipe, example:

atlasws = search(:node, "role:atlasws", :filter_result => {'name' => ['name']} )

node.normal['push_jobs']['whitelist'] = {
  atlasws.each do |atlas|
    name = atlas['name'].split('.')[0]
    "be_atlasws-enable-#{name}" => "/movile/scripts/haproxy_backend.sh be_atlasws #{name} ready",
    "be_atlasws-disable-#{name}" => "/movile/scripts/haproxy_backend.sh be_atlasws #{name} disable",
  end
}

But is not working…

SyntaxError: (irb):93: syntax error, unexpected =>, expecting keyword_end
... "be_atlasws-enable-#{name}" => "/movile/scripts/haproxy_bac...
...                               ^
(irb):93: syntax error, unexpected ',', expecting keyword_end

The for loop is ok, if I use ‘puts’ do see on the screen… but not to set the [‘whitelist’]… how can I do this?

Thanks!

Solution:

whitelist = {}
atlasws.each do |atlas|
  name = atlas['name'].split('.')[0]
  whitelist["be_atlasws-enable-#{name}"] = "/movile/scripts/haproxy_backend.sh be_atlasws #{name} ready"
  whitelist["be_atlasws-disable-#{name}"] = "/movile/scripts/haproxy_backend.sh be_atlasws #{name} disable"
end

node.normal['push_jobs']['whitelist'] = whitelist