Idempotence is one of the principles of Chef.
This means that your recipe can run over and over again, and it will only change things that are not as expected.
So in your case it would look like this:
- First Chef run notices that an unexpected kernel is installed. It thus installs the kernel and triggers a reboot.
- Chef runs again, identifies that the kernel is installed as expected and thus just continues. Now you can continue with other things.
One note: I've never tried this, but signalling a reboot
in the middle of a Chef run could do some damage. I'd recommend to abort the chef run after the reboot
signal (e.g. through raising an Exception, see How do you abort/end a Chef run?).