@@ -373,38 +373,34 @@ def generate_scope
373373 end
374374
375375 unless node . is_a? ( Puppet ::Node ) # to allow unit tests to pass a node instance
376- facts = retrieve_node_facts ( node , given_facts )
377- if Puppet . settings . set_by_cli? ( 'environment' )
378- node = Puppet ::Node . new ( node , :classes => nil , :parameters => nil , :facts => facts , :environment => Puppet . settings . value ( 'environment' ) )
379- else
380- ni = Puppet ::Node . indirection
381- tc = ni . terminus_class
382- if options [ :compile ]
383- if tc == :plain
384- node = ni . find ( node , facts : facts )
385- else
386- begin
387- service = Puppet . runtime [ :http ]
388- session = service . create_session
389- cert = session . route_to ( :ca )
390-
391- _ , x509 = cert . get_certificate ( node )
392- cert = OpenSSL ::X509 ::Certificate . new ( x509 )
393- Puppet ::SSL ::Oids . register_puppet_oids
394- trusted = Puppet ::Context ::TrustedInformation . remote ( true , facts . values [ 'certname' ] || node , Puppet ::SSL ::Certificate . from_instance ( cert ) )
395- Puppet . override ( trusted_information : trusted ) do
396- node = ni . find ( node , facts : facts )
397- end
398- rescue
399- Puppet . warning _ ( "CA is not available, the operation will continue without using trusted facts." )
376+ facts = retrieve_node_facts ( node , given_facts )
377+ ni = Puppet ::Node . indirection
378+ tc = ni . terminus_class
379+ if options [ :compile ] && !Puppet . settings . set_by_cli? ( 'environment' )
380+ if tc == :plain
381+ node = ni . find ( node , facts : facts )
382+ else
383+ begin
384+ service = Puppet . runtime [ :http ]
385+ session = service . create_session
386+ cert = session . route_to ( :ca )
387+
388+ _ , x509 = cert . get_certificate ( node )
389+ cert = OpenSSL ::X509 ::Certificate . new ( x509 )
390+ Puppet ::SSL ::Oids . register_puppet_oids
391+ trusted = Puppet ::Context ::TrustedInformation . remote ( true , facts . values [ 'certname' ] || node , Puppet ::SSL ::Certificate . from_instance ( cert ) )
392+ Puppet . override ( trusted_information : trusted ) do
400393 node = ni . find ( node , facts : facts )
401394 end
395+ rescue
396+ Puppet . warning _ ( "CA is not available, the operation will continue without using trusted facts." )
397+ node = ni . find ( node , facts : facts )
402398 end
403- else
404- ni . terminus_class = :plain
405- node = ni . find ( node , facts : facts )
406- ni . terminus_class = tc
407399 end
400+ else
401+ ni . terminus_class = :plain
402+ node = ni . find ( node , facts : facts , environment : Puppet [ :environment ] )
403+ ni . terminus_class = tc
408404 end
409405 else
410406 node . add_extra_facts ( given_facts ) if given_facts
0 commit comments