root@cfe-hub:/var/cfengine/masterfiles# cat environment_none/env_promises.cf
bundle agent env_main
{
reports:
cfengine::
"Environment none: $(environments.active)";
}
root@cfe-hub:/var/cfengine/masterfiles# cat environment_production/env_promises.cf
bundle agent env_main
{
reports:
cfengine::
"Environment prod: $(environments.active)";
}
root@cfe-hub:/var/cfengine/masterfiles# cat env1.cf
bundle common environments
{
classes:
"environment_production" or => {
"cfe_hub",
};
vars:
any::
"active" string=>"none", policy=>"overridable";
environment_production::
"active" string=>"production", policy=>"overridable";
}
body common control
{
inputs=>{
"lib/3.7/stdlib.cf",
"environment_$(environments.active)/env_promises.cf",
};
bundlesequence=>{
"environments",
"env_main",
};
}
root@cfe-hub:/var/cfengine/masterfiles# cf-agent -KIf /var/cfengine/masterfiles/env1.cf
R: Environment prod: production
root@cfe-hub:/var/cfengine/masterfiles# cat /var/cfengine/masterfiles/env2.cf
bundle common environments
{
classes:
"environment_production" expression => classify("cfe-hub");
vars:
any::
"active" string=>"none", policy=>"overridable";
environment_production::
"active" string=>"production", policy=>"overridable";
}
body common control
{
inputs=>{
"lib/3.7/stdlib.cf",
"environment_$(environments.active)/env_promises.cf",
};
bundlesequence=>{
"environments",
"env_main",
};
}
root@cfe-hub:/var/cfengine/masterfiles# cf-agent -KIf /var/cfengine/masterfiles/env2.cf
R: Environment prod: production
root@cfe-hub:/var/cfengine/masterfiles# cat /var/cfengine/masterfiles/env3.cf
bundle common environments
{
vars:
any::
"prod_hosts" slist => {
"cfe-hub",
};
classes:
"environment_production" expression => classify("$(prod_hosts)");
vars:
any::
"active" string=>"none", policy=>"overridable";
environment_production::
"active" string=>"production", policy=>"overridable";
}
body common control
{
inputs=>{
"lib/3.7/stdlib.cf",
"environment_$(environments.active)/env_promises.cf",
};
bundlesequence=>{
"environments",
"env_main",
};
}
root@cfe-hub:/var/cfengine/masterfiles# cf-agent -KIf /var/cfengine/masterfiles/env3.cf
R: Environment none: production
root@cfe-hub:/var/cfengine/masterfiles# cf-agent -V
CFEngine Core 3.7.1
Try canonify instead of classify
classes:
"environment_production" or => {
classify("cfe-hub"),
classify("cfe-2nd"),
classify("cfe-3rd"),
};
vars:
any::
"host" string => "cfe-hub";
classes:
"environment_production" or => {
classify($(host)),
classify("cfe-2nd"),
classify("cfe-3rd"),
};
root@cfe-hub:/var/cfengine/masterfiles# cat /var/cfengine/masterfiles/hjcoel.cf
body common control
{
bundlesequence => { "main", "env_main"};
inputs=>{
"hjcoel_env_$(main.active).cf",
};
}
#bundle common main
bundle agent main
{
vars:
"myhosts" slist => { "one", "two", "three", "ettin", "cfe-hub" };
classes:
"prod_env" expression => classify( "${myhosts}" );
#"prod_env" or => { "one", "two", "three", "ettin", "cfe_hub" };
vars:
any::
"active" string=>"none", policy=>"overridable";
prod_env::
"active" string=>"production", policy=>"overridable";
reports:
prod_env::
"Bundle: $(this.bundle), I am in prod! Environment $(main.active)";
}
root@cfe-hub:/var/cfengine/masterfiles# cat /var/cfengine/masterfiles/hjcoel_env_none.cf
bundle agent env_main
{
reports:
"Bundle: $(this.bundle), Environment: $(main.active), File: $(this.promise_filename)";
}
root@cfe-hub:/var/cfengine/masterfiles# cf-agent -Kf /var/cfengine/masterfiles/hjcoel.cf
R: Bundle: main, I am in prod! Environment production
R: Bundle: env_main, Environment: production, File: /var/cfengine/masterfiles/hjcoel_env_none.cf
root@cfe-hub:/var/cfengine/masterfiles# cf-agent -Kf /var/cfengine/masterfiles/hjcoel.cf
R: Bundle: main, I am in prod! Environment production
R: Bundle: env_main, Environment: production, File: /var/cfengine/masterfiles/hjcoel_env_production.cf