How to join array in ruby dsl


#1

Wowee.,how do I join an array in template?

In the recipe:

hbase_host = [“127.0.0.1”]
template
"/var/titan-#{feature}-#{version}/conf/titan-#{feature}.properties" do
path "/var/titan-#{feature}-#{version}/conf/titan-#{feature}.properties"
source "titan-hbase-#{feature}.properties.erb"
owner "root"
group "root"
mode "0755"
variables({
:version => “#{version}”, :hbase_host => hbase_host,
:elasticsearch_host => “#{elasticsearch_host}”, :elasticsearch_clustername
=> “#{elasticsearch_clustername}”
})
#notifies :restart, resources(:service => “supervisord”)
end

In the template:

storage.hostname=<%=@hbase_host.join(",")%>

My sooooo lovely error…

Running handlers:
[2014-05-13T14:05:51+08:00] ERROR: Running exception handlers
Running handlers complete

[2014-05-13T14:05:51+08:00] ERROR: Exception handlers complete
[2014-05-13T14:05:51+08:00] FATAL: Stacktrace dumped to
/var/chef/cache/chef-stacktrace.out
Chef Client failed. 1 resources updated in 9.574802321 seconds
[2014-05-13T14:05:51+08:00] ERROR:

Chef::Mixin::Template::TemplateError (undefined method `join’ for
"[“127.0.0.1”]":String) on line #96:

94:
95: <storage.backend>hbase</storage.backend>
96:
<storage.hostname><%=@hbase_host.join(",")%></storage.hostname>
97:
<storage.index.search.backend>elasticsearch</storage.index.search.backend>
98:

Thanks


#2

I looks like you have some rouge escaping going on. Where is hbase_host coming from? It is set to a string containing the JSON representation of an array, not the array itself.

–Noah

On May 12, 2014, at 11:10 PM, David Montgomery davidmontgomery@gmail.com wrote:

Wowee.,how do I join an array in template?

In the recipe:

hbase_host = [“127.0.0.1”]
template “/var/titan-#{feature}-#{version}/conf/titan-#{feature}.properties” do
path "/var/titan-#{feature}-#{version}/conf/titan-#{feature}.properties"
source "titan-hbase-#{feature}.properties.erb"
owner "root"
group "root"
mode "0755"
variables({
:version => “#{version}”, :hbase_host => hbase_host, :elasticsearch_host => “#{elasticsearch_host}”, :elasticsearch_clustername => “#{elasticsearch_clustername}”
})
#notifies :restart, resources(:service => “supervisord”)
end

In the template:

storage.hostname=<%=@hbase_host.join(",")%>

My sooooo lovely error…

Running handlers:
[2014-05-13T14:05:51+08:00] ERROR: Running exception handlers
Running handlers complete

[2014-05-13T14:05:51+08:00] ERROR: Exception handlers complete
[2014-05-13T14:05:51+08:00] FATAL: Stacktrace dumped to /var/chef/cache/chef-stacktrace.out
Chef Client failed. 1 resources updated in 9.574802321 seconds
[2014-05-13T14:05:51+08:00] ERROR:

Chef::Mixin::Template::TemplateError (undefined method `join’ for “[“127.0.0.1”]”:String) on line #96:

94:
95: <storage.backend>hbase</storage.backend>
96: <storage.hostname><%=@hbase_host.join(",")%></storage.hostname>
97: <storage.index.search.backend>elasticsearch</storage.index.search.backend>
98:

Thanks