How to override_attribtes per environment in roles file?

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?


@millisami
~ Sachin Sagar Rai
Ruby on Rails Developer
http://tfm.com.np
http://nepalonrails.tumblr.com
Sent with Sparrow (http://www.sparrowmailapp.com/?sig)

Hi,

On Thu, Nov 1, 2012 at 7:43 PM, Sachin Sagar Rai millisami@gmail.comwrote:

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

Hi,

On Thu, 1 Nov 2012 14:28:27 +0545
Sachin Sagar Rai millisami@gmail.com 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.

I proposed the following feature some time ago:

http://tickets.opscode.com/browse/CHEF-3441

Do you think it would be interesting to have it?

--
Xabier de Zuazo
IT System Administrator - Onddo Labs S.L.