[chef] Re: Re: How to override node attribute with lazy value?


Chronological Thread 
  • From: Greg Barker < >
  • To:
  • Subject: [chef] Re: Re: How to override node attribute with lazy value?
  • Date: Thu, 2 Oct 2014 11:18:55 -0700

Thanks Noah. I tried it out but I don't think I'm doing it right.

node["chef-server"]["configuration"]["nginx"] % { ssl_certificate: "/etc/pki/tls/certs/#{node[:fqdn]}.pem" }

This resulted in:

NoMethodError - undefined method `%' for nil:NilClass

So before that line I added:

node.default["chef-server"]["configuration"]["nginx"] = {}

But now I get the error:

NoMethodError - Undefined node attribute or method `%' on `node'

Any ideas?

On Thu, Oct 2, 2014 at 7:55 AM, Noah Kantrowitz < " target="_blank"> > wrote:

On Oct 2, 2014, at 3:13 AM, Greg Barker < "> > wrote:

> The chef-server readme shows how to override nginx attributes. However, it doesn't seem to work like I want it to when I do:
>
> node.override["chef-server"]["configuration"]["nginx"]["ssl_certificate"] = "/etc/pki/tls/certs/#{node[:fqdn]}.pem"
>
> node[:fqdn] is being updated during my chef run using the hostname cookbook, and so using the above results in an error because chef-server ends up looking for /etc/pki/tls/certs/localhost.pem (the old hostname), when it should instead be using /etc/pki/tls/certs/mynode.mycompany.com.pem.
>
> So I think I want something like the following, but this doesn't work. What's the right way to do it?
>
> node.override["chef-server"]["configuration"]["nginx"]["ssl_certificate"] = lazy { "/etc/pki/tls/certs/#{node[:fqdn]}.pem" }

lazy{} is a feature of resources, not of node attributes. See https://coderanger.net/derived-attributes/  for more information about how to handle delayed interpolation in node attributes.

--Noah





Archive powered by MHonArc 2.6.16.

§