2
votes

I'm fixing a cookbook for redis, with 2 distinct recipes + a default one. On the default recipe I add the a PPA repository and do the apt-get update stuff. What I would like to do is be able to persist on the node, only the attributes for the corresponding enabled recipes:

If the node includes "server" recipe, then store the defaults from attributes/server.rb If the node includes "client" recipe, then store the defaults from attributes/client.rb

The documentation isn't clear enough to whether the above will happen or it will store both, despite the recipes inclusion.

What i've seen people suggesting is to move the node.default[...] definitions that are specific to a recipe only and does not fit on "default" recipe to the recipe itself. I believe that this is non logical.

What is the "best-practice" to achieve this separation?

2
That's the typical best practice. You can use something like github.com/poise/poise-appenv otherwise. - Mahmoud Abdelkader

2 Answers

0
votes

The key quote from Chef's documentation is: "When a cookbook is run against a node, the attributes contained in all attribute files are evaluated in the context of the node object." (emphasis mine). You can only achieve what you're talking about by moving to using node.(scope) in the recipes.

0
votes

For thing you need in the client recipe

node[:redis][:client][:foo] = "bar"

For things you need in the server recipe

node[:redis][:server][:foo] = "bar"

Out of curiosity, which redis recipe are you using?