@@ -363,32 +363,28 @@ def generate_scope
363
363
end
364
364
365
365
unless node . is_a? ( Puppet ::Node ) # to allow unit tests to pass a node instance
366
- facts = Puppet ::Node ::Facts . indirection . find ( node , :environment => Puppet . lookup ( :current_environment ) )
367
-
368
- facts = Puppet ::Node ::Facts . new ( node , { } ) if facts . nil?
369
- facts . add_extra_values ( given_facts ) if given_facts
370
-
371
- if facts . values . empty?
372
- raise _ ( "No facts available for target node: %{node}" ) % { node : node }
373
- end
374
-
375
- ni = Puppet ::Node . indirection
376
- tc = ni . terminus_class
377
-
378
- service = Puppet . runtime [ :http ]
379
- session = service . create_session
380
- cert = session . route_to ( :ca )
381
-
382
- cert = cert . get_certificate ( node )
383
- trusted = Puppet ::Context ::TrustedInformation . new ( true , node , cert )
384
-
385
- Puppet . override ( trusted_information : trusted ) do
386
- if tc == :plain || options [ :compile ]
387
- node = ni . find ( node , facts : facts )
388
- else
389
- ni . terminus_class = :plain
390
- node = ni . find ( node , facts : facts )
391
- ni . terminus_class = tc
366
+ facts = retrieve_node_facts ( node , given_facts )
367
+ if Puppet . settings . set_by_cli? ( 'environment' )
368
+ node = Puppet ::Node . new ( node , :classes => nil , :parameters => nil , :facts => facts , :environment => Puppet . settings . value ( 'environment' ) )
369
+ else
370
+ ni = Puppet ::Node . indirection
371
+ tc = ni . terminus_class
372
+
373
+ service = Puppet . runtime [ :http ]
374
+ session = service . create_session
375
+ cert = session . route_to ( :ca )
376
+
377
+ cert = cert . get_certificate ( node )
378
+ trusted = Puppet ::Context ::TrustedInformation . new ( true , node , cert )
379
+
380
+ Puppet . override ( trusted_information : trusted ) do
381
+ if tc == :plain || options [ :compile ]
382
+ node = ni . find ( node , facts : facts )
383
+ else
384
+ ni . terminus_class = :plain
385
+ node = ni . find ( node , facts : facts )
386
+ ni . terminus_class = tc
387
+ end
392
388
end
393
389
end
394
390
else
@@ -405,4 +401,16 @@ def generate_scope
405
401
compiler . compile { |catalog | yield ( compiler . topscope ) ; catalog }
406
402
end
407
403
end
404
+
405
+ def retrieve_node_facts ( node , given_facts )
406
+ facts = Puppet ::Node ::Facts . indirection . find ( node , :environment => Puppet . lookup ( :current_environment ) )
407
+
408
+ facts = Puppet ::Node ::Facts . new ( node , { } ) if facts . nil?
409
+ facts . add_extra_values ( given_facts ) if given_facts
410
+
411
+ if facts . values . empty?
412
+ raise _ ( "No facts available for target node: %{node}" ) % { node : node }
413
+ end
414
+ facts
415
+ end
408
416
end
0 commit comments