puppet 0.9.2 → 0.13.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.

Files changed (213) hide show
  1. data/CHANGELOG +58 -0
  2. data/README +21 -18
  3. data/Rakefile +176 -36
  4. data/bin/puppet +34 -48
  5. data/bin/puppetca +41 -28
  6. data/bin/puppetd +87 -65
  7. data/bin/puppetdoc +99 -23
  8. data/bin/puppetmasterd +72 -91
  9. data/conf/redhat/client.init +80 -0
  10. data/conf/redhat/client.sysconfig +11 -0
  11. data/conf/redhat/fileserver.conf +12 -0
  12. data/conf/redhat/puppet.spec +130 -0
  13. data/conf/redhat/server.init +89 -0
  14. data/conf/redhat/server.sysconfig +9 -0
  15. data/examples/code/allatonce +2 -2
  16. data/examples/code/assignments +1 -1
  17. data/examples/code/classing +2 -2
  18. data/examples/code/components +2 -2
  19. data/examples/code/file.bl +5 -5
  20. data/examples/code/filedefaults +2 -2
  21. data/examples/code/fileparsing +1 -1
  22. data/examples/code/filerecursion +1 -1
  23. data/examples/code/functions +1 -1
  24. data/examples/code/groups +1 -1
  25. data/examples/code/importing +1 -1
  26. data/examples/code/nodes +1 -1
  27. data/examples/code/one +1 -1
  28. data/examples/code/relationships +2 -2
  29. data/examples/code/simpletests +5 -5
  30. data/examples/code/snippets/argumentdefaults +2 -2
  31. data/examples/code/snippets/casestatement +16 -8
  32. data/examples/code/snippets/classheirarchy.pp +4 -4
  33. data/examples/code/snippets/classincludes.pp +4 -4
  34. data/examples/code/snippets/classpathtest +2 -2
  35. data/examples/code/snippets/componentmetaparams.pp +11 -0
  36. data/examples/code/snippets/dirchmod +5 -5
  37. data/examples/code/snippets/emptyclass.pp +9 -0
  38. data/examples/code/snippets/failmissingexecpath.pp +1 -1
  39. data/examples/code/snippets/falsevalues.pp +1 -1
  40. data/examples/code/snippets/filecreate +5 -5
  41. data/examples/code/snippets/implicititeration +5 -5
  42. data/examples/code/snippets/multipleinstances +4 -4
  43. data/examples/code/snippets/namevartest +3 -3
  44. data/examples/code/snippets/scopetest +1 -1
  45. data/examples/code/snippets/selectorvalues.pp +3 -3
  46. data/examples/code/snippets/simpledefaults +2 -2
  47. data/examples/code/snippets/simpleselector +5 -5
  48. data/examples/code/snippets/singleary.pp +19 -0
  49. data/examples/root/etc/init.d/sleeper +3 -2
  50. data/ext/emacs/puppet-mode-init.el +6 -0
  51. data/ext/emacs/puppet-mode.el +189 -0
  52. data/ext/ldap/puppet.schema +17 -0
  53. data/ext/{module:puppet → module_puppet} +30 -31
  54. data/ext/vim/filetype.vim +9 -0
  55. data/ext/vim/puppet.vim +87 -0
  56. data/install.rb +63 -30
  57. data/lib/puppet.rb +216 -122
  58. data/lib/puppet/client.rb +51 -416
  59. data/lib/puppet/client/ca.rb +17 -0
  60. data/lib/puppet/client/dipper.rb +78 -0
  61. data/lib/puppet/client/file.rb +20 -0
  62. data/lib/puppet/client/log.rb +17 -0
  63. data/lib/puppet/client/master.rb +246 -0
  64. data/lib/puppet/client/proxy.rb +27 -0
  65. data/lib/puppet/client/status.rb +7 -0
  66. data/lib/puppet/config.rb +563 -13
  67. data/lib/puppet/daemon.rb +50 -22
  68. data/lib/puppet/element.rb +4 -4
  69. data/lib/puppet/event-loop.rb +1 -0
  70. data/lib/puppet/event-loop/better-definers.rb +367 -0
  71. data/lib/puppet/event-loop/event-loop.rb +355 -0
  72. data/lib/puppet/event-loop/signal-system.rb +220 -0
  73. data/lib/puppet/event.rb +9 -11
  74. data/lib/puppet/filetype.rb +195 -0
  75. data/lib/puppet/log.rb +35 -12
  76. data/lib/puppet/metric.rb +2 -2
  77. data/lib/puppet/networkclient.rb +145 -0
  78. data/lib/puppet/parameter.rb +335 -0
  79. data/lib/puppet/parser/ast.rb +42 -1453
  80. data/lib/puppet/parser/ast/astarray.rb +88 -0
  81. data/lib/puppet/parser/ast/branch.rb +47 -0
  82. data/lib/puppet/parser/ast/caseopt.rb +66 -0
  83. data/lib/puppet/parser/ast/casestatement.rb +78 -0
  84. data/lib/puppet/parser/ast/classdef.rb +78 -0
  85. data/lib/puppet/parser/ast/compdef.rb +111 -0
  86. data/lib/puppet/parser/ast/component.rb +105 -0
  87. data/lib/puppet/parser/ast/hostclass.rb +82 -0
  88. data/lib/puppet/parser/ast/leaf.rb +86 -0
  89. data/lib/puppet/parser/ast/node.rb +103 -0
  90. data/lib/puppet/parser/ast/nodedef.rb +68 -0
  91. data/lib/puppet/parser/ast/objectdef.rb +336 -0
  92. data/lib/puppet/parser/ast/objectparam.rb +30 -0
  93. data/lib/puppet/parser/ast/objectref.rb +76 -0
  94. data/lib/puppet/parser/ast/selector.rb +60 -0
  95. data/lib/puppet/parser/ast/typedefaults.rb +45 -0
  96. data/lib/puppet/parser/ast/vardef.rb +44 -0
  97. data/lib/puppet/parser/interpreter.rb +31 -14
  98. data/lib/puppet/parser/lexer.rb +2 -4
  99. data/lib/puppet/parser/parser.rb +332 -242
  100. data/lib/puppet/parser/scope.rb +55 -38
  101. data/lib/puppet/server.rb +43 -44
  102. data/lib/puppet/server/authstore.rb +3 -6
  103. data/lib/puppet/server/ca.rb +5 -2
  104. data/lib/puppet/server/filebucket.rb +2 -4
  105. data/lib/puppet/server/fileserver.rb +28 -12
  106. data/lib/puppet/server/logger.rb +15 -4
  107. data/lib/puppet/server/master.rb +62 -7
  108. data/lib/puppet/sslcertificates.rb +41 -607
  109. data/lib/puppet/sslcertificates/ca.rb +291 -0
  110. data/lib/puppet/sslcertificates/certificate.rb +283 -0
  111. data/lib/puppet/statechange.rb +6 -1
  112. data/lib/puppet/storage.rb +67 -56
  113. data/lib/puppet/transaction.rb +25 -9
  114. data/lib/puppet/transportable.rb +102 -22
  115. data/lib/puppet/type.rb +1096 -315
  116. data/lib/puppet/type/component.rb +30 -21
  117. data/lib/puppet/type/cron.rb +409 -448
  118. data/lib/puppet/type/exec.rb +234 -174
  119. data/lib/puppet/type/group.rb +65 -82
  120. data/lib/puppet/type/nameservice.rb +247 -3
  121. data/lib/puppet/type/nameservice/netinfo.rb +29 -40
  122. data/lib/puppet/type/nameservice/objectadd.rb +52 -66
  123. data/lib/puppet/type/nameservice/posix.rb +6 -194
  124. data/lib/puppet/type/package.rb +447 -295
  125. data/lib/puppet/type/package/apt.rb +51 -50
  126. data/lib/puppet/type/package/bsd.rb +82 -0
  127. data/lib/puppet/type/package/dpkg.rb +85 -88
  128. data/lib/puppet/type/package/rpm.rb +67 -63
  129. data/lib/puppet/type/package/sun.rb +119 -98
  130. data/lib/puppet/type/package/yum.rb +41 -37
  131. data/lib/puppet/type/parsedtype.rb +295 -0
  132. data/lib/puppet/type/parsedtype/host.rb +143 -0
  133. data/lib/puppet/type/parsedtype/port.rb +232 -0
  134. data/lib/puppet/type/parsedtype/sshkey.rb +129 -0
  135. data/lib/puppet/type/pfile.rb +484 -460
  136. data/lib/puppet/type/pfile/checksum.rb +237 -181
  137. data/lib/puppet/type/pfile/content.rb +67 -0
  138. data/lib/puppet/type/pfile/ensure.rb +212 -0
  139. data/lib/puppet/type/pfile/group.rb +106 -105
  140. data/lib/puppet/type/pfile/mode.rb +98 -101
  141. data/lib/puppet/type/pfile/source.rb +228 -209
  142. data/lib/puppet/type/pfile/type.rb +18 -21
  143. data/lib/puppet/type/pfile/uid.rb +127 -130
  144. data/lib/puppet/type/pfilebucket.rb +68 -63
  145. data/lib/puppet/type/schedule.rb +341 -0
  146. data/lib/puppet/type/service.rb +351 -255
  147. data/lib/puppet/type/service/base.rb +9 -14
  148. data/lib/puppet/type/service/debian.rb +32 -38
  149. data/lib/puppet/type/service/init.rb +130 -130
  150. data/lib/puppet/type/service/smf.rb +48 -20
  151. data/lib/puppet/type/state.rb +229 -16
  152. data/lib/puppet/type/symlink.rb +51 -63
  153. data/lib/puppet/type/tidy.rb +105 -102
  154. data/lib/puppet/type/user.rb +118 -180
  155. data/lib/puppet/util.rb +100 -6
  156. data/test/certmgr/certmgr.rb +0 -1
  157. data/test/client/client.rb +4 -4
  158. data/test/executables/puppetbin.rb +7 -14
  159. data/test/executables/puppetca.rb +18 -24
  160. data/test/executables/puppetd.rb +7 -16
  161. data/test/executables/puppetmasterd.rb +7 -9
  162. data/test/executables/puppetmodule.rb +11 -16
  163. data/test/language/ast.rb +11 -7
  164. data/test/language/interpreter.rb +1 -1
  165. data/test/language/scope.rb +2 -0
  166. data/test/language/snippets.rb +30 -5
  167. data/test/language/transportable.rb +77 -0
  168. data/test/other/config.rb +316 -0
  169. data/test/other/events.rb +22 -21
  170. data/test/other/log.rb +14 -14
  171. data/test/other/metrics.rb +4 -8
  172. data/test/other/overrides.rb +5 -5
  173. data/test/other/relationships.rb +4 -2
  174. data/test/other/storage.rb +64 -3
  175. data/test/other/transactions.rb +20 -20
  176. data/test/parser/parser.rb +7 -4
  177. data/test/puppet/conffiles.rb +12 -12
  178. data/test/puppet/defaults.rb +13 -11
  179. data/test/puppet/utiltest.rb +14 -11
  180. data/test/puppettest.rb +156 -48
  181. data/test/server/bucket.rb +2 -2
  182. data/test/server/fileserver.rb +6 -6
  183. data/test/server/logger.rb +19 -11
  184. data/test/server/master.rb +33 -4
  185. data/test/server/server.rb +2 -7
  186. data/test/types/basic.rb +5 -7
  187. data/test/types/component.rb +22 -18
  188. data/test/types/cron.rb +111 -44
  189. data/test/types/exec.rb +116 -59
  190. data/test/types/file.rb +262 -137
  191. data/test/types/filebucket.rb +13 -15
  192. data/test/types/fileignoresource.rb +12 -16
  193. data/test/types/filesources.rb +73 -48
  194. data/test/types/filetype.rb +13 -15
  195. data/test/types/group.rb +15 -13
  196. data/test/types/host.rb +146 -0
  197. data/test/types/package.rb +74 -63
  198. data/test/types/port.rb +139 -0
  199. data/test/types/query.rb +8 -8
  200. data/test/types/schedule.rb +335 -0
  201. data/test/types/service.rb +137 -21
  202. data/test/types/sshkey.rb +140 -0
  203. data/test/types/symlink.rb +3 -5
  204. data/test/types/tidy.rb +5 -14
  205. data/test/types/type.rb +67 -11
  206. data/test/types/user.rb +25 -23
  207. metadata +186 -122
  208. data/lib/puppet/type/pfile/create.rb +0 -108
  209. data/lib/puppet/type/pprocess.rb +0 -97
  210. data/lib/puppet/type/typegen.rb +0 -149
  211. data/lib/puppet/type/typegen/filerecord.rb +0 -243
  212. data/lib/puppet/type/typegen/filetype.rb +0 -316
  213. data/test/other/state.rb +0 -106
