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


Chronological Thread 
  • From: Greg Barker < >
  • To: Mathieu Martin < >
  • Cc: " " < >
  • Subject: [chef] Re: How to override node attribute with lazy value?
  • Date: Sat, 4 Oct 2014 09:40:37 -0700

Mathieu, it's the opacide chef-server cookbook that ends up using this attribute. That's the problem. :)

On Friday, October 3, 2014, Mathieu Martin < "> > wrote:
Greg, just to make sure, since we don't see how you're using that interpolation:

node["chef-server"]["configuration"]["nginx"]["ssl_certificate"] % { fqdn: node[:fqdn] }

This ^ line of Ruby code returns the string you're looking for. It doesn't modify the string stored in your attribute.

In other words, this whole line should either be assigned to a variable, or be right in your template, like:

  ssl_certificate <%= node["chef-server"]["configuration"]["nginx"]["ssl_certificate"] % { fqdn: node[:fqdn] } %>;

Is that how you were using this?

Mat

On Fri, Oct 3, 2014 at 8:13 PM, Lamont Granquist < ');" target="_blank"> > wrote:
On Fri Oct  3 16:39:36 2014, Lamont Granquist wrote:

How it should be written, i'll look at submitting a PR...


Sorry look like I fell victim to thinking that all problems were like my last problem.

The hostname is getting set at converge time, fairly late, by the hostname cookbook.  Your node['fqdn'] will be the old hostname throughout the whole compile phase of the chef-client run.  In your case since you control the code it'll be way easier to use the node['set_fqdn'] attribute that you're passing to the hostname cookbook to pass to the
chef-server cookbook:

node.override["chef-server"]["configuration"]["nginx"]["ssl_certificate"] = "/etc/pki/tls/certs/#{node['set_fqdn']}.pem"

If that doesn't work for you then you may have an issue trying to do that.  The attributes are most likely getting passed into the template variable sometime in compiletime and your node['fqdn'] isn't getting updated until converge time.   Either the hostname cookbook needs to be changed to do its work at compile-time or else the chef-server cookbook needs to be converted to be lazy.

A better approach would probably be for the hostname cookbook to expose a ruby library to call to get the desired hostname (basically sugar around either returning node['set_fqdn'] or else returning the output of "/usr/sbin/vmtoolsd --cmd 'info-get guestinfo.hostname'") and then you could get that value at compile time and set attributes with it just fine.





--

Organizer of DevOpsMtl. @webmatLinkedIn, blog.



Archive powered by MHonArc 2.6.16.

§