[chef] Re: how to load a json object in a ruby block and pass to a template


Chronological Thread 
  • From: Daniel DeLeo < >
  • To:
  • Subject: [chef] Re: how to load a json object in a ruby block and pass to a template
  • Date: Wed, 3 Apr 2013 09:39:18 -0700


On Friday, March 29, 2013 at 2:20 PM, David Montgomery wrote:

Hi

In a ruby block I am trying to load a json object and passing the hash to a template.  The json file  exists.  How to I load a json object do I cna pass to a

node[:neoservers] should look lie this [xxx.xxx.xxx.xxx,yyy.yyy.yyy.yyy]

ruby_block "stuff" do
    block do
      contents = File.read('/tmp/cluster_ipaddress')
      existing_nodes = JSON.parse(contents)
      require 'set'
      neoservers = [node[:ipaddress]] + existing_nodes
      neoservers = neoservers.to_set.to_a.sort
      node.default["neoservers"]=neoservers
    end
    action :run
end

template "/home/ubuntu/neo4j/conf/neo4j.properties" do
    path "/home/ubuntu/neo4j/conf/neo4j.properties"
    source "neo4j.properties.erb"
    owner "root"
    group "root"
    mode "0644"
    variables({
      :server_id => server_id, :neoservers => node[:neoservers]
      })
    #notifies :restart, "service[neo4j]"
    #action :nothing
end

You're getting bitten by compile vs. converge time ordering issues. You can work around the issue by accessing `node[:neoservers]` directly in your template.


-- 
Daniel DeLeo



  • [chef] Re: how to load a json object in a ruby block and pass to a template, Daniel DeLeo, 04/03/2013

Archive powered by MHonArc 2.6.16.

§