[chef] Re: How to override_attribtes per environment in roles file?


Chronological Thread 
  • From: Peter Donald < >
  • To: Chef Mailing List < >
  • Subject: [chef] Re: How to override_attribtes per environment in roles file?
  • Date: Thu, 1 Nov 2012 20:29:46 +1100

Hi,

On Thu, Nov 1, 2012 at 7:43 PM, Sachin Sagar Rai < " target="_blank"> > wrote:
Following is the role file named ftpserver at roles/ftpserver.rb

    override_attributes(
      :vsftpd => {
        :chroot_users => ["ftpuser"]
      }
    )

One way is to override it from the environments/some-env.rb file.

But I think to look its values later, I'll have to re-map opening individual env files.

It would be better if I could just add it in the roles file per env like env_run_list.

Is this already in chef or any plugins?

The way we deal with it is to create a cookbook/recipe per role.  So we would introduce a cookbook named "mybiz-ftpserver". Then have it do any of the environment specific logic before including the relevant recipes. Something like;

file: mybiz-ftpserver/recipes/default.rb
--------------------------------------------------------
if node.environment == 'production'
  node.override['vsftpd']['chroot_users'] = ["ftpuser"]
else 
  node.override['vsftpd']['chroot_users'] = ["other_ftpuser"]
end

include_recipe 'vsftpd::default'
--------------------------------------------------------

And then the role would look something like

roles/ftpserver.rb
--------------------------------------------------------
name "ftpserver"
description "ftpserver"
run_list('mybiz-ftpserver')
--------------------------------------------------------

That way all the logic you want for environment specific customisation is explicit in a cookbook and relatively easy to understand.


HTH,

Peter Donald



Archive powered by MHonArc 2.6.16.

§