Hi chefs,For our infrastructure automation, we are currently investigating various Chef design patterns to properly (and maybe dynamically) manage multiple "clusters" (like zookeeper, hadoop, rsyslog...). We are wondering how to define a pattern to search other nodes.The current state of things in the cookbooks we encountered (from Opscode and others, like OpenStack), is:1. Specify a role name to search on and optionally set an attribute to search within an environment.2. Sometimes (for example rsyslog) you can directly specify a search query in the node attributes. This is slightly more flexible but the search is still defined by a static attribute.All this works fine but sometimes you want to dynamically allocate clusters using various logic (from ohai data like datacenter, or by environment or a combination of attributes). The classic example is if you have N datacenters and don't want to create a role for each datacenter.One solution would be to create a "site-specific" (or "glue") cookbook that will define dynamically the search string at compile time. This is perfectly OK but adds cookbooks.Another solution would be to use some sort of template for the search string. Ruby string interpolation, or ERB or whatever would work like:In attributes/default.rb:node.default[:my_app][:nodes_search] = 'role:my_app AND location_datacenter:#{node[:location][:datacenter]} AND environment:#{node.chef_environment}'In recipes/default.rb:nodes = search(:node, eval("\"#{node[:my_app][:nodes_search]}\""))Is this pattern reasonable? Or should we stick to the "glue" cookbook way? Or is there anything else we can use?Thanks,Maxime
Archive powered by MHonArc 2.6.16.