And I should have pointed out that the "bundle resolvconf" etc, belongs in the standard library.
Mark Burgess wrote: > Try something like this... > > CF2 > --------------------------------------------------------------------------- > > resolve: > > "search iu.hio.no cfengine.com" > 128.39.89.10 > 158.36.85.10 > 129.241.1.99 > > > CF3 > --------------------------------------------------------------------------- > > vars: > > "resolvers" slist => { "128.39.89.10", "158.36.85.10", "129.241.1.99" }; > > files: > > "$(sys.resolv)" > > edit_line => resolvconf("iu.hio.no cfengine.com",@(resolvers)); > > bundle resolvconf(search,list) > { > delete_lines: > > "search.*"; > > insert_lines: > > "search $(search)"; > "$(list)"; > } > > > Aleksey Tsalolikhin wrote: >> Well, alright. It's not making sense yet. >> >> I am working my way through the tutorial now >> (http://www.cfengine.org/manuals/cf3-tutorial.pdf). Perhaps I'll find >> a working example of iteration there. >> >> It's good you'll have something to make this clearer. I reckon it'll >> help a lot. >> >> Aleksey >> >> On Tue, Dec 15, 2009 at 12:25 AM, Mark Burgess <mark.burg...@iu.hio.no> >> wrote: >>> In the approach given, the file is edited twice - once to add each line. >>> You have to think "sub-routines". Editing is a bundle of promises itself. >>> >>> My Christmas bundle will help to make this clearer. >>> >>> Aleksey Tsalolikhin wrote: >>>> 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 >>> -- >>> Mark Burgess >>> >>> ------------------------------------------------- >>> Professor of Network and System Administration >>> Oslo University College, Norway >>> >>> Personal Web: http://www.iu.hio.no/~mark >>> Office Telf : +47 22453272 >>> ------------------------------------------------- >>> >> _______________________________________________ >> Help-cfengine mailing list >> Help-cfengine@cfengine.org >> https://cfengine.org/mailman/listinfo/help-cfengine > -- Mark Burgess ------------------------------------------------- Professor of Network and System Administration Oslo University College, Norway Personal Web: http://www.iu.hio.no/~mark Office Telf : +47 22453272 ------------------------------------------------- _______________________________________________ Help-cfengine mailing list Help-cfengine@cfengine.org https://cfengine.org/mailman/listinfo/help-cfengine