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
|
# File 'lib/puppet/application/script.rb', line 130
def main
Puppet[:tasks] = true
if options[:code] || command_line.args.length == 0
Puppet[:code] = options[:code] || STDIN.read
else
manifest = command_line.args.shift
raise _("Could not find file %{manifest}") % { manifest: manifest } unless Puppet::FileSystem.exist?(manifest)
Puppet.warning(_("Only one file can be used per run. Skipping %{files}") % { files: command_line.args.join(', ') }) if command_line.args.size > 0
end
unless Puppet[:node_name_fact].empty?
facts = Puppet::Node::Facts.indirection.find(Puppet[:node_name_value])
raise _("Could not find facts for %{node}") % { node: Puppet[:node_name_value] } unless facts
Puppet[:node_name_value] = facts.values[Puppet[:node_name_fact]]
facts.name = Puppet[:node_name_value]
end
node = Puppet::Node.indirection.find(Puppet[:node_name_value])
raise _("Could not find node %{node}") % { node: Puppet[:node_name_value] } unless node
configured_environment = node.environment || Puppet.lookup(:current_environment)
apply_environment = manifest ?
configured_environment.override_with(:manifest => manifest) :
configured_environment
node.environment = apply_environment
Puppet.override({:current_environment => apply_environment}, "For puppet script") do
node.merge(facts.values) if facts
node.add_server_facts({})
begin
begin
node.sanitize()
compiler = Puppet::Parser::ScriptCompiler.new(node.environment, node.name)
topscope = compiler.topscope
topscope.set_trusted(node.trusted_data)
topscope.set_server_facts(node.server_facts)
facts_hash = node.facts.nil? ? {} : node.facts.values
topscope.set_facts(facts_hash)
topscope.merge_settings(node.environment.name, false)
compiler.compile()
rescue Puppet::Error
exit(1)
end
exit(0)
rescue => detail
Puppet.log_exception(detail)
exit(1)
end
end
ensure
if @profiler
Puppet::Util::Profiler.remove_profiler(@profiler)
@profiler.shutdown
end
end
|