Published on June 24, 2025
CFEngine is a powerful open-source automation tool for IT infrastructure configuration management. It is lightweight, scalable, agent-based, and focuses on system compliance, security, and drift correction.
/var/cfengine/inputs/.body common control for global config).classes:: blocks execute conditionally./var/cfengine/
├── inputs/ # Policy files (main config lives here)
├── outputs/ # Run-time outputs/logs
├── masterfiles/ # Canonical policy (symlinked in HA setups)
├── bin/ # CFEngine binaries (cf-agent, cf-serverd, etc.)
bundle agent hello_world
{
reports:
"Hello from CFEngine!";
}
Place this in /var/cfengine/inputs/hello.cf and run: sudo cf-agent -Kf ./hello.cf
bundle agent classify_host
{
classes:
"is_prod" expression => regcmp(".*prod.*", "$(sys.fqhost)");
reports:
is_prod::
"This host is a production server.";
!is_prod::
"This host is NOT a production server.";
}
body common control) set up defaults across the policy.The is_prod class example above shows how to classify a server as “production” if its FQDN contains “prod.”
#. #@ and @# can be used for special tagging but are not standard comments—mainly used for internal documentation or code generation tooling."tls_enabled" #security tagging is for human readability and does not affect code execution.sudo cf-agent --bootstrap <policy_server_ip>/var/cfengine/masterfiles).bundle sequence in body common control:body common control
{
bundlesequence => { "hello_world", "classify_host" };
}
is crucial.classes in body common control for global class definitions, but most class logic should go in bundles.bundle agent manage_ssh_config
{
files:
"/etc/ssh/sshd_config"
perms => mog("600", "root", "root"),
edit_line => replace_or_add("PermitRootLogin no");
}
This example: Ensures /etc/ssh/sshd_config permissions and disables root login.
cf-agent -KIf ./policyfile.cf before rolling out.cf-promises --show-classes to debug classes and policy syntax.Learning CFEngine has been a great experience for understanding foundational concepts in configuration management. If you want a highly efficient, scalable solution—and are willing to learn its unique policy language—CFEngine is a fantastic tool. I will keep updating this post as I dive deeper, especially around automation, best practices, and troubleshooting real-world scenarios.