Dear Brendan,

  I tried out your code below,  expecting it to create

search example.com
nameserver 192.168.1.1
nameserver 192.168.1.2

but it only created:

search example.com
nameserver 192.168.1.1

I am using cfengine 3.0.2 community edition, and calling the code with
"cf-agent -f resolv.cf".

Does this work for you?  If so, what am I doing wrong?

Thanks,
-at


On Sun, Dec 13, 2009 at 1:53 PM, Brendan Strejcek <strej...@gmail.com> wrote:
> Currently there is no map() function, but you can get a similar result
> using iteration.
>
> body common control {
>    bundlesequence  => { 'example' };
> }
>
> bundle agent example {
> vars:
>    any::
>        'nameserver' slist => { '192.168.1.1', '192.168.1.2' };
>        'search' string => 'example.com';
>        'resolv' string => '/tmp/resolv.conf';
> files:
>    any::
>        "${resolv}"
>            create => 'true',
>            edit_line => AppendIfNoSuchLine("search ${search}");
>        "${resolv}"
>            edit_line => AppendIfNoSuchLine("nameserver ${nameserver}");
> }
>
> bundle edit_line AppendIfNoSuchLine(line) {
> classes:
>    'line_absent' not => regline("^${line}$","${edit.filename}");
> insert_lines:
>    line_absent::
>        "${line}";
> }
>
> On Mon, Nov 30, 2009 at 6:53 AM, Matthias Teege <matthias-...@mteege.de> 
> wrote:
>> Moin,
>>
>> I have a question about list substition. I want to create a resolv.conf
>> from variables.
>>
>> "dom" string => "example.com";
>> "dns" slist => { "192.168.1.1", "192.168.1.2" };
>>
>> It would be nice if i can use a generic add_line macro like this one:
>>
>> bundle edit_line add_line(value) {
>> insert_lines:
>>  "${value}";
>> }
>>
>> I can create a new list and use add_line:
>>
>> "resolv" slist => { "search $(dom)", @(dns) };
>>
>> "resolv.conf"
>>
>>  edit_line => add_line (@(resolv));
>>
>> But this does not give me a usefull resolv.conf because I missing
>> "nameserver". Something like
>>
>> "resolv" slist => { "search $(dom)", "nameserver $(dns)" };
>>
>> does not work.
>>
>> Is it possible to "simulate" some kind of map function or list
>> comprehension in cfe3? In python I can write:
>>
>> [ "nameserver %s" % h for h in ('192.168.1.1', '192.168.1.2') ]
>>
>> which gives me a new list.
>>
>> ['nameserver 192.168.1.1', 'nameserver 192.168.1.2']
>>
>> Is there something simular in cfe?
>>
>> Many thanks
>> Matthias
>>
>> _______________________________________________
>> Help-cfengine mailing list
>> Help-cfengine@cfengine.org
>> https://cfengine.org/mailman/listinfo/help-cfengine
>>
> _______________________________________________
> Help-cfengine mailing list
> Help-cfengine@cfengine.org
> https://cfengine.org/mailman/listinfo/help-cfengine
>
_______________________________________________
Help-cfengine mailing list
Help-cfengine@cfengine.org
https://cfengine.org/mailman/listinfo/help-cfengine

Reply via email to