File: mod_files.cf

package info (click to toggle)
cfengine3 3.0.5%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: squeeze
  • size: 10,452 kB
  • ctags: 6,615
  • sloc: ansic: 62,933; sh: 9,712; yacc: 347; makefile: 287; sql: 23
file content (243 lines) | stat: -rw-r--r-- 5,485 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
#  Copyright (C) Cfengine AS

#  This file is part of Cfengine 3 - written and maintained by Cfengine AS.

#  This program is free software; you can redistribute it and/or modify it
#  under the terms of the GNU General Public License as published by the
#  Free Software Foundation; version 3.

#  This program is distributed in the hope that it will be useful,
#  but WITHOUT ANY WARRANTY; without even the implied warranty of
#  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#  GNU General Public License for more details.

# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA

# To the extent this program is licensed as part of the Enterprise
# versions of Cfengine, the applicable Commerical Open Source License
# (COSL) may apply to this file if you as a licensee so wish it. See
# included file COSL.txt.

#########################################################
#
# files module
#
#########################################################

bundle agent filetest()
   {
   vars:

      "filelist" slist => { "/tmp/bla1", "/tmp/bla2" };

      "limit_size" int => "46m";

   files:

      "/path/file.*" -> "me"

            pathtype     => "regex",
            perms        => myperms,
            file_select  => myfilter,
            changes      => tripwire,
            depth_search => recurse("2");

    stupid_faculty::

      "$(filelist)"

              ref    => "Every promise may have an id or explanation to refer by",
           perms     => myperms ,
           perms     => others("fish"); # ("white");

      "/etc/xyz" -> "cfagent"     # create a file

            create    => "true",
            touch     => "true",
            perms    => myperms;

      "/etc/abc/." -> "cfagent"   # create a directory

            create    => "true",
            perms    => myperms;

      "/usr/local"    

            link_from     => linkdetails("/site/mountpoint/local");

      "/usr/local/dir_of_links"    

            link_from     => link_with_override("/site/mountpoint/local/sourcedir");


      "/var" 

            depth_search => recurse("inf"),
            delete       => tidypolicy,    # combined with file_select now
            rename       => rotateme,
            repository   => "/override";
   }

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

body depth_search recurse(d)

{
depth        => "$(d)";
include_dirs => { ".*.exe", ".*.com" };
}

#########################################################
#
# Editfiles in not yet specified
#

bundle edit_line myedit(filename)
  {
  classes:

  append:

      "My important line.*" 

           data        => "New important line" ,
           policy      => IfNoSuchLine,
           transaction => controlbody("my message");

  append:

     "This a line in $(filename)" ;
  
  replace:

   classes::

       "string.[abc]*" 

           with    => "$(new_value)" ,
           which   => all ,
           classes => afterX;  trigger ordering

  }

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

body perms others(parame)

{
milkyway::

owners  => { "root", "wheel", "sudo" };
}

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

body perms myperms()

{
any::

  mode  => "+077,-02";
  owners => { "mark","siri" };

solaris::

  #groups => { readstringlist("filename","#.*","[\n]","1000") };

linux::

  groups => { "root", "wheel" };
}

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

body linkfrom linkdetails(tofile)

{
source        => "$(tofile)";
link_type     => "symlink";
when_no_file  => "force";      # kill
}

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

body linkfrom link_with_override(tofile)

{
source        => "$(tofile)";
link_type     => "symlink";          # /absolute/abs/hard/relative/rel
when_no_file  => "force";             # kill
link_children => "true";
}

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

body transaction controlbody

{
log_level    => "error";
report_level => "inform";
ifelapsed   => "10";
expireafter => "20";
}

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

body changes tripwire

{
hash    => "md5";
update  => "yes";
}

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

body file_select myfilter

#
# we can build old "include", "exclude", and "ignore" from these
# as standard patterns
#

{
leaf_name => { ".*.asc" };                   # regex matching file name
path_name => { "/var/.*/mail", "/usr/.*/mail" };

search_mode      =>  "700";
#search_size      =>  irange("10000","10000000");
search_size      =>  irange("10000","$(filetest.limit_size)");

search_owners     =>  { "mark", "cell", "motd" };
search_groups     =>  { "ecg", "mark" };

ctime     => irange(on(2000,1,1,0,0,0),now);
mtime     => irange(ago(1,0,0,2,30,0),now);  
atime     => irange(on(1997,2,22,0,0,0),now);

exec_regex  => "/usr/bin/file $(this.file) (.*ascii.*)";
filetypes   => { "dir", "symlink" };
issymlinkto => { "/dev/null", "/dev/tyyS0"};
file_result => "type&mode"; 
}

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

body delete tidypolicy

{
dirlinks => "delete";          #keep/tidy/delete
rmdirs   => "true";             #none/all/sub
}

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

body rename rotateme

{
newname => "filename";
rotate => "4"; # 0 means empty file
}