2

I am trying to configure some nodes with specific run_lists depending on environment. So I created environments, then created role and specified env_run_list, and after that created node my_node_ip.json:

{
  "chef_environment": "test",
  "run_list":["role[base]"]
}

but when I start knife solo cook, the _default environment is set. Just after I make -E test flag it works right. This is not right behavior that I expect when I specify chef_environment variable in node's config.

Is there better way to avoid of using -E flag?

StephenKing
  • 36,187
  • 11
  • 83
  • 112
Dmytro
  • 2,200
  • 3
  • 20
  • 32
  • 3
    No.... The -E parameter is how you specify an environment. Environments do not appear on run lists. Equally an environment is not a node attribute. – Mark O'Connor Apr 23 '14 at 23:45
  • You are right, there is no "chef_environment" attribute for node, I saw it in bad article about environments :) So is there no way to config node to be in "test" environment by default? It makes me to remember all the time about node and it's stage. – Dmytro Apr 24 '14 at 12:05
  • There is a "_default" environment but best steer clear of customizing that! What is the problem you're trying to solve? To control node run-lists I generally use a chef role. However complex run-time decisions are best put into cookbook recipes, where the logic can be kept under revision control and loaded into chef server using tools like Berkshelf. – Mark O'Connor Apr 27 '14 at 11:29
  • @MarkO'Connor I have environment config which has options for default/vagrant/test environments, also there is a role "base" which has env_run_lists for every defined environment. and I have a node with role[base] in it's runlist. So when I make new node I just wanted to specify env for it in configs and forget about it :) because vagrant node will always be just with vagrant env. There is no problem to put one more flag to "cook" command, but it is little bit sweeter to write just "knife solo cook ip" – Dmytro Apr 27 '14 at 11:41
  • You could do this just as easily in an application cookbook, testing the value of "node.chef_environment". Fact is there are lots of ways to do this in chef. I just recommend keeping complex logic in Cookbooks where it can be version controlled. – Mark O'Connor Apr 27 '14 at 12:41

0 Answers0