Sorted insert_lines and loop expension

15 views
Skip to first unread message

Jimmy Thrasibule

unread,
Jul 9, 2014, 5:06:23 PM7/9/14
to help-c...@googlegroups.com
Hi,

I was coming with this promises set:


body common control
{
bundlesequence => { "test" };
}

bundle agent test
{
vars:
"values"
slist => {
"a",
"b",
"c",
};

files:
"/tmp/cf-insert-test.txt"
create => "true",
edit_defaults => empty,
edit_line => insert_lines("$(values)");

reports:
cfengine_3::
"$(values)";
}


body edit_defaults empty
{
empty_file_before_editing => "true";
edit_backup => "false";
}

bundle edit_line insert_lines(v)
{
insert_lines:
"$(v)";
}


With the question "am I assured that my inserted lines will always be
inserted as defined in the slist"?

In fact I'm looking for the right structure to insert lines into a
file in an ordered manner.

However, when I run the promises above, the result is not what I was expecting:


$ cf-agent -K
R: a
R: b
R: c
$ cat /tmp/cf-insert-test.txt
c


As you can see, only the last value can be found in the file. Is this
normal behavior? What is the correct way to insert a slist into a
file.


Thanks for your help,
Jimmy

Neil Watson

unread,
Jul 10, 2014, 7:40:48 AM7/10/14
to help-c...@googlegroups.com
Pass the entire list to the edit_line bundle rather than iteration at
the files promise level.

insert_lines( "@{test.values}" );


--
Neil H Watson
Compliance reporting with CFEngine Community http://evolvethinking.com/products/delta-reporting/
Simplify CFEngine with EFL http://evolvethinking.com/evolve-thinkings-free-cfengine-library/
VIM and Cfengine https://github.com/neilhwatson/vim_cf3
CFEngine support and training from Evolve Thinking, http://evolvethinking.com

Jimmy Thrasibule

unread,
Jul 10, 2014, 8:25:27 AM7/10/14
to Neil Watson, help-c...@googlegroups.com
Hi Neil,

> Pass the entire list to the edit_line bundle rather than iteration at
> the files promise level.
>
> insert_lines( "@{test.values}" );

Thanks, this is working (I was forgetting the bundle name), but what
about the order? Can I be sure that lines will inserted in the same
order they are defined in my policy? If not, how can I achieve this?

Jimmy

Neil Watson

unread,
Jul 10, 2014, 8:33:23 AM7/10/14
to help-c...@googlegroups.com
On Thu, Jul 10, 2014 at 02:25:25PM +0200, Jimmy Thrasibule wrote:
>Thanks, this is working (I was forgetting the bundle name), but what
>about the order? Can I be sure that lines will inserted in the same
>order they are defined in my policy? If not, how can I achieve this?

Lists are are always ordered, and should come out correctly in your
edit.
Reply all
Reply to author
Forward
0 new messages