puppet 0.9.2

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.

Files changed (182) hide show
  1. data/CHANGELOG +0 -0
  2. data/COPYING +340 -0
  3. data/LICENSE +17 -0
  4. data/README +24 -0
  5. data/Rakefile +294 -0
  6. data/TODO +4 -0
  7. data/bin/cf2puppet +186 -0
  8. data/bin/puppet +176 -0
  9. data/bin/puppetca +213 -0
  10. data/bin/puppetd +246 -0
  11. data/bin/puppetdoc +184 -0
  12. data/bin/puppetmasterd +258 -0
  13. data/examples/code/allatonce +13 -0
  14. data/examples/code/assignments +11 -0
  15. data/examples/code/classing +35 -0
  16. data/examples/code/components +73 -0
  17. data/examples/code/execs +16 -0
  18. data/examples/code/failers/badclassnoparam +10 -0
  19. data/examples/code/failers/badclassparam +10 -0
  20. data/examples/code/failers/badcompnoparam +9 -0
  21. data/examples/code/failers/badcompparam +9 -0
  22. data/examples/code/failers/badtypeparam +3 -0
  23. data/examples/code/file.bl +11 -0
  24. data/examples/code/filedefaults +10 -0
  25. data/examples/code/fileparsing +116 -0
  26. data/examples/code/filerecursion +15 -0
  27. data/examples/code/functions +3 -0
  28. data/examples/code/groups +7 -0
  29. data/examples/code/head +30 -0
  30. data/examples/code/importing +8 -0
  31. data/examples/code/nodes +20 -0
  32. data/examples/code/one +8 -0
  33. data/examples/code/relationships +34 -0
  34. data/examples/code/selectors +28 -0
  35. data/examples/code/simpletests +11 -0
  36. data/examples/code/snippets/argumentdefaults +14 -0
  37. data/examples/code/snippets/casestatement +39 -0
  38. data/examples/code/snippets/classheirarchy.pp +15 -0
  39. data/examples/code/snippets/classincludes.pp +17 -0
  40. data/examples/code/snippets/classpathtest +11 -0
  41. data/examples/code/snippets/dirchmod +19 -0
  42. data/examples/code/snippets/failmissingexecpath.pp +13 -0
  43. data/examples/code/snippets/falsevalues.pp +3 -0
  44. data/examples/code/snippets/filecreate +11 -0
  45. data/examples/code/snippets/implicititeration +15 -0
  46. data/examples/code/snippets/multipleinstances +7 -0
  47. data/examples/code/snippets/namevartest +9 -0
  48. data/examples/code/snippets/scopetest +13 -0
  49. data/examples/code/snippets/selectorvalues.pp +22 -0
  50. data/examples/code/snippets/simpledefaults +5 -0
  51. data/examples/code/snippets/simpleselector +38 -0
  52. data/examples/code/svncommit +13 -0
  53. data/examples/root/bin/sleeper +69 -0
  54. data/examples/root/etc/configfile +0 -0
  55. data/examples/root/etc/debian-passwd +29 -0
  56. data/examples/root/etc/debian-syslog.conf +71 -0
  57. data/examples/root/etc/init.d/sleeper +65 -0
  58. data/examples/root/etc/otherfile +0 -0
  59. data/examples/root/etc/puppet/fileserver.conf +3 -0
  60. data/examples/root/etc/puppet/puppetmasterd.conf +10 -0
  61. data/ext/module:puppet +195 -0
  62. data/install.rb +270 -0
  63. data/lib/puppet.rb +249 -0
  64. data/lib/puppet/base64.rb +19 -0
  65. data/lib/puppet/client.rb +519 -0
  66. data/lib/puppet/config.rb +49 -0
  67. data/lib/puppet/daemon.rb +208 -0
  68. data/lib/puppet/element.rb +71 -0
  69. data/lib/puppet/event.rb +259 -0
  70. data/lib/puppet/log.rb +321 -0
  71. data/lib/puppet/metric.rb +250 -0
  72. data/lib/puppet/parsedfile.rb +38 -0
  73. data/lib/puppet/parser/ast.rb +1560 -0
  74. data/lib/puppet/parser/interpreter.rb +150 -0
  75. data/lib/puppet/parser/lexer.rb +226 -0
  76. data/lib/puppet/parser/parser.rb +1354 -0
  77. data/lib/puppet/parser/scope.rb +755 -0
  78. data/lib/puppet/server.rb +170 -0
  79. data/lib/puppet/server/authstore.rb +227 -0
  80. data/lib/puppet/server/ca.rb +140 -0
  81. data/lib/puppet/server/filebucket.rb +147 -0
  82. data/lib/puppet/server/fileserver.rb +477 -0
  83. data/lib/puppet/server/logger.rb +43 -0
  84. data/lib/puppet/server/master.rb +103 -0
  85. data/lib/puppet/server/servlet.rb +247 -0
  86. data/lib/puppet/sslcertificates.rb +737 -0
  87. data/lib/puppet/statechange.rb +150 -0
  88. data/lib/puppet/storage.rb +95 -0
  89. data/lib/puppet/transaction.rb +179 -0
  90. data/lib/puppet/transportable.rb +151 -0
  91. data/lib/puppet/type.rb +1354 -0
  92. data/lib/puppet/type/component.rb +141 -0
  93. data/lib/puppet/type/cron.rb +543 -0
  94. data/lib/puppet/type/exec.rb +316 -0
  95. data/lib/puppet/type/group.rb +152 -0
  96. data/lib/puppet/type/nameservice.rb +3 -0
  97. data/lib/puppet/type/nameservice/netinfo.rb +173 -0
  98. data/lib/puppet/type/nameservice/objectadd.rb +146 -0
  99. data/lib/puppet/type/nameservice/posix.rb +200 -0
  100. data/lib/puppet/type/package.rb +420 -0
  101. data/lib/puppet/type/package/apt.rb +70 -0
  102. data/lib/puppet/type/package/dpkg.rb +108 -0
  103. data/lib/puppet/type/package/rpm.rb +81 -0
  104. data/lib/puppet/type/package/sun.rb +117 -0
  105. data/lib/puppet/type/package/yum.rb +58 -0
  106. data/lib/puppet/type/pfile.rb +569 -0
  107. data/lib/puppet/type/pfile/checksum.rb +219 -0
  108. data/lib/puppet/type/pfile/create.rb +108 -0
  109. data/lib/puppet/type/pfile/group.rb +129 -0
  110. data/lib/puppet/type/pfile/mode.rb +131 -0
  111. data/lib/puppet/type/pfile/source.rb +264 -0
  112. data/lib/puppet/type/pfile/type.rb +31 -0
  113. data/lib/puppet/type/pfile/uid.rb +166 -0
  114. data/lib/puppet/type/pfilebucket.rb +80 -0
  115. data/lib/puppet/type/pprocess.rb +97 -0
  116. data/lib/puppet/type/service.rb +347 -0
  117. data/lib/puppet/type/service/base.rb +17 -0
  118. data/lib/puppet/type/service/debian.rb +50 -0
  119. data/lib/puppet/type/service/init.rb +145 -0
  120. data/lib/puppet/type/service/smf.rb +29 -0
  121. data/lib/puppet/type/state.rb +182 -0
  122. data/lib/puppet/type/symlink.rb +183 -0
  123. data/lib/puppet/type/tidy.rb +183 -0
  124. data/lib/puppet/type/typegen.rb +149 -0
  125. data/lib/puppet/type/typegen/filerecord.rb +243 -0
  126. data/lib/puppet/type/typegen/filetype.rb +316 -0
  127. data/lib/puppet/type/user.rb +290 -0
  128. data/lib/puppet/util.rb +138 -0
  129. data/test/certmgr/certmgr.rb +265 -0
  130. data/test/client/client.rb +203 -0
  131. data/test/executables/puppetbin.rb +53 -0
  132. data/test/executables/puppetca.rb +79 -0
  133. data/test/executables/puppetd.rb +71 -0
  134. data/test/executables/puppetmasterd.rb +153 -0
  135. data/test/executables/puppetmodule.rb +60 -0
  136. data/test/language/ast.rb +412 -0
  137. data/test/language/interpreter.rb +71 -0
  138. data/test/language/scope.rb +412 -0
  139. data/test/language/snippets.rb +445 -0
  140. data/test/other/events.rb +111 -0
  141. data/test/other/log.rb +195 -0
  142. data/test/other/metrics.rb +92 -0
  143. data/test/other/overrides.rb +115 -0
  144. data/test/other/parsedfile.rb +31 -0
  145. data/test/other/relationships.rb +113 -0
  146. data/test/other/state.rb +106 -0
  147. data/test/other/storage.rb +39 -0
  148. data/test/other/transactions.rb +235 -0
  149. data/test/parser/lexer.rb +120 -0
  150. data/test/parser/parser.rb +180 -0
  151. data/test/puppet/conffiles.rb +104 -0
  152. data/test/puppet/defaults.rb +100 -0
  153. data/test/puppet/error.rb +23 -0
  154. data/test/puppet/utiltest.rb +120 -0
  155. data/test/puppettest.rb +774 -0
  156. data/test/server/authstore.rb +209 -0
  157. data/test/server/bucket.rb +227 -0
  158. data/test/server/ca.rb +201 -0
  159. data/test/server/fileserver.rb +710 -0
  160. data/test/server/logger.rb +175 -0
  161. data/test/server/master.rb +150 -0
  162. data/test/server/server.rb +130 -0
  163. data/test/tagging/tagging.rb +80 -0
  164. data/test/test +51 -0
  165. data/test/types/basic.rb +119 -0
  166. data/test/types/component.rb +272 -0
  167. data/test/types/cron.rb +261 -0
  168. data/test/types/exec.rb +273 -0
  169. data/test/types/file.rb +616 -0
  170. data/test/types/filebucket.rb +167 -0
  171. data/test/types/fileignoresource.rb +287 -0
  172. data/test/types/filesources.rb +587 -0
  173. data/test/types/filetype.rb +162 -0
  174. data/test/types/group.rb +271 -0
  175. data/test/types/package.rb +205 -0
  176. data/test/types/query.rb +101 -0
  177. data/test/types/service.rb +100 -0
  178. data/test/types/symlink.rb +93 -0
  179. data/test/types/tidy.rb +124 -0
  180. data/test/types/type.rb +135 -0
  181. data/test/types/user.rb +371 -0
  182. metadata +243 -0
