11require 'puppet/application'
2+ require 'puppet/configurer'
23require 'puppet/util/network_device'
34
45class Puppet ::Application ::Device < Puppet ::Application
@@ -53,6 +54,10 @@ def preinit
5354 options [ :detailed_exitcodes ] = true
5455 end
5556
57+ option ( "--libdir LIBDIR" ) do |arg |
58+ options [ :libdir ] = arg
59+ end
60+
5661 option ( "--apply MANIFEST" ) do |arg |
5762 options [ :apply ] = arg . to_s
5863 end
@@ -93,10 +98,11 @@ def help
9398
9499USAGE
95100-----
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]]
100106 [-t|--target <device>] [--user=<user>] [-V|--version]
101107
102108
@@ -135,9 +141,25 @@ def help
135141long argument. For example, 'server' is a valid configuration parameter, so
136142you can specify '--server <servername>' as an argument.
137143
138- * --debug:
144+ * --help, -h:
145+ Print this help message
146+
147+ * --verbose, -v:
148+ Turn on verbose reporting.
149+
150+ * --debug, -d:
139151 Enable full debugging.
140152
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+
141163* --detailed-exitcodes:
142164 Provide transaction information via exit codes. If this is enabled, an exit
143165 code of '1' means at least one device had a compile failure, an exit code of
@@ -149,18 +171,16 @@ def help
149171 Path to the device config file for puppet device.
150172 Default: $confdir/device.conf
151173
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.
154180
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.
164184
165185* --apply:
166186 Apply a manifest against a remote target. Target must be specified.
@@ -183,16 +203,6 @@ def help
183203* --user:
184204 The user to run as.
185205
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-
196206
197207EXAMPLE
198208-------
@@ -205,7 +215,7 @@ def help
205215
206216COPYRIGHT
207217---------
208- Copyright (c) 2011 Puppet Inc., LLC
218+ Copyright (c) 2011-2018 Puppet Inc., LLC
209219Licensed under the Apache 2.0 License
210220 HELP
211221 end
@@ -222,11 +232,12 @@ def main
222232 raise _ ( "missing argument: --target is required when using --apply" ) if options [ :target ] . nil?
223233 raise _ ( "%{file} does not exist, cannot apply" ) % { file : options [ :apply ] } unless File . file? ( options [ :apply ] )
224234 end
235+ libdir = Puppet [ :libdir ]
225236 vardir = Puppet [ :vardir ]
226237 confdir = Puppet [ :confdir ]
227238 certname = Puppet [ :certname ]
228239
229- env = Puppet . lookup ( :environments ) . get ( Puppet [ :environment ] )
240+ env = Puppet :: Node :: Environment . remote ( Puppet [ :environment ] )
230241 returns = Puppet . override ( :current_environment => env , :loaders => Puppet ::Pops ::Loaders . new ( env ) ) do
231242 # find device list
232243 require 'puppet/util/network_device/config'
@@ -251,9 +262,13 @@ def main
251262
252263 # override local $vardir and $certname
253264 Puppet [ :confdir ] = ::File . join ( Puppet [ :devicedir ] , device . name )
265+ Puppet [ :libdir ] = options [ :libdir ] || ::File . join ( Puppet [ :devicedir ] , device . name , 'lib' )
254266 Puppet [ :vardir ] = ::File . join ( Puppet [ :devicedir ] , device . name )
255267 Puppet [ :certname ] = device . name
256268
269+ unless options [ :resource ] || options [ :facts ] || options [ :apply ] || options [ :libdir ]
270+ Puppet ::Configurer ::PluginHandler . new . download_plugins ( env )
271+ end
257272 # this init the device singleton, so that the facts terminus
258273 # and the various network_device provider can use it
259274 Puppet ::Util ::NetworkDevice . init ( device )
@@ -309,13 +324,14 @@ def main
309324
310325 require 'puppet/configurer'
311326 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 ] )
313328 end
314329 rescue => detail
315330 Puppet . log_exception ( detail )
316331 # If we rescued an error, then we return 1 as the exit code
317332 1
318333 ensure
334+ Puppet [ :libdir ] = libdir
319335 Puppet [ :vardir ] = vardir
320336 Puppet [ :confdir ] = confdir
321337 Puppet [ :certname ] = certname
0 commit comments