@@ -0,0 +1,143 @@
1
+ require 'etc'
2
+ require 'facter'
3
+ require 'puppet/type/parsedtype'
4
+ require 'puppet/type/state'
5
+
6
+ module Puppet
7
+ newtype(:host, Puppet::Type::ParsedType) do
8
+ newstate(:ip) do
9
+ desc "The host's IP address."
10
+ end
11
+
12
+ newstate(:alias) do
13
+ desc "Any alias the host might have. Multiple values must be
14
+ specified as an array. Note that this state has the same name
15
+ as one of the metaparams; using this state to set aliases will
16
+ make those aliases available in your Puppet scripts and also on
17
+ disk."
18
+
19
+ # We have to override the feeding mechanism; it might be nil or
20
+ # white-space separated
21
+ def is=(value)
22
+ # If it's just whitespace, ignore it
23
+ case value
24
+ when /^\s+$/
25
+ @is = nil
26
+ when String
27
+ @is = value.split(/\s+/)
28
+ else
29
+ @is = value
30
+ end
31
+ end
32
+
33
+ # We actually want to return the whole array here, not just the first
34
+ # value.
35
+ def should
36
+ if defined? @should
37
+ return @should
38
+ else
39
+ return []
40
+ end
41
+ end
42
+
43
+ def should_to_s
44
+ @should.join(" ")
45
+ end
46
+
47
+ validate do |value|
48
+ if value =~ /\s/
49
+ raise Puppet::Error, "Aliases cannot include whitespace"
50
+ end
51
+ end
52
+
53
+ munge do |value|
54
+ # Add the :alias metaparam in addition to the state
55
+ @parent.newmetaparam(@parent.class.metaparamclass(:alias), value)
56
+ value
57
+ end
58
+ end
59
+
60
+ newparam(:name) do
61
+ desc "The host name."
62
+
63
+ isnamevar
64
+ end
65
+
66
+ @doc = "Installs and manages host entries. For most systems, these
67
+ entries will just be in /etc/hosts, but some systems (notably OS X)
68
+ will have different solutions."
69
+
70
+ @instances = []
71
+
72
+ @path = "/etc/hosts"
73
+ @fields = [:ip, :name, :alias]
74
+
75
+ @filetype = Puppet::FileType.filetype(:flat)
76
+ # case Facter["operatingsystem"].value
77
+ # when "Solaris":
78
+ # @filetype = Puppet::FileType::SunOS
79
+ # else
80
+ # @filetype = Puppet::CronType::Default
81
+ # end
82
+
83
+ # Parse a host file
84
+ #
85
+ # This method also stores existing comments, and it stores all host
86
+ # jobs in order, mostly so that comments are retained in the order
87
+ # they were written and in proximity to the same jobs.
88
+ def self.parse(text)
89
+ count = 0
90
+ hash = {}
91
+ text.chomp.split("\n").each { |line|
92
+ case line
93
+ when /^#/, /^\s*$/:
94
+ # add comments and blank lines to the list as they are
95
+ @instances << line
96
+ else
97
+ if line.sub!(/^(\S+)\s+(\S+)\s*/, '')
98
+ hash[:ip] = $1
99
+ hash[:name] = $2
100
+
101
+ unless line == ""
102
+ line.sub!(/\s*/, '')
103
+ line.sub!(/^([^#]+)\s*/) do |value|
104
+ aliases = $1
105
+ unless aliases =~ /^\s*$/
106
+ hash[:alias] = aliases
107
+ end
108
+
109
+ ""
110
+ end
111
+ end
112
+ else
113
+ raise Puppet::Error, "Could not match '%s'" % line
114
+ end
115
+
116
+ if hash[:alias] == ""
117
+ hash.delete(:alias)
118
+ end
119
+
120
+ Puppet.notice "sending %s" % hash.inspect
121
+
122
+ hash2obj(hash)
123
+
124
+ hash.clear
125
+ count += 1
126
+ end
127
+ }
128
+ end
129
+
130
+ # Convert the current object into a host-style string.
131
+ def to_record
132
+ str = "%s\t%s" % [self.state(:ip).should, self[:name]]
133
+
134
+ if state = self.state(:alias)
135
+ str += "\t%s" % state.should.join("\t")
136
+ end
137
+
138
+ str
139
+ end
140
+ end
141
+ end
142
+
143
+ # $Id: host.rb 831 2006-01-16 20:01:20Z luke $
@@ -0,0 +1,232 @@
1
+ require 'etc'
2
+ require 'facter'
3
+ require 'puppet/type/parsedtype'
4
+ require 'puppet/type/state'
5
+
6
+ module Puppet
7
+ newtype(:port, Puppet::Type::ParsedType) do
8
+ newstate(:protocols) do
9
+ desc "The protocols the port uses. Valid values are *udp* and *tcp*.
10
+ Most services have both protocols, but not all. If you want
11
+ both protocols, you must specify that; Puppet replaces the
12
+ current values, it does not merge with them. If you specify
13
+ multiple protocols they must be as an array."
14
+
15
+ def is=(value)
16
+ case value
17
+ when String
18
+ @is = value.split(/\s+/)
19
+ else
20
+ @is = value
21
+ end
22
+ end
23
+
24
+ def is
25
+ @is
26
+ end
27
+
28
+ # We actually want to return the whole array here, not just the first
29
+ # value.
30
+ def should
31
+ @should
32
+ end
33
+
34
+ validate do |value|
35
+ unless value == "udp" or value == "tcp"
36
+ raise Puppet::Error, "Protocols can be either 'udp' or 'tcp'"
37
+ end
38
+ end
39
+ end
40
+
41
+ newstate(:number) do
42
+ desc "The port number."
43
+ end
44
+
45
+ newstate(:description) do
46
+ desc "The port description."
47
+ end
48
+
49
+ newstate(:alias) do
50
+ desc "Any aliases the port might have. Multiple values must be specified
51
+ as an array. Note that this state has the same name as one of the
52
+ metaparams; using this state to set aliases will make those aliases
53
+ available in your Puppet scripts and also on disk."
54
+
55
+ # We have to override the feeding mechanism; it might be nil or
56
+ # white-space separated
57
+ def is=(value)
58
+ # If it's just whitespace, ignore it
59
+ case value
60
+ when /^\s+$/
61
+ @is = nil
62
+ when String
63
+ @is = value.split(/\s+/)
64
+ when Symbol
65
+ @is = value
66
+ else
67
+ raise Puppet::DevError, "Invalid value %s" % value.inspect
68
+ end
69
+ end
70
+
71
+ # We actually want to return the whole array here, not just the first
72
+ # value.
73
+ def should
74
+ @should
75
+ end
76
+
77
+ validate do |value|
78
+ if value =~ /\s/
79
+ raise Puppet::Error, "Aliases cannot have whitespace in them"
80
+ end
81
+ end
82
+
83
+ munge do |value|
84
+ # Add the :alias metaparam in addition to the state
85
+ @parent.newmetaparam(@parent.class.metaparamclass(:alias), value)
86
+ value
87
+ end
88
+ end
89
+
90
+ newparam(:name) do
91
+ desc "The port name."
92
+
93
+ isnamevar
94
+ end
95
+
96
+ @doc = "Installs and manages port entries. For most systems, these
97
+ entries will just be in /etc/services, but some systems (notably OS X)
98
+ will have different solutions."
99
+
100
+ @path = "/etc/services"
101
+ @fields = [:ip, :name, :alias]
102
+
103
+ @filetype = Puppet::FileType.filetype(:flat)
104
+ # case Facter["operatingsystem"].value
105
+ # when "Solaris":
106
+ # @filetype = Puppet::FileType::SunOS
107
+ # else
108
+ # @filetype = Puppet::CronType::Default
109
+ # end
110
+
111
+ # Parse a services file
112
+ #
113
+ # This method also stores existing comments, and it stores all host
114
+ # jobs in order, mostly so that comments are retained in the order
115
+ # they were written and in proximity to the same jobs.
116
+ def self.parse(text)
117
+ count = 0
118
+ hash = {}
119
+ text.chomp.split("\n").each { |line|
120
+ case line
121
+ when /^#/, /^\s*$/:
122
+ # add comments and blank lines to the list as they are
123
+ @instances << line
124
+ else
125
+ #if match = /^(\S+)\s+(\d+)\/(\w+)/.match(line)
126
+ # Puppet.warning "%s %s %s" % [$1, $2, $3]
127
+ # next
128
+ #if line.sub(/^(\S+)\s+(\d+)\/(\w+)\s*(\S*)$/.match(line)
129
+ if line.sub!(/^(\S+)\s+(\d+)\/(\w+)\s*/, '')
130
+ hash[:name] = $1
131
+ hash[:number] = $2
132
+ hash[:protocols] = $3
133
+
134
+ unless line == ""
135
+ line.sub!(/^([^#]+)\s*/) do |value|
136
+ aliases = $1
137
+ unless aliases =~ /^\s*$/
138
+ hash[:alias] = aliases
139
+ end
140
+
141
+ ""
142
+ end
143
+
144
+ line.sub!(/^\s*#\s*(.+)$/) do |value|
145
+ desc = $1
146
+ unless desc =~ /^\s*$/
147
+ hash[:description] = desc.sub(/\s*$/, '')
148
+ end
149
+
150
+ ""
151
+ end
152
+ end
153
+ else
154
+ raise Puppet::Error, "Could not match '%s'" % line
155
+ end
156
+
157
+ # If there's already a service with this name, then check
158
+ # to see if the only difference is the proto; if so, just
159
+ # add our proto and walk away
160
+ if obj = self[hash[:name]]
161
+ if obj.portmerge(hash)
162
+ next
163
+ end
164
+ end
165
+
166
+ hash2obj(hash)
167
+
168
+ hash.clear
169
+ count += 1
170
+ end
171
+ }
172
+ end
173
+
174
+ def portmerge(hash)
175
+ unless @states.include?(:protocols)
176
+ return false
177
+ end
178
+ proto = self.state(:protocols).is
179
+
180
+ if proto.nil? or proto == :absent
181
+ # We are an unitialized object; we've got 'should'
182
+ # values but no 'is' values
183
+ return false
184
+ end
185
+
186
+ if hash[:protocols]
187
+ # The protocol can be a symbol, so...
188
+ if proto.is_a?(Symbol)
189
+ proto = []
190
+ end
191
+ # Check to see if it already includes our proto
192
+ unless proto.include?(hash[:protocols])
193
+ # We are missing their proto
194
+ proto << hash[:protocols]
195
+ #Puppet.info "new proto is %s" % proto.inspect
196
+ @states[:protocols].is = proto
197
+ #Puppet.info "new value is %s" % @states[:protocols].is.inspect
198
+ end
199
+ end
200
+
201
+ if hash.include?(:description) and ! @states.include?(:description)
202
+ Puppet.info "Adding description to %s" % hash[:name]
203
+ self.is = [:description, hash[:description]]
204
+ end
205
+
206
+ return true
207
+ end
208
+
209
+ # Convert the current object into a host-style string.
210
+ def to_record
211
+ self.state(:protocols).should.collect { |proto|
212
+ str = "%s\t%s/%s" % [self[:name], self.state(:number).should,
213
+ proto]
214
+
215
+ if state = self.state(:alias)
216
+ str += "\t%s" % state.should.join(" ")
217
+ else
218
+ str += "\t"
219
+ end
220
+
221
+ if state = self.state(:description)
222
+ str += "\t# %s" % state.should
223
+ else
224
+ str += "\t"
225
+ end
226
+ str
227
+ }.join("\n")
228
+ end
229
+ end
230
+ end
231
+
232
+ # $Id: port.rb 831 2006-01-16 20:01:20Z luke $
@@ -0,0 +1,129 @@
1
+ require 'etc'
2
+ require 'facter'
3
+ require 'puppet/type/parsedtype'
4
+ require 'puppet/type/state'
5
+
6
+ module Puppet
7
+ newtype(:sshkey, Puppet::Type::ParsedType) do
8
+ isaggregatable
9
+
10
+ newstate(:type) do
11
+ desc "The encryption type used. Probably ssh-dss or ssh-rsa."
12
+ end
13
+
14
+ newstate(:key) do
15
+ desc "The key itself; generally a long string of hex digits."
16
+ end
17
+
18
+ # FIXME This should automagically check for aliases to the hosts, just
19
+ # to see if we can automatically glean any aliases.
20
+ newstate(:alias) do
21
+ desc "Any alias the host might have. Multiple values must be
22
+ specified as an array. Note that this state has the same name
23
+ as one of the metaparams; using this state to set aliases will
24
+ make those aliases available in your Puppet scripts and also on
25
+ disk."
26
+
27
+ # We actually want to return the whole array here, not just the first
28
+ # value.
29
+ def should
30
+ @should
31
+ end
32
+
33
+ validate do |value|
34
+ if value =~ /\s/
35
+ raise Puppet::Error, "Aliases cannot include whitespace"
36
+ end
37
+ if value =~ /,/
38
+ raise Puppet::Error, "Aliases cannot include whitespace"
39
+ end
40
+ end
41
+
42
+ # Make a puppet alias in addition.
43
+ munge do |value|
44
+ # Add the :alias metaparam in addition to the state
45
+ @parent.newmetaparam(@parent.class.metaparamclass(:alias), value)
46
+ value
47
+ end
48
+ end
49
+
50
+ newparam(:name) do
51
+ desc "The host name."
52
+
53
+ isnamevar
54
+ end
55
+
56
+ @doc = "Installs and manages host entries. For most systems, these
57
+ entries will just be in /etc/hosts, but some systems (notably OS X)
58
+ will have different solutions."
59
+
60
+ @instances = []
61
+
62
+ @path = "/etc/ssh/ssh_known_hosts"
63
+ @fields = [:name, :type, :key]
64
+
65
+ @filetype = Puppet::FileType.filetype(:flat)
66
+ # case Facter["operatingsystem"].value
67
+ # when "Solaris":
68
+ # @filetype = Puppet::FileType::SunOS
69
+ # else
70
+ # @filetype = Puppet::CronType::Default
71
+ # end
72
+
73
+ # Parse a host file
74
+ #
75
+ # This method also stores existing comments, and it stores all host
76
+ # jobs in order, mostly so that comments are retained in the order
77
+ # they were written and in proximity to the same jobs.
78
+ def self.parse(text)
79
+ count = 0
80
+ hash = {}
81
+ text.chomp.split("\n").each { |line|
82
+ case line
83
+ when /^#/, /^\s*$/:
84
+ # add comments and blank lines to the list as they are
85
+ @instances << line
86
+ else
87
+ hash = {}
88
+ fields().zip(line.split(" ")).each { |param, value|
89
+ hash[param] = value
90
+ }
91
+
92
+ if hash[:name] =~ /,/
93
+ names = hash[:name].split(",")
94
+ hash[:name] = names.shift
95
+ hash[:alias] = names
96
+ end
97
+
98
+ #if match = /^(\S+)\s+(\S+)\s*(\S*)$/.match(line)
99
+ # fields().zip(match.captures).each { |param, value|
100
+ # hash[param] = value
101
+ # }
102
+ #else
103
+ # raise Puppet::Error, "Could not match '%s'" % line
104
+ #end
105
+
106
+ if hash[:alias] == ""
107
+ hash.delete(:alias)
108
+ end
109
+
110
+ hash2obj(hash)
111
+
112
+ hash.clear
113
+ count += 1
114
+ end
115
+ }
116
+ end
117
+
118
+ # Convert the current object into a host-style string.
119
+ def to_record
120
+ name = self[:name]
121
+ if @states.include?(:alias)
122
+ name += "," + @states[:alias].should.join(",")
123
+ end
124
+ [name, @states[:type].should, @states[:key].should].join(" ")
125
+ end
126
+ end
127
+ end
128
+
129
+ # $Id: sshkey.rb 831 2006-01-16 20:01:20Z luke $