On Mon, Apr 2, 2012 at 1:14 PM, Nick Anderson <n...@cmdln.org> wrote:
> On 04/02/2012 12:10 PM, Aleksey Tsalolikhin wrote:
>>     files:
>>
>>       "/tmp/etc/.*.conf"
>>
>>         edit_line => has_my_...
>
> I think because this is a "single promise".

Dear Nick,

Yes, it's a single promise, but remember, the promiser can affect
multiple objects.

For example, {{{ processes: "trn" signals => {"term"}; }}} will kill
multiple "trn" processes.
The promiser field, with PCRE, allows you to specify the pattern for
affected system objects.
Another example, {{{ delete_lines: ".*"; }}} will kill multiple lines.

If you look at the verbose output, it looks like the agent identified
the *.conf files correctly:

cf3>  -> Handling file existence constraints on /tmp/etc/warnquota.conf
...
cf3>  -> Handling file existence constraints on /tmp/etc/nscd.conf
...
cf3>  -> Handling file existence constraints on /tmp/etc/syslog.conf
...
cf3>  -> Handling file existence constraints on /tmp/etc/syslog.conf
...
cf3>  -> Handling file existence constraints on /tmp/etc/dhcp6c.conf
...
cf3>  -> Handling file existence constraints on /tmp/etc/ldap.conf
...

It looks like it was *trying* to handle multiple files but it didn't actually.
Only one file got edited.

> Begining with 3.3.0 you could probably use the lsdir function to get a
> list of files with .conf Then you could have an implitity looped promise.

I understand.  And Mike Svoboda, ack re using file_select, thank you! :)

Either lsdir or fileselect would swell my code; if I understand the language
correctly, I should be able to specify what files I want to handle in
the promiser
of the files type promise.  That's part of the promise of CFEngine 3 - increased
power (and brevity) through the use of industry-standard regular expressions.

Here is another example of trying to handle multiple files using PCRE and it
does not work:

[root@web01 verticalsysadmin_training_examples]# more
2440_Special_Variables._Edit.cf
# INPUT
# Put a few text files in /tmp (ending in .txt), and put
# the line "hello world" in one of them.
#
# Cfengine will report which file contains the line "hello world".
#

########################################################

bundle agent example

{
files:

  "/tmp/.*.txt"
      edit_line => grep_dash_l("hello world");
}

########################################################



bundle edit_line grep_dash_l(regex)
{
classes:

    "ok" expression => regline("$(regex)","$(edit.filename)");


reports:

 ok::

   "File $(edit.filename) has a line with \"$(regex)\" in it";

}
[root@web01 verticalsysadmin_training_examples]#
[root@web01 verticalsysadmin_training_examples]# touch /tmp/date.txt
[root@web01 verticalsysadmin_training_examples]# echo 'hello world' >
/tmp/file2.txt
[root@web01 verticalsysadmin_training_examples]# cf-agent -f
./2440_Special_Variables._Edit.cf  -b example -KI
 >> Using command line specified bundlesequence
[root@web01 verticalsysadmin_training_examples]# ls -l /tmp/*txt
-rw-r--r-- 1 root root  0 Apr  2 16:45 /tmp/date.txt
-rw-r--r-- 1 root root 12 Apr  2 16:45 /tmp/file2.txt
[root@web01 verticalsysadmin_training_examples]# grep -l 'hello world'
/tmp/*.txt
/tmp/file2.txt
[root@web01 verticalsysadmin_training_examples]# cf-agent -f
./2440_Special_Variables._Edit.cf  -b example -KI
 >> Using command line specified bundlesequence
[root@web01 verticalsysadmin_training_examples]#

I suspect I'm running into the same barrier.

I'm trying to identify if it is incomplete understanding on my part,
or a defect in the product.

Yours fondly,
-at
_______________________________________________
Help-cfengine mailing list
Help-cfengine@cfengine.org
https://cfengine.org/mailman/listinfo/help-cfengine

Reply via email to