CFEngine tip #001: Modularize complex policies using methods: calls

Welcome to the new "CFEngine tip" series. In this series of posts I will explore different tips, tricks and techniques for making better use of CFEngine. For now I will post weekly, but the frequency may change as time goes by. If you have any suggestions for topics that I should cover in this series, please let me know!

For our first installment, we will talk about methods: promises, and how they can be used to make policies both clearer and more extensible.

As your CFEngine policies grow in complexity, they become harder to read if all your promises are in a single bundle, or if you split them among bundles, to have all those bundles listed in the bundlesequence declaration.

Enter the methods: promise type. Promises of this type allow you to call other bundles in sequence, passing arbitrary parameters. For example, consider the following example (from Chapter 5 of "Learning CFEngine 3"):

{% gist 2471468 %}

The methods: section makes it very easy to see the sequence of actions that will take place: backup some files, configure sysctl, sshd, inittab and users in sequence. This helps both in clarity and in code reusability: each bundle can perform logically different functionality, and they could potentially be reused in different settings and with different parameters. The promiser string in a methods: promise is an arbitrary string. The CFEngine documentation uses "any", but you can also use it, as in this example, to indicate the purpose of the promise.

Furthermore, you can use CFEngine's implicit looping to create generic promises that will call as many other bundles as necessary. Consider this revised code:

{% gist 2471468 %}

Now the list of bundles to call (edit_sysctl, edit_sshd and edit_inittab) is being built on the fly from the contents of the files array, and used through implicit looping to call the bundles in the methods: promises. Note how you can even pass arguments to these calls. This makes it very easy to extend the functionality by simply adding new elements to the files array (and of course, defining the appropriate edit_* bundle).

Until next time!

New "reviews" page

I have started collecting some of the nice things I have read people say about the book, and put them in the Reviews page. Check it out!

My first batch of print books arrived

I'm visiting Purdue University today to give a talk and to visit old friends and colleagues. And the first box of books arrived here! It's incredible to have the physical book in my hand.


This is the building where I spent most of my grad school years.


The bird on the cover of "Learning CFEngine 3"

A lot of people have asked me about the bird on the cover of the book, and I had to admit I didn't know. Unfortunately, the book (even in the print version) does not include a description of the cover in the Colophon, like most other O'Reilly books. But today I got the information directly from Karen Montgomery at O'Reilly, who designed the cover:

The bird is a Tui, a kind of bird that leaves in New Zealand, also known as a Parson Bird. Here's a photo of a real Tui bird:

(photo by Matt Binns, reused under the Creative Commons Attribution 2.0 Generic license)

CFEngine-related speaking engagements from March 26th-28th, 2012

I will be giving three CFEngine related talks this week. I would love to see you at any one of them!

March 26th - Purdue University, Lawson CS Building 3102, West Lafayette, IN, 1:30PM

"CFEngine 3: Empowering the Next-Generation SysAdmin"

March 27thChicago Devops Meetup, Morningstar, Chicaco, IL, 5:30PM

"CFEngine 3: Empowering the Next-Generation SysAdmin"

March 28thCampIT conference on IT Infrastructure & Operations Management, Chicago, IL, 9:00AM

"Achieving IT Infrastructure and Operational Excellence"

Book status: released!


I am ecstatic to announce that the book is now officially released! You can get it here: If you purchased the Early Release version, you should automatically be able to download the final version from your "Your products" page at

It's been an incredible ride, and it's an incredible feeling to see it come to this big milestone (I won't say "the end", because I know this book will keep evolving).

There have been so many people who helped me through this process, including my editor (Andy Oram), all the staff at O'Reilly, who have been so professional and helpful, my very competent tech reviewers (Mark Burgess and Jesse Becker), all my colleagues at CFEngine AS, all the readers of intermediate and partial versions of the book, all the people who purchased the Early Release, and of course, my lovely wife and my two beautiful daughters, who were so patient while I worked on "the book". Everyone gave me encouragement, incredible feedback, and tons of guidance and support. Thank you everyone!

Book status: print-ready

I am very happy! I got the notification today that the final book draft has been produced and sent to the printer. This means that over the next few days the final version will be available for purchase, both as e-book and in print form. I will of course let you know when this happens.

For now, time to enjoy a relaxing weekend, the first with no book-related work in a long time :)

Syntax highlighting in "Learning CFEngine 3"

The electronic versions of the book contain full syntax highlighting and other useful features. I'm biased of course, but I think it is both functional and beautiful. Here's a sample from Chapter 4:


The syntax highlighting in my opinion greatly helps in reading the code. Additionally, each one of those numbered callouts in the code are in-document links that take you to the paragraph where that part of the code is described. Conversely, the callouts in the text take you back to the corresponding line in the code. And finally, most CFEngine keywords and concepts are links to the corresponding description in the CFEngine Reference Manual. In the PDF, clicking on that blue "files:" in the last paragraph will take you to

CFEngine community event: March 8th, 2012

I am visiting the Bay Area this week, and we took the opportunity to organize a CFEngine community event on Thursday, March 8th, at 6:30 PM. Come by, meet the CFEngine team, hear about some of the exciting things we are working on, and give us your feedback for the future.

Hope to see you there! If you plan to attend please don't forget to register.

Book status: production

Some people have asked me what the status of the book is, so I thought I would post it here. The book is currently in the "production stage", which means that the draft has been finalized content-wise, and is now being prepared for publication by O'Reilly. They have a specialized group of people for this, who work on preparing nice final versions of the figures, making sure the layout of the book is correct, and doing a few thorough proofreading and editing passes.

This means that it's now really close to publication. I cannot make any promises about the specific date, but it should be before the end of March.

Thank you for your interest!