I want to implement env_attributes() in Chef roles


#1

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.


#2

Hello DV,

On Thu, 14 Nov 2013 11:02:06 -0800
DV 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

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

Public Key = http://www.onddo.com/xabier_zuazo.pub
Key Fingerprint = 8EFA 5B17 7275 5F1F 42B2 26B4 8E18 8B67 9DE1 9468


#3

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

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

Hello DV,

On Thu, 14 Nov 2013 11:02:06 -0800
DV 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

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

Public Key = http://www.onddo.com/xabier_zuazo.pub
Key Fingerprint = 8EFA 5B17 7275 5F1F 42B2 26B4 8E18 8B67 9DE1 9468


#4

That doesn’t make sense… :confused: 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.comwrote:

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

On Thu, Nov 14, 2013 at 12:49 PM, Xabier de Zuazo xabier@onddo.comwrote:

Hello DV,

On Thu, 14 Nov 2013 11:02:06 -0800
DV 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

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

Public Key = http://www.onddo.com/xabier_zuazo.pub
Key Fingerprint = 8EFA 5B17 7275 5F1F 42B2 26B4 8E18 8B67 9DE1 9468


Best regards, Dmitriy V.


#5

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

On Thu, Nov 14, 2013 at 1:24 PM, DV vindimy@gmail.com wrote:

That doesn’t make sense… :confused: 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

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

On Thu, Nov 14, 2013 at 12:49 PM, Xabier de Zuazo xabier@onddo.comwrote:

Hello DV,

On Thu, 14 Nov 2013 11:02:06 -0800
DV 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

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

Public Key = http://www.onddo.com/xabier_zuazo.pub
Key Fingerprint = 8EFA 5B17 7275 5F1F 42B2 26B4 8E18 8B67 9DE1 9468


Best regards, Dmitriy V.


#6

Hi DV,

On Thu, 14 Nov 2013 13:24:57 -0800
DV 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!

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:




[…]

Regards,


Xabier de Zuazo Oteiza
IT System Administrator - Onddo Labs S.L.
www.onddo.com

Public Key = http://www.onddo.com/xabier_zuazo.pub
Key Fingerprint = 8EFA 5B17 7275 5F1F 42B2 26B4 8E18 8B67 9DE1 9468


#7

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 wrote:

Hi DV,

On Thu, 14 Nov 2013 13:24:57 -0800
DV 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!

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:

https://github.com/opscode/chef_db/blob/master/src/chef_otto.erl#L290

https://github.com/opscode/chef_wm/blob/master/src/chef_wm_malformed.erl#L122
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

Public Key = http://www.onddo.com/xabier_zuazo.pub
Key Fingerprint = 8EFA 5B17 7275 5F1F 42B2 26B4 8E18 8B67 9DE1 9468


Best regards, Dmitriy V.