[chef] Re: Re: Re: Is there a difference between setting attributes like this?


Chronological Thread 
  • From: Greg Barker < >
  • To: " " < >
  • Subject: [chef] Re: Re: Re: Is there a difference between setting attributes like this?
  • Date: Thu, 12 Feb 2015 18:01:37 -0800

Thanks for the feedback!

Regarding setting the attributes in recipe code like that, I got it from this blog post that cheeseplus linked me to in IRC. Today I've been trying to experiment with using Environment Cookbooks and Role Cookbooks but I'm having a hard time wrapping my head around it. Regular Environments & Roles make a lot of sense to me, and I understand some of the downsides to them. I like that I get a version number associated with the environment and role if they are moved to cookbooks. I'm just not clear to me if what I'm gonna end up with after this refactoring is ideal, or if it's just gonna be a mess of different types of cookbooks and simple roles that only reference the role cookbook they are associated with. Other questions arise along the way like, if I have a mycorp-base cookbook, do I need a mycorp_base role, or can I just have the mycorp-myapp-jenkins cookbook do include_recipe "mycorp-base" ? Do I keep the myapp_jenkins role and have the run_list set to role["mycorp-base"], recipe["mycorp-myapp-jenkins"] ?

I'm also a little unsure if things have changed enough since posts I'm basing this off like this one and this one were written that maybe there's other some best practice to follow now?

On Thu, Feb 12, 2015 at 5:37 PM, Lamont Granquist < " target="_blank"> > wrote:

Also you don't want to use node.set, you want to use node.default or maybe node.override if you have to.  When you use node.set that is an alias for node.normal which has the side effect of persisting data permanently in the node object.  If you delete those lines, you'll find the attributes are still set, which can be highly confusing.  The normal and override attribute precedence levels are actually wiped at the start of the chef run and re-built completely by your code which is what you actually want.  You should only use 'node.set' or 'node.normal' if you're doing something like generating a password for a database on the first run and you need to remember that (and even there you should probably use a data bag).

And one last thing is that its better to move those kinds of settings into an attributes file if at all possible and not set attributes in recipe code like that.


On 2/12/15 3:53 PM, Sean Clemmer wrote:
Yes.

The first version will replace the entire node.openssh.server attribute with the Hash you've provided. The second will only update node.openssh.server.port and node.openssh.server.permit_root_login. So if there were other attributes like node.openssh.server.example declared elsewhere, the first version would blow away this value, while the second would not.

On Thu, Feb 12, 2015 at 3:41 PM, Greg Barker < " target="_blank"> > wrote:
This is for my "base cookbook", wasn't sure if there was a difference between setting attributes like this:

node.set["openssh"]["server"] = {
  "port" => 22,
  "permit_root_login" => "no"
}

Versus setting them like this:
node.set["openssh"]["server"]["port"] = 22
node.set["openssh"]["server"]["permit_root_login"] = "no"

Thanks!






Archive powered by MHonArc 2.6.16.

§