How is define the maisl subject of cf_execd

7 views
Skip to first unread message

Jerome Jean Verleyen

unread,
Oct 21, 2025, 8:52:27 PMOct 21
to help-cfengine
Dear all
I've installed a cfengine on some server. Every change of state i'll received an email, thank's to postfix configured by.... cfenegine :-)

What i'v notice is that the subject of the email is of the following format:

[hostname / ip address]

Which IP address is using cf_execd? That's seems to be the first one present as a result of "ip a" command (excluding localhost, that's normal).

It is a way to define some proper subjet? The documentation about that is not very clear to me:

body executor control { mailsubject => "CFEngine report ($(sys.fqhost))"; }

Where should i write this code?

Thank's a lot!

Lars Erik Wik

unread,
Oct 22, 2025, 4:27:42 AMOct 22
to help-cfengine
Hi there,

I would recommend configuring it in augments (i.e., /var/cfengine/masterfiles/def.json). Something like:

```
{
  "vars": {
    "control_executor_mailsubject": "My value defined from augments"
    }
}
```


The variable could also be modified in /var/cfengine/masterfiles/controls/cf_execd.cf. But I would advice against modifying default policy, as it makes upgrades much harder.

Nick Anderson

unread,
Oct 22, 2025, 2:17:37 PMOct 22
to help-c...@googlegroups.com, jerome....@ibt.unam.mx

It is a way to define some proper subjet? The documentation about that is not very clear to me:

body executor control { mailsubject => "CFEngine report ($(sys.fqhost))"; }

Where should i write this code?

Hi Jerome,

TL;DR

Create a def.json at the root of your policy set and define default:def.control_executor_mailsubject.

https://docs.cfengine.com/docs/3.24/reference-masterfiles-policy-framework.html#configure-subject-for-emails-sent-by-cf-execd

{
  "variables": {
    "default:def.control_executor_mailsubject": {
        "value": "CFEngine output from $(sys.fqhost)"
    }
  }
}

The rest of the story:

When a cfengine agent runs, it is going to do some system discovery to understand the environment (basically sys vars and hard classes). Then it's going to process Augments (https://docs.cfengine.com/docs/3.24/reference-language-concepts-augments.html). First, $(sys.workdir)/data/host_specific.json if it exists, then $(sys.policy_entry_dirname)/def_preferred.json or $(sys.policy_entry_dirname)/def.json if they exist and then other supplemental augments as specified by the augments key.

Then it's going to start parsing policy starting with the first policy file read $(sys.policy_entry_filename) which defaults to promises.cf and other policy files are parsed as they are discovered based on the presence of the inputs defined (which may have been extended by Augments via the inputs key).

The setting you are talking about, for mailsubject lives in body executor control, you will find it within the policy framework in controls/cf_execd.cf

Looking at this file you will find it looks like this:

cfengine_internal_agent_email.!cfengine_internal_disable_agent_email::
  mailto       => "$(def.mailto)";
  mailfrom     => "$(def.mailfrom)";
  smtpserver   => "$(def.smtpserver)";
  mailmaxlines => "$(default:def.control_executor_mailmaxlines)";

control_executor_mailsubject_configured.cfengine_internal_agent_email.!cfengine_internal_disable_agent_email::
  mailsubject => "$(default:def.control_executor_mailsubject)";

control_executor_mailfilter_exclude_configured.cfengine_internal_agent_email.!cfengine_internal_disable_agent_email::
  mailfilter_exclude => { "@(default:def.control_executor_mailfilter_exclude)" };

control_executor_mailfilter_include_configured.cfengine_internal_agent_email.!cfengine_internal_disable_agent_email::
  mailfilter_include => { "@(default:def.control_executor_mailfilter_include)" };

Notice that mailsubject here has a value of $(default:def.control_executor_mailsubject). This tells us that the value is defined in the default namespace (see more about namespaces here https://docs.cfengine.com/docs/3.24/reference-language-concepts-namespaces.html), in the def bundle scope, in the variable control_executor_mailsubject.

We can leverage Augments to define that variable, as mentioned in the docs for configuring the subject for emails sent by cf-execd (https://docs.cfengine.com/docs/3.24/reference-masterfiles-policy-framework.html#configure-subject-for-emails-sent-by-cf-execd).

{
  "variables": {
    "default:def.control_executor_mailsubject": {
        "value": "CFEngine output from $(sys.fqhost)"
    }
  }
}
Reply all
Reply to author
Forward
0 new messages