Chef - how to avoid duplicating a recipe -
in our chef cookbooks support multiple versions of same software. we've adopted bad practice. each version we've made copy of recipe , changed it's attributes.
e.g.
remote_file install_file source node['android']['sdk']['23']['source_url'] not_if ::file.exists?(extract_dir) end notifies :run, "execute[extract-sdk-23]", :immediately end
becomes
remote_file install_file source node['android']['sdk']['24']['source_url'] not_if ::file.exists?(extract_dir) end notifies :run, "execute[extract-sdk-24]", :immediately end
this code duplication. it'd cleaner keep attributes same vary values.
is possible chef?
if matters use chef-client 0 directly. i.e. don't use knife, etc.
as @stephenking mentioned, best bet write custom resource abstracts logic. put different sdks in hash in node attributes , iterate on them in single recipe, going less flexible.
Comments
Post a Comment