Forum: Cfengine Help
Subject: File_select help
Author: neilhwatson
Link to topic: https://cfengine.com/forum/read.php?3,22617,22617#msg-22617

Greetings,

Given a fairly complex dir tree I'm trying to promise two things.  One, any 
file under dirs bin or libexe, and there might be multiple such dirs in the 
tree at any depth, make mode 750.  Two, any file not in those dirs make mode 
640.
I tried this:

bundle agent recipe {

vars:

   "exes" slist => { "/bin/" };

files:

   "/tmp/nwatson"
      handle => "exe_dirs",
      depth_search => recurse("inf"),
      action => warn_only,
      file_select => in_path( @(execs) ),
      perms => mog("0750", "root", "root");

   "/tmp/nwatson"
      handle => "non_exe_dirs",
      depth_search => recurse("inf"),
      action => warn_only,
      file_select => ex_path( "@(execs)" ),
      perms => mog("0640", "root", "root");

}

body file_select in_path (dirs) {
   leaf_name => { ".*" };
   path_name => { @(dirs) };
   file_result => "path_name.leaf_name";
}

body file_select ex_path (dirs) {
   leaf_name => { ".*" };
   path_name => { @(dirs) };
   file_result => "!path_name.leaf_name";
}


That results in

nova>     .........................................................
nova>     Promise handle: exe_dirs
nova>     Promise made by: /tmp/nwatson
nova>     .........................................................
nova>
nova>  -> Using literal pathtype for /tmp/nwatson
nova>  ->>  Entering /tmp/nwatson/com (0)
nova>  ->>  Entering /tmp/nwatson/com/man (1)
nova>  ->>  Entering /tmp/nwatson/com/bin (1)
nova>
nova>     .........................................................
nova>     Promise handle: non_exe_dirs
nova>     Promise made by: /tmp/nwatson
nova>     .........................................................
nova>
nova>  -> Using literal pathtype for /tmp/nwatson
nova>  -> Handling file existence constraints on /tmp/nwatson
nova>  -> Promise to skip base directory /tmp/nwatson
nova>  ->>  Entering /tmp/nwatson/com (0)
nova>  ->>  Entering /tmp/nwatson/com/man (1)
nova>  -> Handling file existence constraints on /tmp/nwatson/com/man/page.5
nova>  !! /tmp/nwatson/com/man/page.5 has permission 644 - 
nova> I: Report relates to a promise with handle "non_exe_dirs"
nova> I: Made in version 'not specified' of './promises.cf' near line 29
nova>  -> Handling file existence constraints on /tmp/nwatson/com/man
nova>  !! /tmp/nwatson/com/man has permission 755 - 
nova> I: Report relates to a promise with handle "non_exe_dirs"
nova> I: Made in version 'not specified' of './promises.cf' near line 29
nova>  ->>  Entering /tmp/nwatson/com/bin (1)
nova>  -> Handling file existence constraints on /tmp/nwatson/com/bin/foo.sh
nova>  !! /tmp/nwatson/com/bin/foo.sh has permission 644 - 

#### foo.sh should be set to 750 (in the previous promise which actually did 
nothing) not 640.

nova> I: Report relates to a promise with handle "non_exe_dirs"
nova> I: Made in version 'not specified' of './promises.cf' near line 29
nova>  -> Handling file existence constraints on /tmp/nwatson/com/bin
nova>  !! /tmp/nwatson/com/bin has permission 755 - 
nova> I: Report relates to a promise with handle "non_exe_dirs"
nova> I: Made in version 'not specified' of './promises.cf' near line 29
nova>  -> Handling file existence constraints on /tmp/nwatson/com
nova>  !! /tmp/nwatson/com has permission 755 - 
nova> I: Report relates to a promise with handle "non_exe_dirs"
nova> I: Made in version 'not specified' of './promises.cf' near line 29


_______________________________________________
Help-cfengine mailing list
Help-cfengine@cfengine.org
https://cfengine.org/mailman/listinfo/help-cfengine

Reply via email to