Class: Puppet::Application::Agent
Constant Summary
DOCPATTERN
Constants included
from Util
Util::ALNUM, Util::ALPHA, Util::AbsolutePathPosix, Util::AbsolutePathWindows, Util::DEFAULT_POSIX_MODE, Util::DEFAULT_WINDOWS_MODE, Util::ESCAPED, Util::HEX, Util::HttpProxy, Util::PUPPET_STACK_INSERTION_FRAME, Util::RESERVED, Util::RFC_3986_URI_REGEX, Util::UNRESERVED, Util::UNSAFE
Constants included
from Util::POSIX
Util::POSIX::LOCALE_ENV_VARS, Util::POSIX::USER_ENV_VARS
Util::SymbolicFileMode::SetGIDBit, Util::SymbolicFileMode::SetUIDBit, Util::SymbolicFileMode::StickyBit, Util::SymbolicFileMode::SymbolicMode, Util::SymbolicFileMode::SymbolicSpecialToBit
Instance Attribute Summary
#command_line, #options
Instance Method Summary
collapse
[], available_application_names, banner, clear!, clear?, clear_everything_for_tests, #configure_indirector_routes, controlled_run, #deprecate, #deprecated?, environment_mode, exit, find, get_environment_mode, #handle_logdest_arg, #handlearg, #initialize, #initialize_app_defaults, interrupted?, #log_runtime_environment, #name, option, option_parser_commands, #parse_options, restart!, restart_requested?, #run, run_mode, #set_log_level, #setup_logs, stop!, stop_requested?, try_load_class
Methods included from Util
absolute_path?, benchmark, chuser, clear_environment, create_erb, default_env, deterministic_rand, deterministic_rand_int, exit_on_fail, format_backtrace_array, format_puppetstack_frame, get_env, get_environment, logmethods, merge_environment, path_to_uri, pretty_backtrace, replace_file, resolve_stackframe, rfc2396_escape, safe_posix_fork, set_env, skip_external_facts, symbolizehash, thinmark, uri_encode, uri_query_encode, uri_to_path, uri_unescape, which, withenv, withumask
#get_posix_field, #gid, groups_of, #idfield, #methodbyid, #methodbyname, #search_posix_field, #uid
#display_mode, #normalize_symbolic_mode, #symbolic_mode_to_int, #valid_symbolic_mode?
Instance Method Details
#app_defaults ⇒ Object
13
14
15
16
17
18
19
20
|
# File 'lib/puppet/application/agent.rb', line 13
def app_defaults
super.merge({
:catalog_terminus => :rest,
:catalog_cache_terminus => :json,
:node_terminus => :rest,
:facts_terminus => :facter,
})
end
|
#fingerprint ⇒ Object
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
|
# File 'lib/puppet/application/agent.rb', line 415
def fingerprint
Puppet::Util::Log.newdestination(:console)
cert_provider = Puppet::X509::CertProvider.new
client_cert = cert_provider.load_client_cert(Puppet[:certname])
if client_cert
puts Puppet::SSL::Digest.new(options[:digest].to_s, client_cert.to_der).to_s
else
csr = cert_provider.load_request(Puppet[:certname])
if csr
puts Puppet::SSL::Digest.new(options[:digest].to_s, csr.to_der).to_s
else
$stderr.puts _("Fingerprint asked but neither the certificate, nor the certificate request have been issued")
exit(1)
end
end
rescue => e
Puppet.log_exception(e, _("Failed to generate fingerprint: %{message}") % { message: e.message })
exit(1)
end
|
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
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
|
# File 'lib/puppet/application/agent.rb', line 87
def help
"\n puppet-agent(8) -- \#{summary}\n ========\n\n SYNOPSIS\n --------\n Retrieves the client configuration from the OpenVox server and applies it to\n the local host.\n\n This service may be run as a daemon, run periodically using cron (or something\n similar), or run interactively for testing purposes.\n\n\n USAGE\n -----\n puppet agent [--certname <NAME>] [-D|--daemonize|--no-daemonize]\n [-d|--debug] [--detailed-exitcodes] [--digest <DIGEST>] [--disable [MESSAGE]] [--enable]\n [--fingerprint] [-h|--help] [-l|--logdest syslog|eventlog|<ABS FILEPATH>|console]\n [--serverport <PORT>] [--noop] [-o|--onetime] [--sourceaddress <IP_ADDRESS>] [-t|--test]\n [-v|--verbose] [-V|--version] [-w|--waitforcert <SECONDS>]\n\n\n DESCRIPTION\n -----------\n This is the main puppet client. Its job is to retrieve the local\n machine's configuration from a remote server and apply it. In order to\n successfully communicate with the remote server, the client must have a\n certificate signed by a certificate authority that the server trusts;\n the recommended method for this, at the moment, is to run a certificate\n authority as part of the puppet server (which is the default). The\n client will connect and request a signed certificate, and will continue\n connecting until it receives one.\n\n Once the client has a signed certificate, it will retrieve its\n configuration and apply it.\n\n\n USAGE NOTES\n -----------\n 'puppet agent' does its best to find a compromise between interactive\n use and daemon use. If you run it with no arguments and no configuration, it\n goes into the background, attempts to get a signed certificate, and retrieves\n and applies its configuration every 30 minutes.\n\n Some flags are meant specifically for interactive use --- in particular,\n 'test', 'tags' and 'fingerprint' are useful.\n\n '--test' runs once in the foreground with verbose logging, then exits.\n It also exits if it can't get a valid catalog. `--test` includes the\n '--detailed-exitcodes' option by default and exits with one of the following\n exit codes:\n\n * 0: The run succeeded with no changes or failures; the system was already in\n the desired state.\n * 1: The run failed, or wasn't attempted due to another run already in progress.\n * 2: The run succeeded, and some resources were changed.\n * 4: The run succeeded, and some resources failed.\n * 6: The run succeeded, and included both changes and failures.\n\n '--tags' allows you to specify what portions of a configuration you want\n to apply. Puppet elements are tagged with all of the class or definition\n names that contain them, and you can use the 'tags' flag to specify one\n of these names, causing only configuration elements contained within\n that class or definition to be applied. This is very useful when you are\n testing new configurations --- for instance, if you are just starting to\n manage 'ntpd', you would put all of the new elements into an 'ntpd'\n class, and call puppet with '--tags ntpd', which would only apply that\n small portion of the configuration during your testing, rather than\n applying the whole thing.\n\n '--fingerprint' is a one-time flag. In this mode 'puppet agent' runs\n once and displays on the console (and in the log) the current certificate\n (or certificate request) fingerprint. Providing the '--digest' option\n allows you to use a different digest algorithm to generate the fingerprint.\n The main use is to verify that before signing a certificate request on\n the master, the certificate request the master received is the same as\n the one the client sent (to prevent against man-in-the-middle attacks\n when signing certificates).\n\n '--skip_tags' is a flag used to filter resources. If this is set, then\n only resources not tagged with the specified tags will be applied.\n Values must be comma-separated.\n\n\n OPTIONS\n -------\n\n Note that any Puppet setting that's valid in the configuration file is also a\n valid long argument. For example, 'server' is a valid setting, so you can\n specify '--server <servername>' as an argument. Boolean settings accept a '--no-'\n prefix to turn off a behavior, translating into '--setting' and '--no-setting'\n pairs, such as `--daemonize` and `--no-daemonize`.\n\n See the configuration file documentation at\n https://puppet.com/docs/puppet/latest/configuration.html for the\n full list of acceptable settings. A commented list of all settings can also be\n generated by running puppet agent with '--genconfig'.\n\n * --certname:\n Set the certname (unique ID) of the client. The master reads this\n unique identifying string, which is usually set to the node's\n fully-qualified domain name, to determine which configurations the\n node will receive. Use this option to debug setup problems or\n implement unusual node identification schemes.\n (This is a Puppet setting, and can go in puppet.conf.)\n\n * --daemonize:\n Send the process into the background. This is the default.\n (This is a Puppet setting, and can go in puppet.conf. Note the special 'no-'\n prefix for boolean settings on the command line.)\n\n * --no-daemonize:\n Do not send the process into the background.\n (This is a Puppet setting, and can go in puppet.conf. Note the special 'no-'\n prefix for boolean settings on the command line.)\n\n * --debug:\n Enable full debugging.\n\n * --detailed-exitcodes:\n Provide extra information about the run via exit codes; works only if '--test'\n or '--onetime' is also specified. If enabled, 'puppet agent' uses the\n following exit codes:\n\n 0: The run succeeded with no changes or failures; the system was already in\n the desired state.\n\n 1: The run failed, or wasn't attempted due to another run already in progress.\n\n 2: The run succeeded, and some resources were changed.\n\n 4: The run succeeded, and some resources failed.\n\n 6: The run succeeded, and included both changes and failures.\n\n * --digest:\n Change the certificate fingerprinting digest algorithm. The default is\n SHA256. Valid values depends on the version of OpenSSL installed, but\n will likely contain MD5, MD2, SHA1 and SHA256.\n\n * --disable:\n Disable working on the local system. This puts a lock file in place,\n causing 'puppet agent' not to work on the system until the lock file\n is removed. This is useful if you are testing a configuration and do\n not want the central configuration to override the local state until\n everything is tested and committed.\n\n Disable can also take an optional message that will be reported by the\n 'puppet agent' at the next disabled run.\n\n 'puppet agent' uses the same lock file while it is running, so no more\n than one 'puppet agent' process is working at a time.\n\n 'puppet agent' exits after executing this.\n\n * --enable:\n Enable working on the local system. This removes any lock file,\n causing 'puppet agent' to start managing the local system again\n However, it continues to use its normal scheduling, so it might\n not start for another half hour.\n\n 'puppet agent' exits after executing this.\n\n * --evaltrace:\n Logs each resource as it is being evaluated. This allows you to interactively\n see exactly what is being done. (This is a Puppet setting, and can go in\n puppet.conf. Note the special 'no-' prefix for boolean settings on the command line.)\n\n * --fingerprint:\n Display the current certificate or certificate signing request\n fingerprint and then exit. Use the '--digest' option to change the\n digest algorithm used.\n\n * --help:\n Print this help message\n\n * --job-id:\n Attach the specified job id to the catalog request and the report used for\n this agent run. This option only works when '--onetime' is used. When using\n Puppet Enterprise this flag should not be used as the orchestrator sets the\n job-id for you and it must be unique.\n\n * --logdest:\n Where to send log messages. Choose between 'syslog' (the POSIX syslog\n service), 'eventlog' (the Windows Event Log), 'console', or the path to a log\n file. If debugging or verbosity is enabled, this defaults to 'console'.\n Otherwise, it defaults to 'syslog' on POSIX systems and 'eventlog' on Windows.\n Multiple destinations can be set using a comma separated list\n (eg: `/path/file1,console,/path/file2`)\"\n\n A path ending with '.json' will receive structured output in JSON format. The\n log file will not have an ending ']' automatically written to it due to the\n appending nature of logging. It must be appended manually to make the content\n valid JSON.\n\n A path ending with '.jsonl' will receive structured output in JSON Lines\n format.\n\n * --masterport:\n The port on which to contact the Puppet Server.\n (This is a Puppet setting, and can go in puppet.conf.\n Deprecated in favor of the 'serverport' setting.)\n\n * --noop:\n Use 'noop' mode where the daemon runs in a no-op or dry-run mode. This\n is useful for seeing what changes Puppet would make without actually\n executing the changes.\n (This is a Puppet setting, and can go in puppet.conf. Note the special 'no-'\n prefix for boolean settings on the command line.)\n\n * --onetime:\n Run the configuration once. Runs a single (normally daemonized) Puppet\n run. Useful for interactively running puppet agent when used in\n conjunction with the --no-daemonize option.\n (This is a Puppet setting, and can go in puppet.conf. Note the special 'no-'\n prefix for boolean settings on the command line.)\n\n * --serverport:\n The port on which to contact the Puppet Server.\n (This is a Puppet setting, and can go in puppet.conf.)\n\n * --sourceaddress:\n Set the source IP address for transactions. This defaults to automatically selected.\n (This is a Puppet setting, and can go in puppet.conf.)\n\n * --test:\n Enable the most common options used for testing. These are 'onetime',\n 'verbose', 'no-daemonize', 'no-usecacheonfailure', 'detailed-exitcodes',\n 'no-splay', and 'show_diff'.\n\n * --trace\n Prints stack traces on some errors. (This is a Puppet setting, and can go in\n puppet.conf. Note the special 'no-' prefix for boolean settings on the command line.)\n\n * --verbose:\n Turn on verbose reporting.\n\n * --version:\n Print the puppet version number and exit.\n\n * --waitforcert:\n This option only matters for daemons that do not yet have certificates\n and it is enabled by default, with a value of 120 (seconds). This\n causes 'puppet agent' to connect to the server every 2 minutes and ask\n it to sign a certificate request. This is useful for the initial setup\n of a puppet client. You can turn off waiting for certificates by\n specifying a time of 0.\n (This is a Puppet setting, and can go in puppet.conf.)\n\n * --write_catalog_summary\n After compiling the catalog saves the resource list and classes list to the node\n in the state directory named classes.txt and resources.txt\n (This is a Puppet setting, and can go in puppet.conf.)\n\n EXAMPLE\n -------\n $ puppet agent --server puppet.domain.com\n\n\n DIAGNOSTICS\n -----------\n\n Puppet agent accepts the following signals:\n\n * SIGHUP:\n Restart the puppet agent daemon.\n * SIGINT and SIGTERM:\n Shut down the puppet agent daemon.\n * SIGUSR1:\n Immediately retrieve and apply configurations from the puppet master.\n * SIGUSR2:\n Close file descriptors for log files and reopen them. Used with logrotate.\n\n AUTHOR\n ------\n Luke Kanies\n\n\n COPYRIGHT\n ---------\n Copyright (c) 2011 Puppet Inc.\n Copyright (c) 2024 Vox Pupuli\n Licensed under the Apache 2.0 License\n\n HELP\nend\n"
|
#log_config ⇒ Object
404
405
406
407
408
409
410
411
412
413
|
# File 'lib/puppet/application/agent.rb', line 404
def log_config
return unless Puppet::Util::Log.sendlevel?(:debug)
Puppet.settings.stringify_settings(:agent, :all).each_pair do |k, v|
next if k.include?("password") || v.to_s.empty?
Puppet.debug("Using setting: #{k}=#{v}")
end
end
|
#main(daemon) ⇒ Object
453
454
455
456
|
# File 'lib/puppet/application/agent.rb', line 453
def main(daemon)
Puppet.notice _("Starting Puppet client version %{version}") % { version: Puppet.version }
daemon.start
end
|
#onetime(daemon) ⇒ Object
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
|
# File 'lib/puppet/application/agent.rb', line 435
def onetime(daemon)
begin
exitstatus = daemon.agent.run({ :job_id => options[:job_id], :start_time => options[:start_time], :waitforcert => options[:waitforcert] })
rescue => detail
Puppet.log_exception(detail)
end
daemon.stop(:exit => false)
if !exitstatus
exit(1)
elsif options[:detailed_exitcodes] then
exit(exitstatus)
else
exit(0)
end
end
|
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
|
# File 'lib/puppet/application/agent.rb', line 22
def preinit
Signal.trap(:INT) do
$stderr.puts _("Cancelling startup")
exit(0)
end
{
:waitforcert => nil,
:detailed_exitcodes => false,
:verbose => false,
:debug => false,
:setdest => false,
:enable => false,
:disable => false,
:fqdn => nil,
:serve => [],
:digest => 'SHA256',
:graph => true,
:fingerprint => false,
:sourceaddress => nil,
:start_time => Time.now,
}.each do |opt, val|
options[opt] = val
end
@argv = ARGV.dup
end
|
#run_command ⇒ Object
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
|
# File 'lib/puppet/application/agent.rb', line 376
def run_command
if options[:fingerprint]
fingerprint
else
daemon = daemonize_process_when(Puppet[:daemonize])
daemon.set_signal_traps
log_config if Puppet[:daemonize]
env = Puppet.lookup(:current_environment)
Puppet.override(current_environment: env,
loaders: Puppet::Pops::Loaders.new(env, true)) do
if Puppet[:onetime]
onetime(daemon)
else
main(daemon)
end
end
end
end
|
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
|
# File 'lib/puppet/application/agent.rb', line 469
def setup
raise ArgumentError, _("The puppet agent command does not take parameters") unless command_line.args.empty?
setup_test if options[:test]
setup_logs
exit(Puppet.settings.print_configs ? 0 : 1) if Puppet.settings.print_configs?
Puppet::SSL::Oids.register_puppet_oids
if options[:fqdn]
Puppet[:certname] = options[:fqdn]
end
Puppet.settings.use :main, :agent, :ssl
Puppet::Transaction::Report.indirection.terminus_class = :rest
Puppet::Transaction::Report.indirection.cache_class = :yaml
if Puppet[:catalog_cache_terminus]
Puppet::Resource::Catalog.indirection.cache_class = Puppet[:catalog_cache_terminus]
end
unless options[:fingerprint]
setup_agent
end
end
|
#setup_test ⇒ Object
Enable all of the most common test options.
459
460
461
462
463
464
465
466
467
|
# File 'lib/puppet/application/agent.rb', line 459
def setup_test
Puppet.settings.handlearg("--no-usecacheonfailure")
Puppet.settings.handlearg("--no-splay")
Puppet.settings.handlearg("--show_diff")
Puppet.settings.handlearg("--no-daemonize")
options[:verbose] = true
Puppet[:onetime] = true
options[:detailed_exitcodes] = true
end
|
83
84
85
|
# File 'lib/puppet/application/agent.rb', line 83
def summary
_("The puppet agent daemon provided by OpenVox")
end
|