Hi,

Le 08/07/2011 15:05, no-re...@cfengine.com a écrit :
> Forum: CFEngine Help
> Subject: edit global list
> Author: schattenfell
> Link to topic: https://cfengine.com/forum/read.php?3,22770,22770#msg-22770
>
> Hello,
>
> by design it seems not to be possible, to edit global lists. E.g. I create a 
> list in a bundle (common or agent).
>
>
> bundle common v
> {
>    vars:
>       "my_module_list_global" slist  => { "loop" }, policy => "overridable";
> }
>
>
> Now I want to add literals to this global list in the "vars:" - section of 
> other bundles. But here only a local use is possible like:
>
>
> "my_module_list_local" slist => {
>                                    @(v.my_module_list_global),
>                                    "drbd"
>                                  },
>                                  policy => "overridable";
>
>
> So my intention ist the following: I have different bundles of type agent for 
> different services, that I want to configure.
> In every bundle I want to be able to collect information about needed kernel 
> modules.
> At the end a bundle agent called modules shall use this global list, to 
> create /etc/modules from it.
>
> I know I could e.g. define classes in the different service bundles and check 
> them in the module bundle, but then I always have to edit the module bundle, 
> if I want to add a new service bundle with the need of a specific kernel 
> module.
>
> Does anyone have an idea, how I can define a global var / list, that is 
> acessible from different bundles for writing?
> Or another way to deal with the mentionned problem?

I'm pretty sure that you can't edit lists in other bundles, so I see
your frustration.

I can see two approaches that I would use here, depending on whether you
need a list of modules to *set* (ie, the whole list, and you must delete
any other lines) or whether you need a list of modules to *add* (just
adding lines to /etc/modules).

Both cases would use a bundle agent that takes a parameter (the module
name), that you can call using a "methods" promise from each of your
service bundles, ie :

bundle agent add_module(module_name) {
  files:
     "/etc/modules"
            edit_line => add_lines("$(module_name)");
}

bundle agent my_service {
  # do real stuff
 
  methods:
      "any" usebundle => add_module("some module");
}

This would just add lines to /etc/modules, if they don't exist (2nd case
above).

If you want to *set* the contents of the file, I suggest using a
temporary file to build up the list (similar to your approach of
building up a slist). The bundle add_module above would be the same, but
using a temporary file. Then at the end of your bundlesequence, add a
bundle with a files promise to replace /etc/modules with that temporary
file.

Hope this helps,
Jonathan

-- 
==========================================
Jonathan CLARKE
CTO - Directeur technique
------------------------------------------
Normation
44 rue Cauchy, 94110 Arcueil, France
------------------------------------------
Telephone:  +33 (0)1 83 62 41 24
------------------------------------------
Web:        http://www.normation.com/
==========================================

_______________________________________________
Help-cfengine mailing list
Help-cfengine@cfengine.org
https://cfengine.org/mailman/listinfo/help-cfengine

Reply via email to