Search code examples
chef-infrachef-recipeknifecookbook

How do I rename a recipe and replace it on the run list of all nodes


Let's say I have a recipe called my_cookbook::recipe_old.rb. This recipe has been applied to the run list of nodes, roles, etc.

But let's say I need to rename the recipe to recipe_new.rb. How can I update the run list of all my nodes and roles?

I'm thinking I'd have to do a knife search to find all nodes and roles with the recipe applied, add the newly named recipe to their run lists, then delete the old recipe from their run lists.

Is this the best way or does Chef have a better solution for this?


Solution

  • Something like this

    knife exec -E 'nodes.transform("*:*") {|n| n.run_list.each_index {|i| if n.run_list[i] == "recipe[my_cookbook::recipe_old]"; n.run_list[i] = "recipe[my_cookbook::recipe_new"; return true; end } false }'
    

    And then something similar for roles.transform.