Forum: Cfengine Help
Subject: Getting a long list of files into Cfengine
Author: sauer
Link to topic: https://cfengine.com/forum/read.php?3,21000,21000#msg-21000
I'm trying to set up a promise that will ensure the first line of every perl
file under a directory (there's about 3,000 of them) is the correct path to
perl / has the right arguments passed. Obviously, this isn't a really
lightweight task, but it's not terrible, and it's not like I plan to check it
every 5 minutes.
However, I'm having a hard time getting all of the files in. I can't
recursively edit files, because Cfengine has unfortunately decided not to allow
edit rules with recursion, and doesn't provide a "yes, I really know what I'm
doing" option to override that. I can live with that decision, but that means
I need to generate a list somehow.
I refuse to hard-code the list of files because that's evil. And the string is
way too big for this to work:
"exec_list" slist => splitstring(
execresult( "$(find_path) $(find_arg)",
"noshell"
),
"$(const.n)",
"99999999999" #why does "0" not work here?
);
even if I yank the prefix off and just list the relative filenames.
So, my first thought was to use the module protocol to generate an array. But
the array-making syntax isn't apparently available in the version I have
(3.0.5), and due to the complexities of my environment, I won't be able to get
a new version deployed across the enterprise until roughly December. But I
will eventally upgrade, so I wonder whether or not the module protocol suffers
the same limits as execresult in terms of working with long strings. If I can
return a really long @files={ 'one' 'two', ... } string from a module, will
Cfengine be ok with it? Or is there a limitation on the maximum line or
overall output length from a module, too?
In either case, to address my current issue before December-ish, I need to make
this list. And it looks like I need to build the list incrementally. I do
have a promise:
"$(server_root)"
perms => mog("u+rw,g+r,g-w,o-rwx", "$(user)", "$(group)"),
file_select => by_name( @(executables) ),
depth_search => recurse("inf");
which is, one by one, hitting each of these files and setting the permissions.
Is there something I can add to that promise along the lines of
set_variable => filelist = slist { @(filelist) $(current_filename) }
which will let me build the array of files for doing the edits upon later? I
can't just define classes for each file, because the canonicalization of the
names will make it impossible to go back to the actual filename (ie: was
bin_file_pl originally /bin_file.pl or /bin/file.pl?) That would be ideal from
a performance POV, since I wouldn't have to traverse the directory again (on
top of doing the edits). I can't figure out a good way to do this with single
variables from the module protocol, either, since I don't see anything in the
docs about variable varables / pointers / whatever which would allow me to
iterate over an unknown set of similarly-named variables. If there was a
structure where I could just say "do this on every $(modulename.file_*)
variable", that might work.
I really want to do as much of this internal to Cfengine as possible.
Suggestions are welcome.
_______________________________________________
Help-cfengine mailing list
[email protected]
https://cfengine.org/mailman/listinfo/help-cfengine