Feature Friday #7: depends_on

Posted by Nick Anderson
April 26, 2024

Ever wanted to make sure a promise only runs if some other promise has succeeded?

Consider this contrived example with two reports type promises, It's Friday! and I love CFEngine Feature Friday. Per normal ordering1, these two promises will be emitted in the written order.

/tmp/feature-friday-7.cf
bundle agent feature_friday
{
  reports:
    "It's Friday, Friday";
    "Gotta get down on Friday";
}
command
cf-agent --no-lock --bundlesequence feature_friday --file /tmp/feature-friday-7.cf
output
R: It's Friday!
R: I love CFEngine Feature Friday.

If we want them in the opposite order, we could either change the order or define classes based on the results of the promises. But today’s feature, depends_on, lets us influence the ordering using a more lightweight method via handle.

/tmp/feature-friday-7-1.cf
bundle agent feature_friday
{
  reports:
    "It's Friday!"
      depends_on => { "first" };
    "I love CFEngine Feature Friday."
      handle => "first";
}
command
cf-agent --no-lock --bundlesequence feature_friday --file /tmp/feature-friday-7-1.cf
output
R: I love CFEngine Feature Friday.
R: It's Friday!

As you can see from the output above, we effectively switched the order of the promises.

The depends_on attribute requires that the promises with the named handles have been resolved as KEPT or REPAIRED before it’s allowed to actuate.

Happy Friday! 🎉