Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Enforce order of execution in chef recipes

Tags:

chef-infra

I have two recipes:

  1. Configures my home directory with things like my .bashrc, run on almost every machine I use
  2. Mounts an EBS volume containing my home directory. This only gets used by a single EC2 instance at a time, but lets me easily migrate to a new instance

In the case of this EC2 instance when it first boots up, I need recipe #2 to be executed before recipe #1 or the volume won't be mounted yet. How can I ensure that this order of execution will be explicitly forced?

like image 552
Mark Roddy Avatar asked Nov 29 '25 04:11

Mark Roddy


1 Answers

Chef always executes recipes in the order you specify them. It will not arbitrarily reorder things. So if you want one recipe to be run before another, just load them in that order (e.g. In the run_list)

To further enforce this (at the expense of additional coupling between your recipes) you can also use include_recipe at he beginning of the second recipe to load the first one.

like image 85
Holger Just Avatar answered Dec 02 '25 03:12

Holger Just