[chef] Overriding conditional attributes in a wrapper cookbook?


Chronological Thread 
  • From: Mick Brooks < >
  • To:
  • Subject: [chef] Overriding conditional attributes in a wrapper cookbook?
  • Date: Sat, 8 Feb 2014 02:18:11 +0000

Hi,

I'm trying to write a wrapper cookbook for postfix, with the intention of just setting some attributes for my organisation. However, some of the attributes defined in the postfix cookbook are 'conditional' i.e. whether they're defined depends on values of other attributes. That decision is being made when postfix's attributes/default.rb file is processed, which is before the attributes for my wrapper are processed, and so (some of) the attributes I'm setting in the wrapper are being ignored. Well, not ignored exactly: their values are updated, but the values of attributes defined conditionally on them are not. 

Here's a concrete example. The postfix cookbook has an attributes/default.rb file with:
----
if node['postfix']['main']['smtp_sasl_auth_enable'] == 'yes'
  ...
  default['postfix']['main']['smtp_sasl_security_options'] = 'noanonymous'
  ...
end
----

In my wrapper I added an attributes/default.rb file with:
----
override['postfix']['main']['smtp_sasl_auth_enable'] = 'yes'
----

but, when the postfix recipe is run the node['postfix']['main']['smtp_sasl_auth_enable'] value is not being defined i.e. my override has not fully taken effect.

Is there a way to set the node['postfix']['main']['smtp_sasl_auth_enable'] value from my wrapper
such that node['postfix']['main']['smtp_sasl_security_options'] = 'noanonymous' is declared as in
the postfix cookbook?

I did find the documentation about reloading attributes[1], but updating my recipes/default.rb file
to:
----
ruby_block 'some_code' do
  block do
    node.from_file(run_context.resolve_attribute("postfix", "default"))
  end
  action :create
end

include_recipe 'postfix::default'
include_recipe 'postfix::sasl_auth'
----

didn't seem to help. What am I doing wrong?

Thanks in advance,

Mick


--



Archive powered by MHonArc 2.6.16.

§