Search code examples
chef-infrachef-recipechef-solo

Chef skip recipes


I have 2 roles:

base.json

{
  "chef_type": "role",
  "default_attributes": {},
  "description": "Base Machine",
  "env_run_lists": {},
  "json_class": "Chef::Role",
  "name": "base",
  "override_attributes": {},
  "run_list": [
    "recipe[apt]",
    "recipe[clean-up]"
  ]
}

web.json which includes base role

  {
    "chef_type": "role",
    "default_attributes": {},
    "description": "Web Machine",
    "env_run_lists": {},
    "json_class": "Chef::Role",
    "name": "web",
    "override_attributes": {},
    "run_list": [
      "role[base]",
      "recipe[nginx]",
      "recipe[clean-up]"
    ]
  }

when I run, the run_list will be expanded as: recipe[apt], recipe[clean-up], recipe[nginx]. Note that it skipped the last recipe[clean-up] of the web role. Why is it? Is there anyway that I can force to rerun recipe[clean-up]?


Solution

  • No, Chef is a configuration management system, not a script runner.

    Each recipe is supposed to be run once and get the system in a particular state.

    This is done in many phases:

    1. Sync the runlist (after expanding it, each recipe once in the order they appear)
    2. Compile the resources in each recipe, making a resources collection (in order they appear too)
    3. Converge: run the code for each resource (provider code) and do something if the desired state differ from the current state.
    4. Run the delayed notifications triggered by updated resources.

    More details here

    The main idea is to decribe a system state, and be able to run N times not changing the system if it's in the desired state.

    You can remove this recipe from your base role or you can do a "closing" role wich you ensure appear at the end of each node runlist.