[chef] Databags parsing and templates


Chronological Thread 
  • From: Philippe Bérard < >
  • To: < >
  • Subject: [chef] Databags parsing and templates
  • Date: Fri, 14 Dec 2012 15:49:12 +0100

I think I’ve a quite simple question for experts here, but this one’s driving me mad as there are only a very few examples on how to use databags with templates on the Web.

 

I have a databag on my CHEF server, named “instances” and organized like this :

owner : nobody

id : instances

type : dbapp {

                Java_webapp

               Tomcat

}

webapps : {

_default {

                port : “8001”

                name : “preprod1.test.com”

}

                testjava {

                port : “8002”

                name : “preprodjava.test.com”

}

                Testtomcat {

                port “8003”

                name : “preprodtomcat.test.com”

}

}

 

A template :

è /templates/default/test.conf.erb :

# Set up application listeners here.

worker.list = jkstatus

 

# Test configuration

 

<% @server.each do |server, port| %>

<%= server %>, <%= port %>

<% end %>

 

And my recipe to generate a proper configuration file :

è /recipes/default.rb

#

# Cookbook Name:: testdatabag

# Recipe:: default

#

# Copyright 2012, TEST

#

# All rights reserved - Do Not Redistribute

#

require 'chef/data_bag'

 

server=[]

port=[]

 

data_bag(‘instances’).each do |webapps|

    s = data_bag_item(‘instances’,'webapps')

    server << s['name']

    port << s['port']

end

 

 

template "test.conf" do

  path "/tmp/test.conf"

  source "test.conf.erb"

  owner "root"

  group "root"

  mode "0644"

  variables(

                :server => server,

                :port => port

)

 

My result should be :

# Test configuration

preprod1.test.com, 8001

preprodjava.test.com, 8002

preprodtomcat.test.com, 8003

 

And, well, it doesn’t work at all.

 

Thanks in advance for any help or hint.

 

Regards,

 

Philippe Bérard




Archive powered by MHonArc 2.6.16.

§