[chef] Re: Re: Re: Libraries being used in templates.


Chronological Thread 
  • From: Scott Likens <scott@likens.us>
  • To: chef@lists.opscode.com
  • Subject: [chef] Re: Re: Re: Libraries being used in templates.
  • Date: Fri, 24 Jul 2009 12:06:22 -0700

Hi Adam,

actually it was just me being tired and screwing up, but I finally wrangled it.

all_vhosts do |name, info|
  template "#{node[:affnginx][:dir]}/sites-available/#{name}.conf" do
    source "default-site.erb"
    owner "root"
    group "root"
    backup false
    mode 0644
    variables(
      :name => name,
      :ipaddress => info[:ipaddress],
      :networkid => info[:networkid]
    )
  end
end

Works just fine, and as far as my limited testing (it's pulling in 5 vhosts via attributes) just fine. I may find a great use for libraries now with nginx and apache and will find a way to enjoy this ability greatly.

Scott

(mainly the error was in the variables the lack of : in :name initially which threw me off and confused me... tunnel vision is a great thing sometimes, and fun to break out of)

On Jul 24, 2009, at 8:38 AM, Adam Jacob wrote:

What was it?

Adam

On Fri, Jul 24, 2009 at 12:10 AM, Scott Likens<scott@likens.us> wrote:
Cancel this.

Got it all straightened out.

On Jul 23, 2009, at 10:54 PM, Scott Likens wrote:

Hello all,

I had recently dug myself into using libraries and wondered if anyone had
a way to make it work in templates?

I was looking at http://wiki.opscode.com/display/chef/Libraries and
noticed it did not mention the word templates,

so I whipped up something like this,

all_vhosts do |name, info|
 template "/etc/nginx/sites-available/#{name}.conf" do
 source "default-site.erb"
 owner "www-data"
 group "www-data"
 mode 0644
 variables(
  name => name
 )
 end
end

I can't seem to obviously get name to iterate properly? (not sure if
that's the right word) but @name never appears in the template, as a simple
<%= @name %> shows zilch.

Obviously this works super clean and awesome in 1/2 of my recipe, but I
was wondering if anyone had any thoughts on the last part of this hurdle?
I'm sure it's something I've overlooked but I'd love a hint/ pointer/etc?

Thanks

Sincerely,

Scott M. Likens









--
Opscode, Inc.
Adam Jacob, CTO
T: (206) 508-7449 E: adam@opscode.com

!DSPAM:4a69d59179371394918276!






Archive powered by MHonArc 2.6.16.

§