Well,

specifically for this example, the possibility to simplify is quite
straightforward:

> vars:
>     any::   'common'      slist => { 'foo', 'quux', 'fubar' };
>     alpha:: 'pkgs[alpha]' slist => { 'foo', 'bar', 'baz' };
>     beta::  'pkgs[beta]'  slist => { @{common}, 'yipyip' };
>     delta:: 'pkgs[delta]' slist => {  'yipyip' };

it is obvious here that "alpha" etc repeats twice per line, so you can
rewrite it as follows:

       alpha::  "pkgs" slist => { ... };

But I cannot guarantee that every single case can be solved that easy.

2010/12/18 Jesse Becker <becker...@mail.nih.gov>:
> Yeah, I found a post (from you, I think) from a few months back that
> said as much.  Any ideas for more elegant workarounds?
>
> As I said, I've got one, but it's ugly, and I'd like something a bit
> more elegant and concise.
>
> On Sat, Dec 18, 2010 at 02:45:20AM -0500, Seva Gluschenko wrote:
>>
>> Jesse,
>>
>> unfortunately, the Cfengine has limitations when evaluating variables,
>> so deep nesting should be avoided as far as possible. I'm not the
>> Cfengine developer to tell for sure whether you met the natural limit
>> of the evaluation depth, or is it just a bug, but this behaviour
>> remains pretty the same since 3.0.4.
>>
>> 2010/12/18 Jesse Becker <becker...@mail.nih.gov>:
>>>
>>> So, the snipped below does not work, but I wish that it did. ?It also
>>> isn't limited to package promises either, I can think of cases for file
>>> and command promises as well.
>>>
>>> At a high level, I am trying to define per-host lists, then iterate over
>>> those lists, but only on the appropriate host.
>>>
>>> <-----snip----->
>>>
>>> bundle agent testing {
>>>
>>> vars:
>>> ? ? any:: ? 'common' ? ? ?slist => { 'foo', 'quux', 'fubar' };
>>> ? ? alpha:: 'pkgs[alpha]' slist => { 'foo', 'bar', 'baz' };
>>> ? ? beta:: ?'pkgs[beta]' ?slist => { @{common}, 'yipyip' };
>>> ? ? delta:: 'pkgs[delta]' slist => { ?'yipyip' };
>>>
>>> packages:
>>>
>>> ? ? # only "NY" is needed, since the others are squished into this in
>>> ? ? # yum.cf
>>> ? ? centos.!NY::
>>> ? ? ? ? "${pkgs[${sys.uqhost}]}"
>>> ? ? ? ? ? ? handle ? ? ? ? => "per_host_packages_for_${sys.uqhost}",
>>> ? ? ? ? ? ? package_policy => 'add',
>>> ? ? ? ? ? ? package_method => yum,
>>> ? ? ? ? ? ? ifvarclass ? ? => isvariable("pkgs[${sys.uqhost}]"),
>>> ? ? ? ? ? ? package_architectures => { 'x86_64' };
>>> }
>>>
>>> <-----snip----->
>>>
>>>
>>> What happens is that "${pkgs[${sys.uqhost}]}" is evaluated once, with
>>> only "${sys.uqhost}" getting processed, leaving the string as a literal
>>> "${pkgs[alpha]}" ). ?This will, of course, fail when passed to the
>>> actual promise in question.
>>>
>>> I do have a workaround, but it's inelegant. ?Bascially, flatten the
>>> array into multiple slists, and have a separate promise for each one,
>>> based on the hostnames.
>>>
>>> So my question: ?Is there a concise way to do something like what I've
>>> posted above?
>>>
>>>
>>> --
>>> Jesse Becker
>>> NHGRI Linux support (Digicon Contractor)
>>> _______________________________________________
>>> Help-cfengine mailing list
>>> Help-cfengine@cfengine.org
>>> https://cfengine.org/mailman/listinfo/help-cfengine
>>>
>>
>>
>>
>> --
>> SY, Seva Gluschenko.
>
> --
> Jesse Becker
> NHGRI Linux support (Digicon Contractor)
>



-- 
SY, Seva Gluschenko.
_______________________________________________
Help-cfengine mailing list
Help-cfengine@cfengine.org
https://cfengine.org/mailman/listinfo/help-cfengine

Reply via email to