# I want to implement env\_attributes() in Chef roles

**URL:** <https://discourse.chef.io/t/i-want-to-implement-env-attributes-in-chef-roles/4675>\
**Category:** Chef Infra (archive)\
**Created:** [November 14, 2013, 7:02pm UTC](https://discourse.chef.io/t/i-want-to-implement-env-attributes-in-chef-roles/4675 "2013-11-14T19:02:06Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![DV1](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.chef.io/dv1/32/186_2.png) [@DV1](https://discourse.chef.io/u/DV1)\
**Post date:** [November 14, 2013, 7:02pm UTC](https://discourse.chef.io/t/i-want-to-implement-env-attributes-in-chef-roles/4675/1 "2013-11-14T19:02:06Z")

</div>

Hey all,

I’m trying to come up with an efficient way to promote changes to our  
applications one environment at a time. Say I have 4 prod environments, and  
many roles in each environment, some for database, some for app server,  
etc. My task is to promote a new version of database to each environment in  
a specific role only, one environment at a time (to avoid downtime).

If I update the database version attribute in the role, it’ll update all  
environments. If I update the database version attribute in the  
environment, it’ll update all databases in that environment, not only the  
one I’m targeting.

I want to have ability to specify something like the following in the role:

env\_attributes(  
“env-1” =\> {  
“database” =\> {  
“version” =\> “1.2.3”  
}  
},  
“env-2” =\> {  
“database” =\> {  
“verison” =\> “1.2.1”  
}  
}  
)

My current solution is to use env\_run\_lists() to do this, but it’s  
time-consuming as I have to create a new recipe each time I want to upgrade  
to new version.

Does that make sense? Would anyone know how I can go about implementing  
this role functionality?

–  
Best regards, Dmitriy V.

---

<div class="post-metadata">

**Author:** ![zuazo\_onddo](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.chef.io/zuazo_onddo/32/137_2.png) [@zuazo\_onddo](https://discourse.chef.io/u/zuazo_onddo)\
**Post date:** [November 14, 2013, 8:49pm UTC](https://discourse.chef.io/t/i-want-to-implement-env-attributes-in-chef-roles/4675/2 "2013-11-14T20:49:50Z")

</div>

Hello DV,

On Thu, 14 Nov 2013 11:02:06 -0800  
DV [vindimy@gmail.com](mailto:vindimy@gmail.com) wrote:

[...]

> I want to have ability to specify something like the following in the  
> role:
> 
> env\_attributes(  
> "env-1" =\> {  
> "database" =\> {  
> "version" =\> "1.2.3"  
> }  
> },  
> "env-2" =\> {  
> "database" =\> {  
> "verison" =\> "1.2.1"  
> }  
> }  
> )
> 
> My current solution is to use env\_run\_lists() to do this, but it's  
> time-consuming as I have to create a new recipe each time I want to  
> upgrade to new version.
> 
> Does that make sense? Would anyone know how I can go about  
> implementing this role functionality?

An old ticket related to this topic:

[https://tickets.opscode.com/browse/CHEF-3441](https://tickets.opscode.com/browse/CHEF-3441)

I recommend you read the comments below. It seems that it would not be  
advisable to use this feature in case of adding it to the core.

I started the implementation of this some time ago. It's actually quite  
simple. But I didn't continue with it because it seemed that there was  
no interest.

Regards,

## -- Xabier de Zuazo Oteiza IT System Administrator - Onddo Labs S.L. [www.onddo.com](http://www.onddo.com)

## Public Key = [http://www.onddo.com/xabier\_zuazo.pub](http://www.onddo.com/xabier_zuazo.pub) Key Fingerprint = 8EFA 5B17 7275 5F1F 42B2 26B4 8E18 8B67 9DE1 9468

---

<div class="post-metadata">

**Author:** ![Morgan\_Blackthorne](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.chef.io/morgan_blackthorne/32/100_2.png) [@Morgan\_Blackthorne](https://discourse.chef.io/u/Morgan_Blackthorne)\
**Post date:** [November 14, 2013, 9:10pm UTC](https://discourse.chef.io/t/i-want-to-implement-env-attributes-in-chef-roles/4675/3 "2013-11-14T21:10:11Z")

</div>

Something I heard at the Summit was that folks are thinking of deprecating  
environment run lists.

--  
~_~ StormeRider ~_~

"Every world needs its heroes [...] They inspire us to be better than we  
are. And they protect from the darkness that's just around the corner."

(from Smallville Season 6x1: "Zod")

On why I hate the phrase "that's so lame"... [http://bit.ly/Ps3uSS](http://bit.ly/Ps3uSS)

On Thu, Nov 14, 2013 at 12:49 PM, Xabier de Zuazo [xabier@onddo.com](mailto:xabier@onddo.com) wrote:

> Hello DV,
> 
> On Thu, 14 Nov 2013 11:02:06 -0800  
> DV [vindimy@gmail.com](mailto:vindimy@gmail.com) wrote:
> 
> [...]
> 
> > I want to have ability to specify something like the following in the  
> > role:
> > 
> > env\_attributes(  
> > "env-1" =\> {  
> > "database" =\> {  
> > "version" =\> "1.2.3"  
> > }  
> > },  
> > "env-2" =\> {  
> > "database" =\> {  
> > "verison" =\> "1.2.1"  
> > }  
> > }  
> > )
> > 
> > My current solution is to use env\_run\_lists() to do this, but it's  
> > time-consuming as I have to create a new recipe each time I want to  
> > upgrade to new version.
> > 
> > Does that make sense? Would anyone know how I can go about  
> > implementing this role functionality?
> 
> An old ticket related to this topic:
> 
> [https://tickets.opscode.com/browse/CHEF-3441](https://tickets.opscode.com/browse/CHEF-3441)
> 
> I recommend you read the comments below. It seems that it would not be  
> advisable to use this feature in case of adding it to the core.
> 
> I started the implementation of this some time ago. It's actually quite  
> simple. But I didn't continue with it because it seemed that there was  
> no interest.
> 
> Regards,
> 
> ## -- Xabier de Zuazo Oteiza IT System Administrator - Onddo Labs S.L. [www.onddo.com](http://www.onddo.com)
> 
> ## Public Key = [http://www.onddo.com/xabier\_zuazo.pub](http://www.onddo.com/xabier_zuazo.pub) Key Fingerprint = 8EFA 5B17 7275 5F1F 42B2 26B4 8E18 8B67 9DE1 9468

---

<div class="post-metadata">

**Author:** ![DV1](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.chef.io/dv1/32/186_2.png) [@DV1](https://discourse.chef.io/u/DV1)\
**Post date:** [November 14, 2013, 9:24pm UTC](https://discourse.chef.io/t/i-want-to-implement-env-attributes-in-chef-roles/4675/4 "2013-11-14T21:24:57Z")

</div>

That doesn't make sense... 😕 There's a well-defined need for having  
role+environment specific attributes. Most organizations have multiple prod  
environments and want to roll out upgrades one environment at a time.

I think the method of having a switch/if statement in recipe or using  
environment run lists is too burdensome... Plus I want my users to stop  
writing one-off recipes. Having env attributes would make it super easy to  
get the big picture by looking at just one role.

Xabier, if you have any code from your attempt you can share or point me to  
the right direction, I'd like to give it a try!

On Thu, Nov 14, 2013 at 1:10 PM, Morgan Blackthorne  
[stormerider@gmail.com](mailto:stormerider@gmail.com)wrote:

> Something I heard at the Summit was that folks are thinking of deprecating  
> environment run lists.
> 
> --  
> ~_~ StormeRider ~_~
> 
> "Every world needs its heroes [...] They inspire us to be better than we  
> are. And they protect from the darkness that's just around the corner."
> 
> (from Smallville Season 6x1: "Zod")
> 
> On why I hate the phrase "that's so lame"... [http://bit.ly/Ps3uSS](http://bit.ly/Ps3uSS)
> 
> On Thu, Nov 14, 2013 at 12:49 PM, Xabier de Zuazo [xabier@onddo.com](mailto:xabier@onddo.com)wrote:
> 
> > Hello DV,
> > 
> > On Thu, 14 Nov 2013 11:02:06 -0800  
> > DV [vindimy@gmail.com](mailto:vindimy@gmail.com) wrote:
> > 
> > [...]
> > 
> > > I want to have ability to specify something like the following in the  
> > > role:
> > > 
> > > env\_attributes(  
> > > "env-1" =\> {  
> > > "database" =\> {  
> > > "version" =\> "1.2.3"  
> > > }  
> > > },  
> > > "env-2" =\> {  
> > > "database" =\> {  
> > > "verison" =\> "1.2.1"  
> > > }  
> > > }  
> > > )
> > > 
> > > My current solution is to use env\_run\_lists() to do this, but it's  
> > > time-consuming as I have to create a new recipe each time I want to  
> > > upgrade to new version.
> > > 
> > > Does that make sense? Would anyone know how I can go about  
> > > implementing this role functionality?
> > 
> > An old ticket related to this topic:
> > 
> > [https://tickets.opscode.com/browse/CHEF-3441](https://tickets.opscode.com/browse/CHEF-3441)
> > 
> > I recommend you read the comments below. It seems that it would not be  
> > advisable to use this feature in case of adding it to the core.
> > 
> > I started the implementation of this some time ago. It's actually quite  
> > simple. But I didn't continue with it because it seemed that there was  
> > no interest.
> > 
> > Regards,
> > 
> > ## -- Xabier de Zuazo Oteiza IT System Administrator - Onddo Labs S.L. [www.onddo.com](http://www.onddo.com)
> > 
> > ## Public Key = [http://www.onddo.com/xabier\_zuazo.pub](http://www.onddo.com/xabier_zuazo.pub) Key Fingerprint = 8EFA 5B17 7275 5F1F 42B2 26B4 8E18 8B67 9DE1 9468

--  
Best regards, Dmitriy V.

---

<div class="post-metadata">

**Author:** ![Morgan\_Blackthorne](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.chef.io/morgan_blackthorne/32/100_2.png) [@Morgan\_Blackthorne](https://discourse.chef.io/u/Morgan_Blackthorne)\
**Post date:** [November 14, 2013, 9:45pm UTC](https://discourse.chef.io/t/i-want-to-implement-env-attributes-in-chef-roles/4675/5 "2013-11-14T21:45:32Z")

</div>

Well, like you said, env run lists are a bit of a burden, and with people  
writing more application cookbooks than roles, it's easier to put the logic  
into a recipe (and is currently a best practice since roles aren't  
versionable).

Until roles are versionable, which was loudly voted for at the Chef 12  
discussion, I doubt you'll see any official traction on this front.  
Currently less is more when it comes to roles.

--  
~_~ StormeRider ~_~

"Every world needs its heroes [...] They inspire us to be better than we  
are. And they protect from the darkness that's just around the corner."

(from Smallville Season 6x1: "Zod")

On why I hate the phrase "that's so lame"... [http://bit.ly/Ps3uSS](http://bit.ly/Ps3uSS)

On Thu, Nov 14, 2013 at 1:24 PM, DV [vindimy@gmail.com](mailto:vindimy@gmail.com) wrote:

> That doesn't make sense... 😕 There's a well-defined need for having  
> role+environment specific attributes. Most organizations have multiple prod  
> environments and want to roll out upgrades one environment at a time.
> 
> I think the method of having a switch/if statement in recipe or using  
> environment run lists is too burdensome... Plus I want my users to stop  
> writing one-off recipes. Having env attributes would make it super easy to  
> get the big picture by looking at just one role.
> 
> Xabier, if you have any code from your attempt you can share or point me  
> to the right direction, I'd like to give it a try!
> 
> On Thu, Nov 14, 2013 at 1:10 PM, Morgan Blackthorne \<[stormerider@gmail.com](mailto:stormerider@gmail.com)
> 
> > wrote:
> 
> > Something I heard at the Summit was that folks are thinking of  
> > deprecating environment run lists.
> > 
> > --  
> > ~_~ StormeRider ~_~
> > 
> > "Every world needs its heroes [...] They inspire us to be better than we  
> > are. And they protect from the darkness that's just around the corner."
> > 
> > (from Smallville Season 6x1: "Zod")
> > 
> > On why I hate the phrase "that's so lame"... [http://bit.ly/Ps3uSS](http://bit.ly/Ps3uSS)
> > 
> > On Thu, Nov 14, 2013 at 12:49 PM, Xabier de Zuazo [xabier@onddo.com](mailto:xabier@onddo.com)wrote:
> > 
> > > Hello DV,
> > > 
> > > On Thu, 14 Nov 2013 11:02:06 -0800  
> > > DV [vindimy@gmail.com](mailto:vindimy@gmail.com) wrote:
> > > 
> > > [...]
> > > 
> > > > I want to have ability to specify something like the following in the  
> > > > role:
> > > > 
> > > > env\_attributes(  
> > > > "env-1" =\> {  
> > > > "database" =\> {  
> > > > "version" =\> "1.2.3"  
> > > > }  
> > > > },  
> > > > "env-2" =\> {  
> > > > "database" =\> {  
> > > > "verison" =\> "1.2.1"  
> > > > }  
> > > > }  
> > > > )
> > > > 
> > > > My current solution is to use env\_run\_lists() to do this, but it's  
> > > > time-consuming as I have to create a new recipe each time I want to  
> > > > upgrade to new version.
> > > > 
> > > > Does that make sense? Would anyone know how I can go about  
> > > > implementing this role functionality?
> > > 
> > > An old ticket related to this topic:
> > > 
> > > [https://tickets.opscode.com/browse/CHEF-3441](https://tickets.opscode.com/browse/CHEF-3441)
> > > 
> > > I recommend you read the comments below. It seems that it would not be  
> > > advisable to use this feature in case of adding it to the core.
> > > 
> > > I started the implementation of this some time ago. It's actually quite  
> > > simple. But I didn't continue with it because it seemed that there was  
> > > no interest.
> > > 
> > > Regards,
> > > 
> > > ## -- Xabier de Zuazo Oteiza IT System Administrator - Onddo Labs S.L. [www.onddo.com](http://www.onddo.com)
> > > 
> > > ## Public Key = [http://www.onddo.com/xabier\_zuazo.pub](http://www.onddo.com/xabier_zuazo.pub) Key Fingerprint = 8EFA 5B17 7275 5F1F 42B2 26B4 8E18 8B67 9DE1 9468
> 
> --  
> Best regards, Dmitriy V.

---

<div class="post-metadata">

**Author:** ![zuazo\_onddo](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.chef.io/zuazo_onddo/32/137_2.png) [@zuazo\_onddo](https://discourse.chef.io/u/zuazo_onddo)\
**Post date:** [November 15, 2013, 6:30pm UTC](https://discourse.chef.io/t/i-want-to-implement-env-attributes-in-chef-roles/4675/6 "2013-11-15T18:30:54Z")

</div>

Hi DV,

On Thu, 14 Nov 2013 13:24:57 -0800  
DV [vindimy@gmail.com](mailto:vindimy@gmail.com) wrote:

[...]

> Xabier, if you have any code from your attempt you can share or point  
> me to the right direction, I'd like to give it a try!

> **[GitHub - zuazo-forks/chef at 10.28.2-CHEF-3441](https://github.com/zuazo-forks/chef/tree/10.28.2-CHEF-3441)**
>
> 10.28.2-CHEF-3441

I honestly don't remember how far I get. I rebased this against the  
las Chef 10 stable, but this code is more than a year old and is  
not tested, it may even be incomplete. Used the wrong way can destroy  
the space time continuum.

If you want to test this with Chef 11, you will also need to patch  
erchef:

> <https://github.com/chef-boneyard/chef_db/blob/master/src/chef_otto.erl#L290>

> <https://github.com/chef-boneyard/chef_wm/blob/master/src/chef_wm_malformed.erl#L122>

> <https://github.com/chef-boneyard/chef_objects/blob/master/src/chef_role.erl#L70>

[...]

Regards,

## -- Xabier de Zuazo Oteiza IT System Administrator - Onddo Labs S.L. [www.onddo.com](http://www.onddo.com)

## Public Key = [http://www.onddo.com/xabier\_zuazo.pub](http://www.onddo.com/xabier_zuazo.pub) Key Fingerprint = 8EFA 5B17 7275 5F1F 42B2 26B4 8E18 8B67 9DE1 9468

---

<div class="post-metadata">

**Author:** ![DV1](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.chef.io/dv1/32/186_2.png) [@DV1](https://discourse.chef.io/u/DV1)\
**Post date:** [November 18, 2013, 2:51am UTC](https://discourse.chef.io/t/i-want-to-implement-env-attributes-in-chef-roles/4675/7 "2013-11-18T02:51:41Z")

</div>

Thanks Xabier! Unfortunately I don't know much about Chef to be able to  
patch it.. If I end up implementing this sort of feature, I'll go the route  
of writing a special recipe that looks at a special place containing  
environments and attributes. Then it overrides attributes with the ones it  
found, if applicable. Finally, I'll place that special recipe first thing  
in the runlist.

On Fri, Nov 15, 2013 at 10:30 AM, Xabier de Zuazo [xabier@onddo.com](mailto:xabier@onddo.com) wrote:

> Hi DV,
> 
> On Thu, 14 Nov 2013 13:24:57 -0800  
> DV [vindimy@gmail.com](mailto:vindimy@gmail.com) wrote:
> 
> [...]
> 
> > Xabier, if you have any code from your attempt you can share or point  
> > me to the right direction, I'd like to give it a try!
> 
> [GitHub - zuazo-forks/chef at 10.28.2-CHEF-3441](https://github.com/onddo/chef/tree/10.28.2-CHEF-3441)
> 
> I honestly don't remember how far I get. I rebased this against the  
> las Chef 10 stable, but this code is more than a year old and is  
> not tested, it may even be incomplete. Used the wrong way can destroy  
> the space time continuum.
> 
> If you want to test this with Chef 11, you will also need to patch  
> erchef:
> 
> [chef\_db/src/chef\_otto.erl at master · chef-boneyard/chef\_db · GitHub](https://github.com/opscode/chef_db/blob/master/src/chef_otto.erl#L290)
> 
> [chef\_wm/src/chef\_wm\_malformed.erl at master · chef-boneyard/chef\_wm · GitHub](https://github.com/opscode/chef_wm/blob/master/src/chef_wm_malformed.erl#L122)  
> [chef\_objects/src/chef\_role.erl at master · chef-boneyard/chef\_objects · GitHub](https://github.com/opscode/chef_objects/blob/master/src/chef_role.erl#L70)  
> [...]
> 
> Regards,
> 
> ## -- Xabier de Zuazo Oteiza IT System Administrator - Onddo Labs S.L. [www.onddo.com](http://www.onddo.com)
> 
> ## Public Key = [http://www.onddo.com/xabier\_zuazo.pub](http://www.onddo.com/xabier_zuazo.pub) Key Fingerprint = 8EFA 5B17 7275 5F1F 42B2 26B4 8E18 8B67 9DE1 9468

--  
Best regards, Dmitriy V.
