Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions libenv/sysinfo.c
Original file line number Diff line number Diff line change
Expand Up @@ -4059,9 +4059,18 @@ static void SysPolicyVersion(EvalContext *ctx)
}
}

static void SysCFEngineRole(EvalContext *ctx)
{
const bool is_policy_server = EvalContextClassGet(ctx, "default", "policy_server");
const bool am_policy_hub = EvalContextClassGet(ctx, "default", "am_policy_hub");

const char *role = (is_policy_server || am_policy_hub) ? "hub" : "client";
Comment thread
victormlg marked this conversation as resolved.
EvalContextVariablePutSpecial(ctx, SPECIAL_SCOPE_SYS, "cfengine_role", role, CF_DATA_TYPE_STRING, "source=agent,derived-from=policy_server,derived-from=am_policy_hub");
}

void DetectEnvironmentFromPolicy(EvalContext *ctx, Policy *policy)
{
SysPolicyReleaseId(ctx, policy);
SysPolicyVersion(ctx);
SysCFEngineRole(ctx);
}
23 changes: 23 additions & 0 deletions tests/acceptance/01_vars/01_basic/cfengine_role.cf
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
body common control
{
bundlesequence => { "check" };
}

bundle agent check
{
vars:
"role" string => ifelse("policy_server|am_policy_hub", "hub", "client");

classes:
"ok" expression => strcmp("$(sys.cfengine_role)", "$(role)");

reports:
DEBUG::
"sys.cfengine_role resolved to '$(sys.cfengine_role)', role resolved to '$(role)'";

ok::
"$(this.promise_filename) Pass";

!ok::
"$(this.promise_filename) FAIL";
}
Loading