Consequences of enabling unified mode?

Apparently chef 16 introduced a new "unified mode" for custom resources, chef 17 is actively suggesting to enable it and chef 18 will enable it by default.

As a result cookstyle has now (quite reasonably) started to suggest enabling it.

My problem is that I can't find out what it actually does, beyond a one line summary in various release announcements, and as far as I can tell it is never mentioned anywhere in the documentation.

So what are the consequences of enabling it? Presumably there is some risk that existing custom resources will need changes when using it or it would just have been turned on by default.

So what do I need to look out for when considering enabling it for a resource?

1 Like

"unified mode" is a way of making sure that ruby code outside of a ruby_block resource is executed in proper sequence, instead of being executed before any other resources. That way, it prevents out-of-sequence execution of code. I've actually been using it for quite some time, and if you have something like a custom resource, it's a godsend.

Just to be clear, are you stating that the Recipe DSL for resources will compile and converge at the same time when unified mode is enabled versus compiling and being thrown on the resource collection, to be converged in order at the end of compilation?

I have lots of custom resources - a total of 41 in fact.

What I have no idea about is how many are relying on the current behaviour, which doesn't seem to be that surprising to me, as it's the same as a cookbook - the code that defines the resources runs first and then the resources run later.

So in unified mode sub-resources in a custom resource are effectively executed as soon as they are defined?

Or are you saying that when the custom resource executes it is effectively compiled at that point and then all the resources it defined are executed?

I mean that still leaves open the possibility of hard to predict changes in behaviour so I guess I'm going to have to test each of these resources carefully before enabling unified mode.

your recipe


my_resource_1
<ruby_statement3>
my_resource_2

"traditional mode" - all ruby code outside a ruby_block is executed first, then resources are executed. This can cause unintended consequences like out-of-order execution of the ruby code, as s1,s2,s3,r1,r2, when what you wanted was s1, s2,r1,s3,r2.

"unified mode" the recipe is guaranteed to execute as s1,s2,r1,s3,r2. In other words, more like a traditional programming language. So if you've done some code finagling to make things run the way you want, you may be able to "de-finagle" your code and make it easier to deal with.