@@ -0,0 +1,316 @@
1
+
2
+ require 'open3'
3
+ require 'puppet/type/state'
4
+
5
+ module Puppet
6
+ # okay, how do we deal with parameters that don't have operations
7
+ # associated with them?
8
+ class State
9
+ # this always runs
10
+ class Returns < Puppet::State
11
+ attr_reader :output
12
+
13
+ @doc = "The expected return code. An error will be returned if the
14
+ executed command returns something else."
15
+ @name = :returns
16
+
17
+ # Make output a bit prettier
18
+ def change_to_s
19
+ return "executed successfully"
20
+ end
21
+
22
+ # because this command always runs,
23
+ # we're just using retrieve to verify that the command
24
+ # exists and such
25
+ def retrieve
26
+ if file = @parent[:creates]
27
+ if FileTest.exists?(file)
28
+ @is = true
29
+ @should = [true]
30
+ return
31
+ end
32
+ end
33
+
34
+ cmd = self.parent[:command]
35
+ if cmd =~ /^\//
36
+ exe = cmd.split(/ /)[0]
37
+ unless FileTest.exists?(exe)
38
+ raise TypeError.new(
39
+ "Could not find executable %s" % exe
40
+ )
41
+ end
42
+ unless FileTest.executable?(exe)
43
+ raise TypeError.new(
44
+ "%s is not executable" % exe
45
+ )
46
+ end
47
+ elsif path = self.parent[:path]
48
+ exe = cmd.split(/ /)[0]
49
+ tmppath = ENV["PATH"]
50
+ ENV["PATH"] = self.parent[:path]
51
+
52
+ path = %{which #{exe}}.chomp
53
+ if path == ""
54
+ raise TypeError.new(
55
+ "Could not find command '%s'" % exe
56
+ )
57
+ end
58
+ ENV["PATH"] = tmppath
59
+ else
60
+ raise TypeError.new(
61
+ "%s is somehow not qualified with no search path" %
62
+ self.parent[:command]
63
+ )
64
+ end
65
+
66
+ if self.parent[:refreshonly]
67
+ # if refreshonly is enabled, then set things so we
68
+ # won't sync
69
+ self.is = self.should
70
+ else
71
+ # else, just set it to something we know it won't be
72
+ self.is = nil
73
+ end
74
+ end
75
+
76
+ # Actually execute the command.
77
+ def sync
78
+ olddir = nil
79
+
80
+ # We need a dir to change to, even if it's just the cwd
81
+ dir = self.parent[:cwd] || Dir.pwd
82
+ tmppath = ENV["PATH"]
83
+
84
+ begin
85
+ # Do our chdir
86
+ Dir.chdir(dir) {
87
+ ENV["PATH"] = self.parent[:path]
88
+
89
+ # The user and group default to nil, which 'asuser'
90
+ # handlers correctly
91
+ Puppet::Util.asuser(@parent[:user], @parent[:group]) {
92
+ # capture both stdout and stderr
93
+
94
+ #stdin, stdout, stderr = Open3.popen3(self.parent[:command])
95
+ #@output = stdout.read
96
+ #err = stderr.read
97
+
98
+ #stderr = Puppet::Util.capture_stderr {
99
+ # @output = %x{#{self.parent[:command]}}
100
+ #}
101
+ if @parent[:user]
102
+ unless defined? @@alreadywarned
103
+ Puppet.warning(
104
+ "Cannot capture STDERR when running as another user"
105
+ )
106
+ @@alreadywarned = true
107
+ end
108
+ @output = %x{#{self.parent[:command]}}
109
+ else
110
+ @output = %x{#{self.parent[:command]} 2>&1}
111
+ end
112
+
113
+ #if err != ""
114
+ # stderr.split(/\n/).each { |line|
115
+ # self.send(:err, line)
116
+ # }
117
+ #end
118
+ }
119
+ status = $?
120
+
121
+ loglevel = @parent[:loglevel]
122
+ if status.exitstatus.to_s != self.should.to_s
123
+ err("%s returned %s" %
124
+ [self.parent[:command],status.exitstatus])
125
+
126
+ # if we've had a failure, up the log level
127
+ loglevel = :err
128
+ end
129
+
130
+ # and log
131
+ @output.split(/\n/).each { |line|
132
+ self.send(loglevel, line)
133
+ }
134
+ }
135
+ rescue Errno::ENOENT => detail
136
+ raise Puppet::Error, detail.to_s
137
+ ensure
138
+ # reset things to how we found them
139
+ ENV["PATH"] = tmppath
140
+ end
141
+
142
+ return :executed_command
143
+ end
144
+ end
145
+ end
146
+
147
+ class Type
148
+ class Exec < Type
149
+ # this is kind of hackish, using the return value as the
150
+ # state, but apparently namevars can't also be states
151
+ # who knew?
152
+ @states = [
153
+ Puppet::State::Returns
154
+ ]
155
+
156
+ @parameters = [
157
+ :path,
158
+ :user,
159
+ :group,
160
+ :creates,
161
+ :cwd,
162
+ :refreshonly,
163
+ :command
164
+ ]
165
+
166
+ @paramdoc[:path] = "The search path used for command execution.
167
+ Commands must be fully qualified if no path is specified."
168
+ @paramdoc[:user] = "The user to run the command as. Note that if you use
169
+ this then any error output is not currently captured. This is mostly
170
+ because of a bug within Ruby."
171
+ @paramdoc[:group] = "The group to run the command as."
172
+ @paramdoc[:cwd] = "The directory from which to run the command. If
173
+ this directory does not exist, the command will fail."
174
+ @paramdoc[:refreshonly] = "The command should only be run as a
175
+ refresh mechanism for when a dependent object is changed."
176
+ @paramdoc[:command] = "The actual command to execute."
177
+ @paramdoc[:creates] = "A file that this command creates. If this
178
+ parameter is provided, then the command will only be run
179
+ if the specified file does not exist."
180
+
181
+ @doc = "Executes external commands. It is critical that all commands
182
+ executed using this mechanism can be run multiple times without
183
+ harm, i.e., they are *idempotent*. One useful way to create idempotent
184
+ commands is to use the *creates* parameter.
185
+
186
+ It is worth nothing that ``exec`` is special, in that it is not
187
+ currently considered an error to have multiple ``exec`` instances
188
+ with the same name. This was done purely because it had to be this
189
+ way in order to get certain functionality, but it complicates things.
190
+ In particular, you will not be able to use ``exec`` instances that
191
+ share their commands with other instances as a dependency, since
192
+ Puppet has no way of knowing which instance you mean.
193
+
194
+ It is recommended to avoid duplicate names whenever possible."
195
+ @name = :exec
196
+ @namevar = :command
197
+
198
+ # Exec names are not isomorphic with the objects.
199
+ @isomorphic = false
200
+
201
+ def initialize(hash)
202
+ # default to erroring on a non-zero return
203
+ if hash.include?("returns")
204
+ if hash["returns"].is_a?(Fixnum)
205
+ hash["returns"] = hash["returns"].to_s
206
+ end
207
+ elsif hash.include?(:returns)
208
+ if hash[:returns].is_a?(Fixnum)
209
+ hash[:returns] = hash[:returns].to_s
210
+ end
211
+ else
212
+ hash[:returns] = "0"
213
+ end
214
+
215
+ super
216
+
217
+ if self[:command].nil?
218
+ raise TypeError.new("Somehow the command is nil")
219
+ end
220
+
221
+ # if we're not fully qualified, require a path
222
+ if self[:command] !~ /^\//
223
+ if self[:path].nil?
224
+ raise TypeError,
225
+ "both unqualifed and specified no search path"
226
+ end
227
+ end
228
+ end
229
+
230
+ def output
231
+ if self.state(:returns).nil?
232
+ return nil
233
+ else
234
+ return self.state(:returns).output
235
+ end
236
+ end
237
+
238
+ # FIXME if they try to set this and fail, then we should probably
239
+ # fail the entire exec, right?
240
+ def paramcreates=(file)
241
+ unless file =~ %r{^#{File::SEPARATOR}}
242
+ raise Puppet::Error, "'creates' files must be fully qualified."
243
+ end
244
+ @parameters[:creates] = file
245
+ end
246
+
247
+ def paramcwd=(dir)
248
+ if dir.is_a?(Array)
249
+ dir = dir[0]
250
+ end
251
+
252
+ unless File.directory?(dir)
253
+ raise Puppet::Error, "Directory '%s' does not exist" % dir
254
+ end
255
+
256
+ @parameters[:cwd] = dir
257
+ end
258
+
259
+ # Execute the command as the specified group
260
+ def paramgroup=(group)
261
+ require 'etc'
262
+ method = :getgrnam
263
+ case group
264
+ when Integer: method = :getgrgid
265
+ when /^\d+$/
266
+ group = group.to_i
267
+ method = :getgrgid
268
+ end
269
+
270
+ begin
271
+ Etc.send(method, group)
272
+ rescue ArgumentError
273
+ raise Puppet::Error, "No such group %s" % group
274
+ end
275
+
276
+ @parameters[:group] = group
277
+ end
278
+
279
+ # Execute the command as the specified user
280
+ def paramuser=(user)
281
+ unless Process.uid == 0
282
+ raise Puppet::Error,
283
+ "Only root can execute commands as other users"
284
+ end
285
+ require 'etc'
286
+
287
+ method = :getpwnam
288
+ case user
289
+ when Integer
290
+ method = :getpwuid
291
+ when /^\d+$/
292
+ user = user.to_i
293
+ method = :getpwuid
294
+ end
295
+ begin
296
+ Etc.send(method, user)
297
+ rescue ArgumentError
298
+ raise Puppet::Error, "No such user %s" % user
299
+ end
300
+
301
+ @parameters[:user] = user
302
+ end
303
+
304
+ # this might be a very, very bad idea...
305
+ def refresh
306
+ self.state(:returns).sync
307
+ end
308
+
309
+ def to_s
310
+ "exec(%s)" % self.name
311
+ end
312
+ end
313
+ end
314
+ end
315
+
316
+ # $Id: exec.rb 743 2005-11-16 21:39:31Z luke $
@@ -0,0 +1,152 @@
1
+ # Manage Unix groups. This class is annoyingly complicated; There
2
+ # is some variety in whether systems use 'groupadd' or 'addgroup', but OS X
3
+ # significantly complicates the picture by using NetInfo. Eventually we
4
+ # will also need to deal with systems that have their groups hosted elsewhere
5
+ # (e.g., in LDAP). That will likely only be a problem for OS X, since it
6
+ # currently does not use the POSIX interfaces, since lookupd's cache screws
7
+ # things up.
8
+
9
+ require 'etc'
10
+ require 'facter'
11
+ require 'puppet/type/state'
12
+ require 'puppet/type/nameservice'
13
+
14
+ module Puppet
15
+ class State
16
+ module GroupGID
17
+ def self.doc
18
+ "The group ID. Must be specified numerically. If not
19
+ specified, a number will be picked, which can result in ID
20
+ differences across systems and thus is not recommended. The
21
+ GID is picked according to local system standards."
22
+ end
23
+
24
+ def self.name
25
+ :gid
26
+ end
27
+
28
+ def autogen
29
+ highest = 0
30
+ Etc.group { |group|
31
+ if group.gid > highest
32
+ unless group.gid > 65000
33
+ highest = group.gid
34
+ end
35
+ end
36
+ }
37
+
38
+ return highest + 1
39
+ end
40
+
41
+ def shouldprocess(gid)
42
+ case gid
43
+ when String
44
+ if gid =~ /^[-0-9]+$/
45
+ gid = Integer(gid)
46
+ else
47
+ raise Puppet::Error, "Invalid GID %s" % gid
48
+ end
49
+ when Symbol
50
+ unless gid == :auto or gid == :notfound
51
+ raise Puppet::DevError, "Invalid GID %s" % gid
52
+ end
53
+ if gid == :auto
54
+ unless self.class.autogen?
55
+ gid = autogen
56
+ end
57
+ end
58
+ end
59
+
60
+ self.info "Setting gid to %s" % gid
61
+
62
+ return gid
63
+ end
64
+ end
65
+ end
66
+
67
+ class Type
68
+ class Group < Type
69
+ statenames = [
70
+ "GroupGID"
71
+ ]
72
+ case Facter["operatingsystem"].value
73
+ when "Darwin":
74
+ @statemodule = Puppet::NameService::NetInfo
75
+ else
76
+ @statemodule = Puppet::NameService::ObjectAdd
77
+ end
78
+
79
+ @states = statenames.collect { |name|
80
+ fullname = @statemodule.to_s + "::" + name
81
+ begin
82
+ eval(fullname)
83
+ rescue NameError
84
+ raise Puppet::DevError, "Could not retrieve state class %s" %
85
+ fullname
86
+ end
87
+ }.each { |klass|
88
+ klass.complete
89
+ }
90
+
91
+ @name = :group
92
+ @namevar = :name
93
+
94
+ @parameters = [:name]
95
+
96
+ class << self
97
+ attr_accessor :netinfodir
98
+ attr_accessor :statemodule
99
+ end
100
+
101
+ @netinfodir = "groups"
102
+
103
+ @paramdoc[:name] = "The group name. While naming limitations vary by
104
+ system, it is advisable to keep the name to the degenerate
105
+ limitations, which is a maximum of 8 characters beginning with
106
+ a letter."
107
+
108
+ @doc = "Manage groups. This type can only create groups. Group
109
+ membership must be managed on individual users."
110
+
111
+ def exists?
112
+ self.class.statemodule.exists?(self)
113
+ end
114
+
115
+ def getinfo(refresh = false)
116
+ if @groupinfo.nil? or refresh == true
117
+ begin
118
+ @groupinfo = Etc.getgrnam(self.name)
119
+ rescue ArgumentError => detail
120
+ @groupinfo = nil
121
+ end
122
+ end
123
+
124
+ @groupinfo
125
+ end
126
+
127
+ def initialize(hash)
128
+ @groupinfo = nil
129
+ super
130
+ end
131
+
132
+ def retrieve
133
+ if self.exists?
134
+ super
135
+ else
136
+ # the group does not exist
137
+ unless @states.include?(:gid)
138
+ self[:gid] = :auto
139
+ end
140
+
141
+ @states.each { |name, state|
142
+ state.is = :notfound
143
+ }
144
+
145
+ return
146
+ end
147
+ end
148
+ end
149
+ end
150
+ end
151
+
152
+ # $Id: group.rb 731 2005-10-26 04:44:25Z luke $