puppet 0.13.6 → 0.16.0
Sign up to get free protection for your applications and to get access to all the features.
Potentially problematic release.
This version of puppet might be problematic. Click here for more details.
- data/CHANGELOG +57 -0
- data/Rakefile +38 -410
- data/bin/puppet +14 -12
- data/bin/puppetca +1 -3
- data/bin/puppetd +25 -7
- data/bin/puppetdoc +161 -104
- data/bin/puppetmasterd +4 -4
- data/conf/epm.list +8 -0
- data/conf/redhat/client.init +6 -1
- data/conf/redhat/no-chuser-0.15.1.patch +38 -0
- data/conf/redhat/puppet.spec +20 -5
- data/conf/redhat/puppetd.conf +1 -1
- data/conf/redhat/puppetmasterd.conf +1 -1
- data/conf/redhat/server.init +2 -4
- data/examples/code/snippets/{casestatement → casestatement.pp} +12 -1
- data/examples/code/snippets/selectorvalues.pp +15 -0
- data/examples/code/snippets/singleselector.pp +22 -0
- data/examples/code/snippets/tag.pp +9 -0
- data/ext/module_puppet +1 -1
- data/install.rb +303 -303
- data/lib/puppet.rb +7 -9
- data/lib/puppet/client.rb +18 -5
- data/lib/puppet/client/dipper.rb +12 -10
- data/lib/puppet/client/master.rb +113 -41
- data/lib/puppet/client/pelement.rb +20 -0
- data/lib/puppet/config.rb +113 -6
- data/lib/puppet/element.rb +1 -3
- data/lib/puppet/event.rb +12 -23
- data/lib/puppet/filetype.rb +93 -5
- data/lib/puppet/inifile.rb +201 -0
- data/lib/puppet/log.rb +18 -6
- data/lib/puppet/parameter.rb +80 -29
- data/lib/puppet/parser/ast.rb +6 -4
- data/lib/puppet/parser/ast/caseopt.rb +13 -4
- data/lib/puppet/parser/ast/casestatement.rb +2 -2
- data/lib/puppet/parser/ast/component.rb +4 -14
- data/lib/puppet/parser/ast/hostclass.rb +1 -1
- data/lib/puppet/parser/ast/leaf.rb +12 -0
- data/lib/puppet/parser/ast/node.rb +4 -4
- data/lib/puppet/parser/ast/objectdef.rb +5 -51
- data/lib/puppet/parser/ast/selector.rb +2 -0
- data/lib/puppet/parser/ast/tag.rb +26 -0
- data/lib/puppet/parser/interpreter.rb +89 -74
- data/lib/puppet/parser/lexer.rb +4 -3
- data/lib/puppet/parser/parser.rb +440 -378
- data/lib/puppet/parser/scope.rb +844 -887
- data/lib/puppet/server.rb +12 -1
- data/lib/puppet/server/authconfig.rb +166 -0
- data/lib/puppet/server/authstore.rb +8 -6
- data/lib/puppet/server/ca.rb +23 -26
- data/lib/puppet/server/filebucket.rb +24 -23
- data/lib/puppet/server/fileserver.rb +116 -47
- data/lib/puppet/server/master.rb +58 -19
- data/lib/puppet/server/pelement.rb +176 -0
- data/lib/puppet/server/rights.rb +78 -0
- data/lib/puppet/server/servlet.rb +19 -6
- data/lib/puppet/sslcertificates.rb +4 -2
- data/lib/puppet/sslcertificates/ca.rb +66 -34
- data/lib/puppet/storage.rb +20 -26
- data/lib/puppet/transaction.rb +49 -92
- data/lib/puppet/type.rb +142 -35
- data/lib/puppet/type/cron.rb +29 -14
- data/lib/puppet/type/exec.rb +92 -35
- data/lib/puppet/type/group.rb +29 -11
- data/lib/puppet/type/nameservice.rb +50 -1
- data/lib/puppet/type/nameservice/netinfo.rb +68 -1
- data/lib/puppet/type/nameservice/objectadd.rb +1 -0
- data/lib/puppet/type/package.rb +150 -109
- data/lib/puppet/type/package/apple.rb +27 -0
- data/lib/puppet/type/package/apt.rb +1 -0
- data/lib/puppet/type/package/darwinport.rb +97 -0
- data/lib/puppet/type/package/dpkg.rb +10 -2
- data/lib/puppet/type/package/freebsd.rb +19 -0
- data/lib/puppet/type/package/{bsd.rb → openbsd.rb} +36 -7
- data/lib/puppet/type/package/ports.rb +98 -0
- data/lib/puppet/type/package/rpm.rb +43 -7
- data/lib/puppet/type/package/sun.rb +53 -36
- data/lib/puppet/type/package/yum.rb +5 -16
- data/lib/puppet/type/parsedtype.rb +41 -29
- data/lib/puppet/type/parsedtype/host.rb +13 -5
- data/lib/puppet/type/parsedtype/mount.rb +250 -0
- data/lib/puppet/type/parsedtype/port.rb +8 -6
- data/lib/puppet/type/pfile.rb +284 -30
- data/lib/puppet/type/pfile/checksum.rb +96 -68
- data/lib/puppet/type/pfile/content.rb +16 -13
- data/lib/puppet/type/pfile/ensure.rb +64 -126
- data/lib/puppet/type/pfile/group.rb +12 -5
- data/lib/puppet/type/pfile/mode.rb +16 -4
- data/lib/puppet/type/pfile/source.rb +47 -73
- data/lib/puppet/type/pfile/target.rb +81 -0
- data/lib/puppet/type/pfile/uid.rb +10 -3
- data/lib/puppet/type/pfilebucket.rb +12 -3
- data/lib/puppet/type/schedule.rb +5 -1
- data/lib/puppet/type/service.rb +138 -66
- data/lib/puppet/type/service/debian.rb +9 -3
- data/lib/puppet/type/service/init.rb +51 -56
- data/lib/puppet/type/service/smf.rb +16 -6
- data/lib/puppet/type/state.rb +71 -32
- data/lib/puppet/type/symlink.rb +12 -7
- data/lib/puppet/type/tidy.rb +5 -1
- data/lib/puppet/type/user.rb +116 -20
- data/lib/puppet/type/yumrepo.rb +314 -0
- data/lib/puppet/util.rb +84 -14
- data/test/client/client.rb +41 -18
- data/test/client/master.rb +50 -4
- data/test/executables/puppetbin.rb +31 -4
- data/test/executables/puppetca.rb +18 -2
- data/test/language/ast.rb +201 -31
- data/test/language/interpreter.rb +8 -2
- data/test/{parser → language}/lexer.rb +1 -1
- data/test/language/node.rb +84 -0
- data/test/{parser → language}/parser.rb +1 -1
- data/test/language/scope.rb +101 -2
- data/test/language/snippets.rb +23 -2
- data/test/other/config.rb +99 -1
- data/test/other/filetype.rb +95 -0
- data/test/other/inifile.rb +114 -0
- data/test/other/log.rb +3 -2
- data/test/other/transactions.rb +55 -10
- data/test/puppet/utiltest.rb +25 -1
- data/test/puppettest.rb +140 -46
- data/test/server/authconfig.rb +56 -0
- data/test/server/bucket.rb +32 -18
- data/test/server/fileserver.rb +75 -30
- data/test/server/master.rb +27 -4
- data/test/server/pelement.rb +298 -0
- data/test/server/rights.rb +41 -0
- data/test/server/server.rb +2 -2
- data/test/tagging/tagging.rb +100 -1
- data/test/types/basic.rb +3 -3
- data/test/types/cron.rb +24 -1
- data/test/types/exec.rb +99 -1
- data/test/types/file.rb +298 -2
- data/test/types/filebucket.rb +4 -15
- data/test/types/filesources.rb +43 -14
- data/test/types/group.rb +1 -13
- data/test/types/mount.rb +277 -0
- data/test/types/package.rb +164 -33
- data/test/types/parameter.rb +107 -0
- data/test/types/port.rb +2 -1
- data/test/types/service.rb +37 -2
- data/test/types/state.rb +92 -0
- data/test/types/symlink.rb +30 -2
- data/test/types/tidy.rb +2 -14
- data/test/types/type.rb +35 -1
- data/test/types/user.rb +110 -1
- data/test/types/yumrepo.rb +95 -0
- metadata +316 -290
- data/test/types/filetype.rb +0 -160
@@ -131,13 +131,14 @@ module Puppet
|
|
131
131
|
|
132
132
|
# Parse a services file
|
133
133
|
#
|
134
|
-
# This method also stores existing comments, and it stores all
|
135
|
-
#
|
136
|
-
# they were written and in proximity to the same
|
134
|
+
# This method also stores existing comments, and it stores all port
|
135
|
+
# info in order, mostly so that comments are retained in the order
|
136
|
+
# they were written and in proximity to the same ports.
|
137
137
|
def self.parse(text)
|
138
138
|
count = 0
|
139
139
|
hash = {}
|
140
140
|
text.chomp.split("\n").each { |line|
|
141
|
+
hash.clear
|
141
142
|
case line
|
142
143
|
when /^#/, /^\s*$/:
|
143
144
|
# add comments and blank lines to the list as they are
|
@@ -185,7 +186,6 @@ module Puppet
|
|
185
186
|
|
186
187
|
hash2obj(hash)
|
187
188
|
|
188
|
-
hash.clear
|
189
189
|
count += 1
|
190
190
|
end
|
191
191
|
}
|
@@ -206,6 +206,9 @@ module Puppet
|
|
206
206
|
return false
|
207
207
|
end
|
208
208
|
|
209
|
+
# If this is happening, our object exists
|
210
|
+
self.is = [:ensure, :present]
|
211
|
+
|
209
212
|
if hash[:protocols]
|
210
213
|
# The protocol can be a symbol, so...
|
211
214
|
if proto.is_a?(Symbol)
|
@@ -220,7 +223,6 @@ module Puppet
|
|
220
223
|
end
|
221
224
|
|
222
225
|
if hash.include?(:description) and ! @states.include?(:description)
|
223
|
-
Puppet.info "Adding description to %s" % hash[:name]
|
224
226
|
self.is = [:description, hash[:description]]
|
225
227
|
end
|
226
228
|
|
@@ -250,4 +252,4 @@ module Puppet
|
|
250
252
|
end
|
251
253
|
end
|
252
254
|
|
253
|
-
# $Id: port.rb
|
255
|
+
# $Id: port.rb 1129 2006-04-21 19:14:59Z luke $
|
data/lib/puppet/type/pfile.rb
CHANGED
@@ -34,34 +34,60 @@ module Puppet
|
|
34
34
|
desc "Whether files should be backed up before
|
35
35
|
being replaced. If a filebucket_ is specified, files will be
|
36
36
|
backed up there; else, they will be backed up in the same directory
|
37
|
-
with a ``.puppet-bak`` extension.
|
37
|
+
with a ``.puppet-bak`` extension.
|
38
|
+
|
39
|
+
To use filebuckets, you must first create a filebucket in your
|
40
|
+
configuration::
|
41
|
+
|
42
|
+
filebucket { main:
|
43
|
+
server => puppet
|
44
|
+
}
|
45
|
+
|
46
|
+
``puppetmasterd`` creates a filebucket by default, so you can
|
47
|
+
usually back up to your main server with this configuration. Once
|
48
|
+
you've described the bucket in your configuration, you can use
|
49
|
+
it in any file::
|
50
|
+
|
51
|
+
file { \"/my/file\":
|
52
|
+
source => \"/path/in/nfs/or/something\",
|
53
|
+
backup => main
|
54
|
+
}
|
55
|
+
|
56
|
+
This will back the file up to the central server.
|
57
|
+
|
58
|
+
At this point, the only benefits to doing so are that you do not
|
59
|
+
have backup files lying around on each of your machines, a given
|
60
|
+
version of a file is only backed up once, and you can restore
|
61
|
+
any given file manually, no matter how old. Eventually,
|
62
|
+
transactional support will be able to automatically restore
|
63
|
+
filebucketed files.
|
64
|
+
"
|
38
65
|
|
66
|
+
attr_reader :bucket
|
39
67
|
defaultto true
|
40
68
|
|
41
69
|
munge do |value|
|
42
70
|
case value
|
43
71
|
when false, "false":
|
44
72
|
false
|
45
|
-
when true, "true":
|
73
|
+
when true, "true", ".puppet-bak":
|
46
74
|
".puppet-bak"
|
47
|
-
when
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
else
|
53
|
-
self.fail "Could not retrieve filebucket %s" %
|
54
|
-
value[1]
|
55
|
-
end
|
56
|
-
else
|
57
|
-
self.fail "Invalid backup object type %s" %
|
58
|
-
value[0].inspect
|
59
|
-
end
|
75
|
+
when String:
|
76
|
+
# We can't depend on looking this up right now,
|
77
|
+
# we have to do it after all of the objects
|
78
|
+
# have been instantiated.
|
79
|
+
@bucket = value
|
60
80
|
else
|
61
81
|
self.fail "Invalid backup type %s" %
|
62
82
|
value.inspect
|
63
83
|
end
|
64
84
|
end
|
85
|
+
|
86
|
+
# Provide a straight-through hook for setting the bucket.
|
87
|
+
def bucket=(bucket)
|
88
|
+
@value = bucket
|
89
|
+
@bucket = bucket
|
90
|
+
end
|
65
91
|
end
|
66
92
|
|
67
93
|
newparam(:linkmaker) do
|
@@ -94,6 +120,22 @@ module Puppet
|
|
94
120
|
end
|
95
121
|
end
|
96
122
|
|
123
|
+
newparam(:links) do
|
124
|
+
desc "How to handle links during file actions. During file copying,
|
125
|
+
``follow`` will copy the target file instead of the link, ``manage``
|
126
|
+
will copy the link itself, and ``ignore`` will just pass it by.
|
127
|
+
When not copying, ``manage`` and ``ignore`` behave equivalently
|
128
|
+
(because you cannot really ignore links entirely during local
|
129
|
+
recursion), and ``follow`` will manage the file to which the
|
130
|
+
link points."
|
131
|
+
|
132
|
+
newvalues(:follow, :manage, :ignore)
|
133
|
+
|
134
|
+
# :ignore and :manage behave equivalently on local files,
|
135
|
+
# but don't copy remote links
|
136
|
+
defaultto :ignore
|
137
|
+
end
|
138
|
+
|
97
139
|
autorequire(:file) do
|
98
140
|
cur = []
|
99
141
|
pary = self[:path].split(File::SEPARATOR)
|
@@ -115,6 +157,29 @@ module Puppet
|
|
115
157
|
end
|
116
158
|
end
|
117
159
|
|
160
|
+
# List files, but only one level deep.
|
161
|
+
def self.list(base = "/")
|
162
|
+
unless FileTest.directory?(base)
|
163
|
+
return []
|
164
|
+
end
|
165
|
+
|
166
|
+
files = []
|
167
|
+
Dir.entries(base).reject { |e|
|
168
|
+
e == "." or e == ".."
|
169
|
+
}.each do |name|
|
170
|
+
path = File.join(base, name)
|
171
|
+
if obj = self[path]
|
172
|
+
obj[:check] = :all
|
173
|
+
files << obj
|
174
|
+
else
|
175
|
+
files << self.create(
|
176
|
+
:name => path, :check => :all
|
177
|
+
)
|
178
|
+
end
|
179
|
+
end
|
180
|
+
files
|
181
|
+
end
|
182
|
+
|
118
183
|
@depthfirst = false
|
119
184
|
|
120
185
|
|
@@ -122,6 +187,52 @@ module Puppet
|
|
122
187
|
@arghash.include?(arg)
|
123
188
|
end
|
124
189
|
|
190
|
+
# Determine the user to write files as.
|
191
|
+
def asuser
|
192
|
+
if self.should(:owner) and ! self.should(:owner).is_a?(Symbol)
|
193
|
+
writeable = Puppet::Util.asuser(self.should(:owner)) {
|
194
|
+
FileTest.writable?(File.dirname(self[:path]))
|
195
|
+
}
|
196
|
+
|
197
|
+
# If the parent directory is writeable, then we execute
|
198
|
+
# as the user in question. Otherwise we'll rely on
|
199
|
+
# the 'owner' state to do things.
|
200
|
+
if writeable
|
201
|
+
asuser = self.should(:owner)
|
202
|
+
end
|
203
|
+
end
|
204
|
+
|
205
|
+
return asuser
|
206
|
+
end
|
207
|
+
|
208
|
+
# We have to do some extra finishing, to retrieve our bucket if
|
209
|
+
# there is one
|
210
|
+
def finish
|
211
|
+
# Let's cache these values, since there should really only be
|
212
|
+
# a couple of these buckets
|
213
|
+
@@filebuckets ||= {}
|
214
|
+
|
215
|
+
# Look up our bucket, if there is one
|
216
|
+
if @parameters.include?(:backup) and bucket = @parameters[:backup].bucket
|
217
|
+
case bucket
|
218
|
+
when String:
|
219
|
+
if obj = @@filebuckets.include?(bucket)
|
220
|
+
@parameters[:backup].bucket = obj
|
221
|
+
elsif obj = Puppet.type(:filebucket).bucket(bucket)
|
222
|
+
@@filebuckets[bucket] = obj
|
223
|
+
@parameters[:backup].bucket = obj
|
224
|
+
else
|
225
|
+
self.fail "Could not find filebucket %s" % bucket
|
226
|
+
end
|
227
|
+
when Puppet::Client::Dipper: # things are hunky-dorey
|
228
|
+
else
|
229
|
+
self.fail "Invalid bucket type %s" % bucket.class
|
230
|
+
end
|
231
|
+
end
|
232
|
+
super
|
233
|
+
end
|
234
|
+
|
235
|
+
# Deal with backups.
|
125
236
|
def handlebackup(file = nil)
|
126
237
|
# let the path be specified
|
127
238
|
file ||= self[:path]
|
@@ -137,6 +248,7 @@ module Puppet
|
|
137
248
|
|
138
249
|
case File.stat(file).ftype
|
139
250
|
when "directory":
|
251
|
+
self.info :bc
|
140
252
|
# we don't need to backup directories
|
141
253
|
return true
|
142
254
|
when "file":
|
@@ -144,8 +256,8 @@ module Puppet
|
|
144
256
|
case backup
|
145
257
|
when Puppet::Client::Dipper:
|
146
258
|
sum = backup.backup(file)
|
147
|
-
self.info "Filebucketed %s with sum %s" %
|
148
|
-
[
|
259
|
+
self.info "Filebucketed to %s with sum %s" %
|
260
|
+
[backup.name, sum]
|
149
261
|
return true
|
150
262
|
when String:
|
151
263
|
newfile = file + backup
|
@@ -183,8 +295,8 @@ module Puppet
|
|
183
295
|
return children unless self[:ignore]
|
184
296
|
self[:ignore].each { |ignore|
|
185
297
|
ignored = []
|
186
|
-
Dir.glob(File.join(self[:path],ignore), File::FNM_DOTMATCH) {
|
187
|
-
ignored.push(File.basename(match))
|
298
|
+
Dir.glob(File.join(self[:path],ignore), File::FNM_DOTMATCH) {
|
299
|
+
|match| ignored.push(File.basename(match))
|
188
300
|
}
|
189
301
|
children = children - ignored
|
190
302
|
}
|
@@ -194,7 +306,6 @@ module Puppet
|
|
194
306
|
def initialize(hash)
|
195
307
|
# clean out as many references to any file paths as possible
|
196
308
|
# this was the source of many, many bugs
|
197
|
-
|
198
309
|
@arghash = self.argclean(hash)
|
199
310
|
@arghash.delete(self.class.namevar)
|
200
311
|
|
@@ -245,11 +356,10 @@ module Puppet
|
|
245
356
|
# We specifically look in @parameters here, because 'linkmaker' isn't
|
246
357
|
# a valid attribute for subclasses, so using 'self[:linkmaker]' throws
|
247
358
|
# an error.
|
248
|
-
if @parameters.include?(:linkmaker) and
|
359
|
+
if @parameters.include?(:linkmaker) and
|
249
360
|
args.include?(:source) and ! FileTest.directory?(args[:source])
|
250
361
|
klass = Puppet.type(:symlink)
|
251
362
|
|
252
|
-
self.debug "%s is a link" % path
|
253
363
|
# clean up the args a lot for links
|
254
364
|
old = args.dup
|
255
365
|
args = {
|
@@ -364,8 +474,8 @@ module Puppet
|
|
364
474
|
end
|
365
475
|
|
366
476
|
# are we at the end of the recursion?
|
367
|
-
if recurse == 0
|
368
|
-
|
477
|
+
#if recurse == 0
|
478
|
+
unless self.recurse?
|
369
479
|
return
|
370
480
|
end
|
371
481
|
|
@@ -374,11 +484,88 @@ module Puppet
|
|
374
484
|
end
|
375
485
|
|
376
486
|
self.localrecurse(recurse)
|
487
|
+
if @states.include? :target
|
488
|
+
self.linkrecurse(recurse)
|
489
|
+
end
|
377
490
|
if @states.include?(:source)
|
378
491
|
self.sourcerecurse(recurse)
|
379
492
|
end
|
380
493
|
end
|
381
494
|
|
495
|
+
def recurse?
|
496
|
+
return false unless @parameters.include?(:recurse)
|
497
|
+
|
498
|
+
val = @parameters[:recurse].value
|
499
|
+
|
500
|
+
if val and (val == true or val > 0)
|
501
|
+
return true
|
502
|
+
else
|
503
|
+
return false
|
504
|
+
end
|
505
|
+
end
|
506
|
+
|
507
|
+
# Build a recursive map of a link source
|
508
|
+
def linkrecurse(recurse)
|
509
|
+
target = @states[:target].should
|
510
|
+
|
511
|
+
method = :lstat
|
512
|
+
if self[:links] == :follow
|
513
|
+
method = :stat
|
514
|
+
end
|
515
|
+
|
516
|
+
targetstat = nil
|
517
|
+
unless FileTest.exist?(target)
|
518
|
+
#self.info "%s does not exist; not recursing" %
|
519
|
+
# target
|
520
|
+
return
|
521
|
+
end
|
522
|
+
# Now stat our target
|
523
|
+
targetstat = File.send(method, target)
|
524
|
+
unless targetstat.ftype == "directory"
|
525
|
+
#self.info "%s is not a directory; not recursing" %
|
526
|
+
# target
|
527
|
+
return
|
528
|
+
end
|
529
|
+
|
530
|
+
# Now that we know our corresponding target is a directory,
|
531
|
+
# change our type
|
532
|
+
self[:ensure] = :directory
|
533
|
+
|
534
|
+
unless FileTest.readable? target
|
535
|
+
self.notice "Cannot manage %s: permission denied" % self.name
|
536
|
+
return
|
537
|
+
end
|
538
|
+
|
539
|
+
children = Dir.entries(target).reject { |d| d =~ /^\.+$/ }
|
540
|
+
|
541
|
+
#Get rid of ignored children
|
542
|
+
if @parameters.include?(:ignore)
|
543
|
+
children = handleignore(children)
|
544
|
+
end
|
545
|
+
|
546
|
+
added = []
|
547
|
+
children.each do |file|
|
548
|
+
Dir.chdir(target) do
|
549
|
+
longname = File.join(target, file)
|
550
|
+
|
551
|
+
# Files know to create directories when recursion
|
552
|
+
# is enabled and we're making links
|
553
|
+
args = {
|
554
|
+
:recurse => recurse,
|
555
|
+
:ensure => longname
|
556
|
+
}
|
557
|
+
|
558
|
+
if child = self.newchild(file, true, args)
|
559
|
+
unless @children.include?(child)
|
560
|
+
self.push child
|
561
|
+
added.push file
|
562
|
+
end
|
563
|
+
end
|
564
|
+
end
|
565
|
+
end
|
566
|
+
end
|
567
|
+
|
568
|
+
# Build up a recursive map of what's around right now
|
382
569
|
def localrecurse(recurse)
|
383
570
|
unless FileTest.exist?(self[:path]) and self.stat.directory?
|
384
571
|
#self.info "%s is not a directory; not recursing" %
|
@@ -450,7 +637,7 @@ module Puppet
|
|
450
637
|
|
451
638
|
#self.warning "Listing path %s with ignore %s" %
|
452
639
|
# [path.inspect, ignore.inspect]
|
453
|
-
desc = server.list(path, r, ignore)
|
640
|
+
desc = server.list(path, self[:links], r, ignore)
|
454
641
|
|
455
642
|
desc.split("\n").each { |line|
|
456
643
|
file, type = line.split("\t")
|
@@ -513,15 +700,23 @@ module Puppet
|
|
513
700
|
end
|
514
701
|
end
|
515
702
|
|
703
|
+
# Stat our file. Depending on the value of the 'links' attribute, we use
|
704
|
+
# either 'stat' or 'lstat', and we expect the states to use the resulting
|
705
|
+
# stat object accordingly (mostly by testing the 'ftype' value).
|
516
706
|
def stat(refresh = false)
|
707
|
+
method = :stat
|
708
|
+
|
709
|
+
# Files are the only types that support links
|
710
|
+
if self.class.name == :file and self[:links] != :follow
|
711
|
+
method = :lstat
|
712
|
+
end
|
517
713
|
if @stat.nil? or refresh == true
|
518
714
|
begin
|
519
|
-
@stat = File.
|
715
|
+
@stat = File.send(method, self[:path])
|
520
716
|
rescue Errno::ENOENT => error
|
521
717
|
@stat = nil
|
522
|
-
rescue => error
|
523
|
-
self.
|
524
|
-
[self.name,error]
|
718
|
+
rescue Errno::EACCES => error
|
719
|
+
self.warning "Could not stat; permission denied"
|
525
720
|
@stat = nil
|
526
721
|
end
|
527
722
|
end
|
@@ -583,6 +778,64 @@ module Puppet
|
|
583
778
|
|
584
779
|
return [sourceobj, path.sub(/\/\//, '/')]
|
585
780
|
end
|
781
|
+
|
782
|
+
# Write out the file. We open the file correctly, with all of the
|
783
|
+
# uid and mode and such, and then yield the file handle for actual
|
784
|
+
# writing.
|
785
|
+
def write(usetmp = true)
|
786
|
+
mode = self.should(:mode)
|
787
|
+
|
788
|
+
if FileTest.exists?(self[:path])
|
789
|
+
# this makes sure we have a copy for posterity
|
790
|
+
@backed = self.handlebackup
|
791
|
+
end
|
792
|
+
|
793
|
+
# The temporary file
|
794
|
+
path = nil
|
795
|
+
if usetmp
|
796
|
+
path = self[:path] + ".puppettmp"
|
797
|
+
else
|
798
|
+
path = self[:path]
|
799
|
+
end
|
800
|
+
|
801
|
+
# As the correct user and group
|
802
|
+
Puppet::Util.asuser(asuser(), self.should(:group)) do
|
803
|
+
f = nil
|
804
|
+
# Open our file with the correct modes
|
805
|
+
if mode
|
806
|
+
Puppet::Util.withumask(000) do
|
807
|
+
f = File.open(path,
|
808
|
+
File::CREAT|File::WRONLY|File::TRUNC, mode)
|
809
|
+
end
|
810
|
+
else
|
811
|
+
f = File.open(path, File::CREAT|File::WRONLY|File::TRUNC)
|
812
|
+
end
|
813
|
+
|
814
|
+
# Yield it
|
815
|
+
yield f
|
816
|
+
|
817
|
+
f.flush
|
818
|
+
f.close
|
819
|
+
end
|
820
|
+
|
821
|
+
# And put our new file in place
|
822
|
+
if usetmp
|
823
|
+
begin
|
824
|
+
File.rename(path, self[:path])
|
825
|
+
rescue => detail
|
826
|
+
self.err "Could not rename tmp %s for replacing: %s" %
|
827
|
+
[self[:path], detail]
|
828
|
+
ensure
|
829
|
+
# Make sure the created file gets removed
|
830
|
+
if FileTest.exists?(path)
|
831
|
+
File.unlink(path)
|
832
|
+
end
|
833
|
+
end
|
834
|
+
end
|
835
|
+
|
836
|
+
# And then update our checksum, so the next run doesn't find it.
|
837
|
+
self.setchecksum
|
838
|
+
end
|
586
839
|
end # Puppet.type(:pfile)
|
587
840
|
|
588
841
|
# the filesource class can't include the path, because the path
|
@@ -597,10 +850,11 @@ module Puppet
|
|
597
850
|
require 'puppet/type/pfile/checksum'
|
598
851
|
require 'puppet/type/pfile/content' # can create the file
|
599
852
|
require 'puppet/type/pfile/source' # can create the file
|
853
|
+
require 'puppet/type/pfile/target'
|
600
854
|
require 'puppet/type/pfile/ensure' # can create the file
|
601
855
|
require 'puppet/type/pfile/uid'
|
602
856
|
require 'puppet/type/pfile/group'
|
603
857
|
require 'puppet/type/pfile/mode'
|
604
858
|
require 'puppet/type/pfile/type'
|
605
859
|
end
|
606
|
-
# $Id: pfile.rb
|
860
|
+
# $Id: pfile.rb 1125 2006-04-20 19:38:48Z luke $
|