Setting up multiple cfengine environments

20 views
Skip to first unread message

Ram K

unread,
Aug 27, 2015, 1:51:11 PM8/27/15
to help-cfengine, vk...@ntrs.com, rkri...@yahoo.com
Hello,
I am trying to setup multiple cfengine environments similar to the one in Diego Zamboni's book. In the example in the book, the class 'environment_development' is set based on the ip addresses. In my case, it is supposed to be set based on a module.

Prior to calling the environments bundle, I call the 'hostinfo' bundle (~/masterfiles/hostinfo.cf) which calls the 'hostinfo' module (~/modules/hostinfo). This module reads a file on the server and sets one of the classes: (tierLab|tierSys|tierUat, etc.) based on the information in the file. 

In the environments bundle, if the class 'tierSys' is set, then, it is supposed to set the 'env' variable to 'dev' and in the promises.cf file, the path of the inputs file is supposed to be: dev/env_promises.cf

When I run 'cf-agent -KI ~/masterfiles/promises.cf', I get the following error. 
2015-08-27T09:29:45-0500    error: Unresolved variable '$(environments.env)/env_promises.cf' in input list, cannot parse


But looking further down in the output, I can see that the 'hostinfo' module is executing and that the 'env' variable is set to 'dev'. So, I don't understand why I am getting the error message. Can someone help. Thanks

2015-08-27T10:26:50-0500     info: /default/hostinfo/commands/'/var/cfengine/modules/hostinfo'[0]: Executing 'no timeout' ... '/var/cfengine/modules/hostinfo'
2015-08-27T10:26:50-0500     info: /default/hostinfo/commands/'/var/cfengine/modules/hostinfo'[0]: Completed execution of '/var/cfengine/modules/hostinfo'
R: bundle: environments; env is: dev


The following is the code:
-----------
body common control
{
      bundlesequence => {
<snip>
                          service_catalogue,
                          @(cfengine_enterprise_hub_ha.management_bundles),

                          hostinfo,     # ntrs hostinfo module

                          environments, # ntrs cfengine environments
<snip>
      inputs => {
<snip>
                # List of services here
                  "services/file_change.cf",

                # ntrs hostinfo at: ~/masterfiles/
                  "hostinfo.cf",
                  "environments.cf",    # ntrs; defining cfengine environments

                 "$(environments.env)/env_promises.cf",
<snip>
}


bundle hostinfo
--------------
bundle agent hostinfo
{
   commands:
        # Renaming the cf2 module filename: 'module:hostinfo' to 'hostinfo'
        #"$(sys.workdir)/modules/hostinfo"        # /var/cfengine/modules/hostinfo
        "/var/cfengine/modules/hostinfo"        # /var/cfengine/modules/hostinfo
        module => "true";
}


module: hostinfo (~/modules/hostinfo):
--------------------------
<snip>
echo "+tierSys"


I tried running environments bundle as 'bundle common environments' as well. But, no luck. Here, it is 'bundle agent'
But, if I change the class 'tierSys::' to 'linux::', the 'env' variable is set.
bundle environments (~/masterfiles/environments.cf)
----------------------
bundle agent environments
{
   vars:
        tierSys::
                "env" string => "dev";

   reports:
        any::
                "bundle: $(this.bundle); env is: $(environments.env) ";
}


Neil Watson

unread,
Aug 27, 2015, 2:21:48 PM8/27/15
to help-cfengine

Bas van der Vlies

unread,
Aug 28, 2015, 12:25:14 PM8/28/15
to Ram, help-cfengine
Your welcome.

--
Bas van der Vlies


> On 28 aug. 2015, at 17:09, Ram <r.k...@gmail.com> wrote:
>
> Thank you very much. I changed my bundle type to common and used usemodule to call the module and that fixed it.
>
> Ram
>
> Sent from my iPhone
>
>> On Aug 28, 2015, at 4:06 AM, Bas van der Vlies <bas.van...@surfsara.nl> wrote:
>>
>> I also have a mixed environments that i control via module file. From the past i know that the evolution of the code was too late. I moved everything to:
>> {{{
>> bundle common g
>> ## Use realpath instead of variable name else the classes are activated to late
>> #
>> classes:
>> !(GOT_INIT|windows)::
>> "GOT_INIT" expression => usemodule("init_node","/etc/node_status/cluster”);
>> }}}
>>
>> regards
>>> --
>>> You received this message because you are subscribed to the Google Groups "help-cfengine" group.
>>> To unsubscribe from this group and stop receiving emails from it, send an email to help-cfengin...@googlegroups.com.
>>> To post to this group, send email to help-c...@googlegroups.com.
>>> Visit this group at http://groups.google.com/group/help-cfengine.
>>> For more options, visit https://groups.google.com/d/optout.
>>
>> ---
>> Bas van der Vlies
>> | Operations, Support & Development | SURFsara | Science Park 140 | 1098 XG Amsterdam
>> | T +31 (0) 20 800 1300 | bas.van...@surfsara.nl | www.surfsara.nl |
>>
>>
>>
Reply all
Reply to author
Forward
0 new messages