ruby - Iterating over an array attribute in Chef -
i using chef provisioning create machines in aws. when creating machine, add attribute array of json files. in recipes run, want iterate on array , create template file on machine. machine gets provisioned when iterating on array attribute, error says:
undefined method `each' nil:nilclass
i tried looking @ node file got created on server , guess what? array of json files added node file! i'm not sure why keeps throwing error. ideas?
the code sample follows:
machines.rb
def get_cluster_json(domain_number) clusters = [] @@environment_template['domains'][domain_number]['clusters'].each |cls| clusters << json.parse(::file::read(new_resource.template_path + cls)) end return clusters end provisioning_xyz_machine "test-admin" tag "usage:keep" attribute "clusters_json", get_cluster_json(domain_counter) recipe admin_role machine_options get_machine_options() ohai_hints ohai_hints action $provisioningaction end
admin_role.rb
managed_details = [] node["clusters_json"].each |cls| managed_details << "#{cls['cluster']['name']}" end
log
* template[/tools/appsw/appsautm/config/intfin_config] action create[2015-05-12t10:24:13-07:00] info: processing template[/tools/appsw/appsautm/config/intfin_config] action create (xyz-environment-cookbook::build_admin line 32) ================================================================================ error executing action `create` on resource 'template[/tools/appsw/appsautm/config/intfin_config]' ================================================================================ chef::mixin::template::templateerror ------------------------------------ undefined method 'each' `nil:nilclass` resource declaration: --------------------- # in /var/chef/cache/cookbooks/xyz-environment-cookbook/recipes/build_admin.rb 32: template "/tools/appsw/appsautm/config/#{env_name}_config" 33: source "#{env_name}_config.conf.erb" 34: cookbook "appsautm-template" 35: owner node['xyz-dir-library']['user'] 36: mode "0755" 37: 38: variables({ 39: :admin_servers=> admin_details, 40: :managed_servers=> managed_details 41: }) 42: end 43: compiled resource: ------------------ # declared in /var/chef/cache/cookbooks/xyz-environment-cookbook/recipes/build_admin.rb:32:in `from_file'
the error appears in template, not cookbook. in fact, appears unrelated files posted. i'd need see #{env_name}_config.conf.erb
file , build_admin.rb
file in order more that.
Comments
Post a Comment