1
1
require 'puppet/application'
2
+ require 'puppet/configurer'
2
3
require 'puppet/util/network_device'
3
4
4
5
class Puppet ::Application ::Device < Puppet ::Application
@@ -53,6 +54,10 @@ def preinit
53
54
options [ :detailed_exitcodes ] = true
54
55
end
55
56
57
+ option ( "--libdir LIBDIR" ) do |arg |
58
+ options [ :libdir ] = arg
59
+ end
60
+
56
61
option ( "--apply MANIFEST" ) do |arg |
57
62
options [ :apply ] = arg . to_s
58
63
end
@@ -93,10 +98,11 @@ def help
93
98
94
99
USAGE
95
100
-----
96
- puppet device [-d|--debug] [--detailed-exitcodes] [--deviceconfig <file>]
97
- [-h|--help] [-l|--logdest syslog|<file>|console]
98
- [-v|--verbose] [-w|--waitforcert <seconds>] [-f|--facts]
99
- [-a|--apply <file>] [-r|--resource <type> [name]]
101
+ puppet device [-h|--help] [-v|--verbose] [-d|--debug]
102
+ [-l|--logdest syslog|<file>|console] [--detailed-exitcodes]
103
+ [--deviceconfig <file>] [-w|--waitforcert <seconds>]
104
+ [--libdir <directory>]
105
+ [-a|--apply <file>] [-f|--facts] [-r|--resource <type> [name]]
100
106
[-t|--target <device>] [--user=<user>] [-V|--version]
101
107
102
108
@@ -135,9 +141,25 @@ def help
135
141
long argument. For example, 'server' is a valid configuration parameter, so
136
142
you can specify '--server <servername>' as an argument.
137
143
138
- * --debug:
144
+ * --help, -h:
145
+ Print this help message
146
+
147
+ * --verbose, -v:
148
+ Turn on verbose reporting.
149
+
150
+ * --debug, -d:
139
151
Enable full debugging.
140
152
153
+ * --logdest, -l:
154
+ Where to send log messages. Choose between 'syslog' (the POSIX syslog
155
+ service), 'console', or the path to a log file. If debugging or verbosity is
156
+ enabled, this defaults to 'console'. Otherwise, it defaults to 'syslog'.
157
+
158
+ A path ending with '.json' will receive structured output in JSON format. The
159
+ log file will not have an ending ']' automatically written to it due to the
160
+ appending nature of logging. It must be appended manually to make the content
161
+ valid JSON.
162
+
141
163
* --detailed-exitcodes:
142
164
Provide transaction information via exit codes. If this is enabled, an exit
143
165
code of '1' means at least one device had a compile failure, an exit code of
@@ -149,18 +171,16 @@ def help
149
171
Path to the device config file for puppet device.
150
172
Default: $confdir/device.conf
151
173
152
- * --help:
153
- Print this help message
174
+ * --waitforcert, -w:
175
+ This option only matters for targets that do not yet have certificates
176
+ and it is enabled by default, with a value of 120 (seconds). This causes
177
+ +puppet device+ to poll the server every 2 minutes and ask it to sign a
178
+ certificate request. This is useful for the initial setup of a target.
179
+ You can turn off waiting for certificates by specifying a time of 0.
154
180
155
- * --logdest:
156
- Where to send log messages. Choose between 'syslog' (the POSIX syslog
157
- service), 'console', or the path to a log file. If debugging or verbosity is
158
- enabled, this defaults to 'console'. Otherwise, it defaults to 'syslog'.
159
-
160
- A path ending with '.json' will receive structured output in JSON format. The
161
- log file will not have an ending ']' automatically written to it due to the
162
- appending nature of logging. It must be appended manually to make the content
163
- valid JSON.
181
+ * --libdir:
182
+ Override the per-device libdir with a local directory. Specifying a libdir also
183
+ disables pluginsync. This is useful for testing.
164
184
165
185
* --apply:
166
186
Apply a manifest against a remote target. Target must be specified.
@@ -183,16 +203,6 @@ def help
183
203
* --user:
184
204
The user to run as.
185
205
186
- * --verbose:
187
- Turn on verbose reporting.
188
-
189
- * --waitforcert:
190
- This option only matters for daemons that do not yet have certificates
191
- and it is enabled by default, with a value of 120 (seconds). This causes
192
- +puppet agent+ to connect to the server every 2 minutes and ask it to sign a
193
- certificate request. This is useful for the initial setup of a puppet
194
- client. You can turn off waiting for certificates by specifying a time of 0.
195
-
196
206
197
207
EXAMPLE
198
208
-------
@@ -205,7 +215,7 @@ def help
205
215
206
216
COPYRIGHT
207
217
---------
208
- Copyright (c) 2011 Puppet Inc., LLC
218
+ Copyright (c) 2011-2018 Puppet Inc., LLC
209
219
Licensed under the Apache 2.0 License
210
220
HELP
211
221
end
@@ -222,11 +232,12 @@ def main
222
232
raise _ ( "missing argument: --target is required when using --apply" ) if options [ :target ] . nil?
223
233
raise _ ( "%{file} does not exist, cannot apply" ) % { file : options [ :apply ] } unless File . file? ( options [ :apply ] )
224
234
end
235
+ libdir = Puppet [ :libdir ]
225
236
vardir = Puppet [ :vardir ]
226
237
confdir = Puppet [ :confdir ]
227
238
certname = Puppet [ :certname ]
228
239
229
- env = Puppet . lookup ( :environments ) . get ( Puppet [ :environment ] )
240
+ env = Puppet :: Node :: Environment . remote ( Puppet [ :environment ] )
230
241
returns = Puppet . override ( :current_environment => env , :loaders => Puppet ::Pops ::Loaders . new ( env ) ) do
231
242
# find device list
232
243
require 'puppet/util/network_device/config'
@@ -251,9 +262,13 @@ def main
251
262
252
263
# override local $vardir and $certname
253
264
Puppet [ :confdir ] = ::File . join ( Puppet [ :devicedir ] , device . name )
265
+ Puppet [ :libdir ] = options [ :libdir ] || ::File . join ( Puppet [ :devicedir ] , device . name , 'lib' )
254
266
Puppet [ :vardir ] = ::File . join ( Puppet [ :devicedir ] , device . name )
255
267
Puppet [ :certname ] = device . name
256
268
269
+ unless options [ :resource ] || options [ :facts ] || options [ :apply ] || options [ :libdir ]
270
+ Puppet ::Configurer ::PluginHandler . new . download_plugins ( env )
271
+ end
257
272
# this init the device singleton, so that the facts terminus
258
273
# and the various network_device provider can use it
259
274
Puppet ::Util ::NetworkDevice . init ( device )
@@ -309,13 +324,14 @@ def main
309
324
310
325
require 'puppet/configurer'
311
326
configurer = Puppet ::Configurer . new
312
- configurer . run ( :network_device => true , :pluginsync => Puppet ::Configurer . should_pluginsync? )
327
+ configurer . run ( :network_device => true , :pluginsync => Puppet ::Configurer . should_pluginsync? && ! options [ :libdir ] )
313
328
end
314
329
rescue => detail
315
330
Puppet . log_exception ( detail )
316
331
# If we rescued an error, then we return 1 as the exit code
317
332
1
318
333
ensure
334
+ Puppet [ :libdir ] = libdir
319
335
Puppet [ :vardir ] = vardir
320
336
Puppet [ :confdir ] = confdir
321
337
Puppet [ :certname ] = certname
0 commit comments